Nested types of aliased structures cannot be found
Chlumsky opened this issue · 1 comments
For example:
struct Foo {
struct Bar {
int x;
};
};
using FooAlias = Foo;In this case, we should be able to refer to FooAlias::Bar but due to the way nested names and alias resolution is currently implemented, this is not possible.
Currently, the available workaround is to provide hints to the program as typeAliases in the configuration file, e.g.
"typeAliases": { "FooAlias::Bar": "Foo::Bar" }The ideal solution would be to completely reorganize the type storage & lookup system to form a namespace hierarchy, but that would be a major rewrite for a relatively minor issue, and I believe it might have some unexpected downsides or side effects, e.g. in:
namespace a {
struct A { };
}
namespace b {
namespace a {
struct B { };
}
struct C { a::A x }; // will assume a is ::b::a
}The type of C::x would be currently identified as ::a::A, which is more flexible, however this is not valid in C++ so there is no reason it should work. This solution would allow for a very straightforward implementation of #44, which is an upside. Maybe this could be done later down the line, but for the time being, I would prefer a simpler solution.
For that, I have come up with the following scheme that I believe should work:
- On each typedef (or using), store the string mapping of alias to typename into TypeSet (as long as there is no array suffix or templates involved).
- When parsing a structure, make a list of all nested subtypes and store it so that it is available to TypeSet.
- Between the first and second parser pass, iterate over the entries from step 1, and if one's type resolves to a struct, generate aliases for all its subtypes.
- Since some alias types may only be resolved during step 3, the step needs to be repeated until no unresolved aliases are left or no progress is made.