diff options
author | Nikolai Kosjar <[email protected]> | 2017-02-21 14:18:07 +0100 |
---|---|---|
committer | Nikolai Kosjar <[email protected]> | 2017-02-23 14:49:31 +0000 |
commit | fe27f947b916a6b7333be50127c219bafb3d2353 (patch) | |
tree | 20afb0bdc7efb186bddb5abf0a62f2a5e029e695 /src/libs/cplusplus | |
parent | 4637b3fed7a456ec664ae9ba1de5c03b32aa12fd (diff) |
C++: Avoid inline namespaces in generated code
Task-number: QTCREATORBUG-16086
Change-Id: Ic2f3fd38ae6cc93725bc214c24320f40a0a519a8
Reviewed-by: David Schulz <[email protected]>
Reviewed-by: Eike Ziller <[email protected]>
Diffstat (limited to 'src/libs/cplusplus')
-rw-r--r-- | src/libs/cplusplus/LookupContext.cpp | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/src/libs/cplusplus/LookupContext.cpp b/src/libs/cplusplus/LookupContext.cpp index 0a9138911e7..881c985f866 100644 --- a/src/libs/cplusplus/LookupContext.cpp +++ b/src/libs/cplusplus/LookupContext.cpp @@ -230,6 +230,32 @@ static bool symbolIdentical(Symbol *s1, Symbol *s2) return QByteArray(s1->fileName()) == QByteArray(s2->fileName()); } +static const Name *toName(const QList<const Name *> &names, Control *control) +{ + const Name *n = 0; + for (int i = names.size() - 1; i >= 0; --i) { + if (! n) + n = names.at(i); + else + n = control->qualifiedNameId(names.at(i), n); + } + + return n; +} + +static bool isInlineNamespace(ClassOrNamespace *con, const Name *name) +{ + const QList<LookupItem> items = con->find(name); + if (!items.isEmpty()) { + if (const Symbol *declaration = items.first().declaration() ) { + if (const Namespace *ns = declaration->asNamespace()) + return ns->isInline(); + } + } + + return false; +} + const Name *LookupContext::minimalName(Symbol *symbol, ClassOrNamespace *target, Control *control) { const Name *n = 0; @@ -245,8 +271,17 @@ const Name *LookupContext::minimalName(Symbol *symbol, ClassOrNamespace *target, if (target) { const QList<LookupItem> tresults = target->lookup(n); foreach (const LookupItem &tr, tresults) { - if (symbolIdentical(tr.declaration(), symbol)) - return n; + if (symbolIdentical(tr.declaration(), symbol)) { + // eliminate inline namespaces + QList<const Name *> minimal = names.mid(i); + for (int i = minimal.size() - 2; i >= 0; --i) { + const Name *candidate = toName(minimal.mid(0, i + 1), control); + if (isInlineNamespace(target, candidate)) + minimal.removeAt(i); + } + + return toName(minimal, control); + } } } } |