summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-10-03 14:37:28 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2011-10-04 14:48:48 -0300
commit5f3ed94f7a83acf0fc7dfddf414a34121eabe58a (patch)
tree9c1dadf03a4768982e1540bbac7d7a8efa9305e3
parent44138ada64eb6f9175ea7bb8c05e38f9079fbf8b (diff)
downloadgeneratorrunner-5f3ed94f7a83acf0fc7dfddf414a34121eabe58a.tar.gz
generatorrunner-5f3ed94f7a83acf0fc7dfddf414a34121eabe58a.tar.xz
generatorrunner-5f3ed94f7a83acf0fc7dfddf414a34121eabe58a.zip
Fixed minimalConstructor method for classes with template instantiations.
Reviewed by Luciano Wolf <luciano.wolf@openbossa.org> Reviewed by Renato Ara├║jo <renato.filho@openbossa.org>
-rw-r--r--generator.cpp67
-rw-r--r--generator.h12
2 files changed, 72 insertions, 7 deletions
diff --git a/generator.cpp b/generator.cpp
index 60ff21d..a53e322 100644
--- a/generator.cpp
+++ b/generator.cpp
@@ -398,6 +398,50 @@ bool Generator::isVoidPointer(const AbstractMetaType* type)
&& type->name() == "void";
}
+QString Generator::getFullTypeName(const TypeEntry* type) const
+{
+ return QString("%1%2").arg(type->isCppPrimitive() ? "" : "::").arg(type->qualifiedCppName());
+}
+
+QString Generator::getFullTypeName(const AbstractMetaType* type) const
+{
+ if (isCString(type))
+ return "const char*";
+ if (isVoidPointer(type))
+ return "void*";
+ if (type->typeEntry()->isContainer())
+ return QString("::%1").arg(type->cppSignature());
+ QString typeName;
+ if (type->typeEntry()->isComplex() && type->hasInstantiations())
+ typeName = getFullTypeNameWithoutModifiers(type);
+ else
+ typeName = getFullTypeName(type->typeEntry());
+ return typeName + QString("*").repeated(type->indirections());
+}
+
+QString Generator::getFullTypeName(const AbstractMetaClass* metaClass) const
+{
+ return QString("::%1").arg(metaClass->qualifiedCppName());
+}
+
+QString Generator::getFullTypeNameWithoutModifiers(const AbstractMetaType* type) const
+{
+ if (isCString(type))
+ return "const char*";
+ if (isVoidPointer(type))
+ return "void*";
+ if (!type->hasInstantiations())
+ return getFullTypeName(type->typeEntry());
+ QString typeName = type->cppSignature();
+ if (type->isConstant())
+ typeName.remove(0, sizeof("const ") / sizeof(char) - 1);
+ if (type->isReference())
+ typeName.chop(1);
+ while (typeName.endsWith('*') || typeName.endsWith(' '))
+ typeName.chop(1);
+ return QString("::%1").arg(typeName);
+}
+
QString Generator::minimalConstructor(const AbstractMetaType* type) const
{
if (!type || (type->isReference() && Generator::isObjectType(type)))
@@ -425,7 +469,12 @@ QString Generator::minimalConstructor(const AbstractMetaType* type) const
if (type->typeEntry()->isComplex()) {
const ComplexTypeEntry* cType = reinterpret_cast<const ComplexTypeEntry*>(type->typeEntry());
QString ctor = cType->defaultConstructor();
- return (ctor.isEmpty()) ? minimalConstructor(classes().findClass(cType)) : ctor;
+ if (!ctor.isEmpty())
+ return ctor;
+ ctor = minimalConstructor(classes().findClass(cType));
+ if (type->hasInstantiations())
+ ctor = ctor.replace(getFullTypeName(cType), getFullTypeNameWithoutModifiers(type));
+ return ctor;
}
return minimalConstructor(type->typeEntry());
@@ -480,9 +529,15 @@ QString Generator::minimalConstructor(const AbstractMetaClass* metaClass) const
maxArgs = numArgs;
}
+ QString qualifiedCppName = metaClass->typeEntry()->qualifiedCppName();
+ QStringList templateTypes;
+ foreach (TypeEntry* templateType, metaClass->templateArguments())
+ templateTypes << templateType->qualifiedCppName();
+ QString fixedTypeName = QString("%1<%2 >").arg(qualifiedCppName).arg(templateTypes.join(", "));
+
// Empty constructor.
if (maxArgs == 0)
- return QString("::%1()").arg(metaClass->qualifiedCppName());
+ return QString("::%1()").arg(qualifiedCppName);
QList<const AbstractMetaFunction*> candidates;
@@ -526,10 +581,8 @@ QString Generator::minimalConstructor(const AbstractMetaClass* metaClass) const
}
}
- if (!args.isEmpty()) {
- return QString("::%1(%2)").arg(metaClass->qualifiedCppName())
- .arg(args.join(", "));
- }
+ if (!args.isEmpty())
+ return QString("::%1(%2)").arg(qualifiedCppName).arg(args.join(", "));
candidates << ctor;
}
@@ -553,7 +606,7 @@ QString Generator::minimalConstructor(const AbstractMetaClass* metaClass) const
args << argValue;
}
if (!args.isEmpty()) {
- return QString("::%1(%2)").arg(metaClass->qualifiedCppName())
+ return QString("::%1(%2)").arg(qualifiedCppName)
.arg(args.join(", "));
}
}
diff --git a/generator.h b/generator.h
index 484327d..eeaa07e 100644
--- a/generator.h
+++ b/generator.h
@@ -242,6 +242,18 @@ public:
/// Returns true if the type is a void pointer.
static bool isVoidPointer(const AbstractMetaType* type);
+ // Returns the full name of the type.
+ QString getFullTypeName(const TypeEntry* type) const;
+ QString getFullTypeName(const AbstractMetaType* type) const;
+ QString getFullTypeName(const AbstractMetaClass* metaClass) const;
+
+ /**
+ * Returns the full qualified C++ name for an AbstractMetaType, but removing modifiers
+ * as 'const', '&', and '*' (except if the class is not derived from a template).
+ * This is useful for instantiated templates.
+ */
+ QString getFullTypeNameWithoutModifiers(const AbstractMetaType* type) const;
+
/**
* Tries to build a minimal constructor for the type.
* It will check first for a user defined default constructor.