[cfe-dev] Normalizing the AST across languages

Argiris Kirtzidis akyrtzi at gmail.com
Thu Oct 30 13:48:49 PDT 2008

Doug Gregor wrote:
> Are we going to be able to wait until the end of parsing before we
> create the RecordDefInfo or CXXRecordDefInfo? It seems like that could
> cause some pain with qualified name lookup, e.g.,
>   class Foo {
>     typedef int type;
>     Foo::type member;
>   };
> Normally, I would think that name lookup for Foo::type would find the
> RecordDecl that defines Foo and then go look for a "type" member
> inside it. However, that doesn't work here, because at the point where
> we need to lookup "Foo::type", there is no definition of Foo (yet),
> since we're still parsing it.

The way IdentifierResolver works, allows to put 'Foo' as the new 
DeclContext, insert into this new context the member declarations as we 
parse them and name lookup will find them.

But if there are base classes, we should probably create the 
CXXRecordDefInfo from the start, so that IdentifierResolver can see that 
the current DeclContext has base classes to look into.

> To make this work, we would need to be able to do lookup into whatever
> temporary data structures are used to store the fields of Foo before
> it has been fully defined. That's certainly possible... and in the
> template case, where we're looking up a "member of the current
> instantiation", it might even be easier. Perhaps you and Chris are two
> steps ahead of me... is this the direction in which CXXFieldCollector
> was going?

The purpose of CXXFieldCollector wasn't for name lookup, but rather to 
collect the instance fields and call ActOnFields when parsing of the 
class definition is finished.
This takes a similar code-path to C's parsing of struct definitions and 
reuses the semantic checks done on ActOnFields.
For C, it's the parser that collects the fields and later passes them to 
ActOnFields, but it was not technically possible to have the parser 
collect the instance fields for C++ classes as well (I don't want to 
bore you with the details, but it boiled down to the parser not being 
able to distinguish when a member declaration is an instance field or not).


More information about the cfe-dev mailing list