Fix the symbols tree hierarchy when several tags have the same name
Fix the symbols tree hierarchy by considering the whole scope when adding a tag, avoiding choosing the wrong parent when several tags have the same name. Until now, to avoid such misbehavior we only used to choose the parent candidate that appeared last (line-wise) before the child. It works in most typical situations as generally tag names are fairly unique, and children appear right after their parent. However, there are cases that are trickier and cannot be handled that way. In the following valid C++ snippet, it is impossible to know whether `function` should be listed under the namespace `A` or the class `A` without looking at its full scope: ```C++ namespace A { namespace B { class A { void method() {} }; }; void function() {} }; ``` And it is a real-world problem for some parsers like the JSON parser that generates numeric indices for array elements name, often leading to several possibly close duplicates. Additionally, to prevent trying to set a tag as its own parent, the code guarded against accepting a parent if the child had the same name, lading to incorrect hierarchy for `method` in cases like this: ```C++ namespace A { class A { void method() {} }; }; ``` So to fix this, consider the whole hierarchy of a tag for choosing its parent, when that information is available from the parser. Fixes #1583.
Showing
Please
register
or
sign in
to comment