Skip to content

Commit 0ae8072

Browse files
mwoehlke-kitwaremathstuf
authored andcommitted
Return enums in declaration order (order added)
Modify _ScopeModelItem to return enums (from the enums() method) in the order that they were added (which presumably is the order in which they were declared). We must do this because we must process enumerations in the same order in order to resolve values, as later declared enums may refer to values from earlier declared enums (and in fact, this is exactly the case in the 'testenum' test), and the order we get just from QHash may not match declaration order. Change-Id: I15a05df98a2cee7ecccb6c82d3f9017735281245
1 parent 26b2482 commit 0ae8072

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

ApiExtractor/parser/codemodel.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,10 @@ FunctionDefinitionList _ScopeModelItem::functionDefinitions() const
406406

407407
EnumList _ScopeModelItem::enums() const
408408
{
409-
return _M_enums.values();
409+
EnumList result;
410+
foreach (const QString& name, _M_enumNames)
411+
result.append(_M_enums.value(name));
412+
return result;
410413
}
411414

412415
void _ScopeModelItem::addClass(ClassModelItem item)
@@ -440,7 +443,9 @@ void _ScopeModelItem::addTypeAlias(TypeAliasModelItem item)
440443

441444
void _ScopeModelItem::addEnum(EnumModelItem item)
442445
{
446+
_M_enumNames.removeOne(item->name());
443447
_M_enums.insert(item->name(), item);
448+
_M_enumNames.append(item->name());
444449
}
445450

446451
void _ScopeModelItem::removeClass(ClassModelItem item)
@@ -499,8 +504,10 @@ void _ScopeModelItem::removeEnum(EnumModelItem item)
499504
{
500505
QHash<QString, EnumModelItem>::Iterator it = _M_enums.find(item->name());
501506

502-
if (it != _M_enums.end() && it.value() == item)
507+
if (it != _M_enums.end() && it.value() == item) {
508+
_M_enumNames.removeOne(item->name());
503509
_M_enums.erase(it);
510+
}
504511
}
505512

506513
ClassModelItem _ScopeModelItem::findClass(const QString &name) const

ApiExtractor/parser/codemodel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ class _ScopeModelItem: public _CodeModelItem
401401
_ScopeModelItem(const _ScopeModelItem &other);
402402
void operator = (const _ScopeModelItem &other);
403403

404+
QStringList _M_enumNames;
404405
QStringList _M_enumsDeclarations;
405406
};
406407

0 commit comments

Comments
 (0)