From 7c1048b86bc76e68f728e4819fe832d17276bfe6 Mon Sep 17 00:00:00 2001 From: Marcelo Lira Date: Wed, 29 Sep 2010 10:46:48 -0300 Subject: Improved resolution of enum value attributions. In particular when an enum item is set to the value of an item from other enum. The code for this was moved to the method AbstractMetaBuilder::findOutValueFromString. Tests were added as well. s# ../tests/.testenum.h.swp --- abstractmetabuilder.cpp | 77 ++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 40 deletions(-) (limited to 'abstractmetabuilder.cpp') diff --git a/abstractmetabuilder.cpp b/abstractmetabuilder.cpp index 000ce8400..50a0e6576 100644 --- a/abstractmetabuilder.cpp +++ b/abstractmetabuilder.cpp @@ -788,22 +788,12 @@ int AbstractMetaBuilder::figureOutEnumValue(const QString &stringValue, matched = true; } else { - AbstractMetaEnumValue* ev = 0; - AbstractMetaClass* enumEnclosingClass = metaEnum ? metaEnum->enclosingClass() : 0; - if (metaEnum) { - matched = true; - if (s == "true" || s == "false") { - v = (s == "true"); - } else if ((ev = metaEnum->values().find(s))) { - v = ev->value(); - } else if (enumEnclosingClass && (ev = enumEnclosingClass->findEnumValue(s, metaEnum))) { - v = ev->value(); - } else { - matched = false; + v = findOutValueFromString(s, matched); + if (!matched) { + QString enclosingClass = QString(metaEnum->enclosingClass() ? metaEnum->enclosingClass()->name() + "::" : QString()); ReportHandler::warning("unhandled enum value: " + s + " in " - + (enumEnclosingClass ? QString("%1::").arg(enumEnclosingClass->name()) : QString()) - + metaEnum->name() + + enclosingClass + metaEnum->name() + " from header '" + metaEnum->typeEntry()->include().name() + "'"); } } else { @@ -1945,32 +1935,8 @@ AbstractMetaType* AbstractMetaBuilder::translateType(const TypeInfo& _typei, boo for (int i = typeInfo.arrays.size() - 1; i >= 0; --i) { QString s = typeInfo.arrays.at(i); - bool ok; - - int elems = s.toInt(&ok); - if (!ok) { - if (s == "true" or s == "false") { - elems = (s == "true"); - } else { - AbstractMetaEnumValue* enumValue = m_metaClasses.findEnumValue(s); - if (!enumValue) { - foreach (AbstractMetaEnum* metaEnum, m_globalEnums) { - foreach (AbstractMetaEnumValue* ev, metaEnum->values()) { - if (ev->name() == s) { - enumValue = ev; - break; - } - } - if (enumValue) - break; - } - } - - if (!enumValue) - return 0; - elems = enumValue->value(); - } - } + bool _ok; + int elems = findOutValueFromString(s, _ok); AbstractMetaType* arrayType = createMetaType(); arrayType->setArrayElementCount(elems); @@ -2108,6 +2074,37 @@ AbstractMetaType* AbstractMetaBuilder::translateType(const TypeInfo& _typei, boo return metaType; } + +int AbstractMetaBuilder::findOutValueFromString(const QString& stringValue, bool& ok) +{ + int value = stringValue.toInt(&ok); + if (ok) + return value; + + if (stringValue == "true" or stringValue == "false") { + ok = true; + return (stringValue == "true"); + } + + AbstractMetaEnumValue* enumValue = m_metaClasses.findEnumValue(stringValue); + if (enumValue) { + ok = true; + return enumValue->value(); + } + + foreach (AbstractMetaEnum* metaEnum, m_globalEnums) { + foreach (AbstractMetaEnumValue* ev, metaEnum->values()) { + if (ev->name() == stringValue) { + ok = true; + return ev->value(); + } + } + } + + ok = false; + return 0; +} + void AbstractMetaBuilder::decideUsagePattern(AbstractMetaType *metaType) { const TypeEntry* type = metaType->typeEntry(); -- cgit v1.2.3