[cfe-dev] Normalizing the AST across languages

Doug Gregor doug.gregor at gmail.com
Thu Oct 30 14:47:51 PDT 2008


On Thu, Oct 30, 2008 at 4:48 PM, Argiris Kirtzidis <akyrtzi at gmail.com> wrote:
> 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.

Okay, good. Now, I see that CXXFieldDecls are not ScopedDecls, but
that's something we'll need to change, right? For example:

  class C {
    int m;
    decltype(m) n;
  };

> 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.

Sure.

>> 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).

So I assume that CXXFieldCollector will either be extended to support
other kinds of members (member types, member functions, etc.) or that
there will be similar collectors for those other kinds of members
(CXXMethodCollector, etc.)?

  - Doug



More information about the cfe-dev mailing list