[cfe-dev] Normalizing the AST across languages

Doug Gregor doug.gregor at gmail.com
Thu Oct 30 13:06:14 PDT 2008


On Thu, Oct 30, 2008 at 3:34 PM, Argiris Kirtzidis <akyrtzi at gmail.com> wrote:
> Doug Gregor wrote:
>>
>> So, here is my suggestion: instead of making a distinction between
>> what the two languages support at the AST level, use a single AST node
>> (RecordDecl) that has a pointer to an optionally-allocated "extras"
>> data structure containing that extra information when we need to store
>> it. For RecordDecl, the "extras" structure should definitely have
>> information about C++ classes that isn't needed in C and isn't used by
>> the majority of C++ classes. For example, base classes, friends,
>> user-defined constructors/destructor/copy-assignment operators,  and
>> user-defined conversion operators.
>>
>
> It may be beneficial to "pull out" the 'members' fields from RecordDecl and
> put them into a RecordDefInfo, which is like the "extras" structure you
> mention with the purpose of
> storing the info about the definition.
> Currently there's a new RecordDecl created for each record reference and the
> 'Members' fields is wasted space for them.
>
> After a class definition is parsed, we will know if it's a simple C-like
> struct or not, and we will create a RecordDefInfo or CXXRecordDefInfo
> accordingly (to add to RecordDecl).
> RecordDefInfo will keep the instance members, while CXXRecordDefInfo will
> also keep the other C++ specific stuff (base classes, etc.).

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.

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?

  - Doug



More information about the cfe-dev mailing list