diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2010-02-26 20:21:11 -0300 |
---|---|---|
committer | Marcelo Lira <marcelo.lira@openbossa.org> | 2010-02-26 20:24:28 -0300 |
commit | 3f6b0576c90960d4474623987ccac2877a34869c (patch) | |
tree | 956d6a4848dbec230714cbdf8aad3b0e68524fde /abstractmetabuilder.cpp | |
parent | eaec9c4a8ace3a91fccb12492d445fc939cb8bf5 (diff) |
Added method AbstractMetaBuilder::fixReturnTypeOfConversionOperator(func).
The new method fixes the return type of conversion operators:
they should return the target of the conversion as type and not
the type of its owner class.
fixReturnTypeOfConversionOperator is used in traverseFunctions.
An unit test was added for this case.
Note that this behaviour could be fixed in the parser. I dare you!
Diffstat (limited to 'abstractmetabuilder.cpp')
-rw-r--r-- | abstractmetabuilder.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/abstractmetabuilder.cpp b/abstractmetabuilder.cpp index c98a7bf2d..2c035ccab 100644 --- a/abstractmetabuilder.cpp +++ b/abstractmetabuilder.cpp @@ -1157,6 +1157,27 @@ void AbstractMetaBuilder::setupFunctionDefaults(AbstractMetaFunction *metaFuncti } } +void AbstractMetaBuilder::fixReturnTypeOfConversionOperator(AbstractMetaFunction* metaFunction) +{ + if (!metaFunction->isConversionOperator() + || metaFunction->implementingClass()->typeEntry() != metaFunction->type()->typeEntry()) + return; + + TypeDatabase* types = TypeDatabase::instance(); + QString castTo = metaFunction->name().remove(QRegExp("^operator ")).trimmed(); + + TypeEntry* retType = types->findType(castTo); + if (!retType) + return; + + AbstractMetaType* metaType = createMetaType(); + metaType->setTypeEntry(retType); + metaFunction->setType(metaType); + + AbstractMetaClass* metaClass = m_metaClasses.findClass(castTo); + metaClass->addExternalConversionOperator(metaFunction); +} + void AbstractMetaBuilder::traverseFunctions(ScopeModelItem scopeItem, AbstractMetaClass *metaClass) { foreach (FunctionModelItem function, scopeItem->functions()) { @@ -1217,6 +1238,9 @@ void AbstractMetaBuilder::traverseFunctions(ScopeModelItem scopeItem, AbstractMe ReportHandler::warning(warn); } + if (metaFunction->isConversionOperator()) + fixReturnTypeOfConversionOperator(metaFunction); + metaClass->addFunction(metaFunction); } else if (metaFunction->isDestructor()) { metaClass->setHasPrivateDestructor(metaFunction->isPrivate()); |