diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2010-09-29 10:46:48 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-09 19:10:11 -0300 |
commit | 7c1048b86bc76e68f728e4819fe832d17276bfe6 (patch) | |
tree | 1f0e7211d9948af5c6a48c38fde7794e21eabdce /abstractmetabuilder.cpp | |
parent | 0f84794301386a9371c374e5ed062fc000c96f17 (diff) |
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
Diffstat (limited to 'abstractmetabuilder.cpp')
-rw-r--r-- | abstractmetabuilder.cpp | 77 |
1 files changed, 37 insertions, 40 deletions
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(); |