[cfe-dev] [PATCH]: Parsing for C++ classes

Eli Friedman eli.friedman at gmail.com
Sat Jun 21 11:57:43 PDT 2008


On Sat, Jun 21, 2008 at 10:25 AM, Eli Friedman <eli.friedman at gmail.com> wrote:
> On Sat, Jun 21, 2008 at 8:23 AM, Argiris Kirtzidis <akyrtzi at gmail.com> wrote:
>> Eli Friedman wrote:
>>>
>>> A couple more potential issues that I found while re-reading the patch:
>>> +    bool isInstField = (DS.getStorageClassSpec() ==
>>> DeclSpec::SCS_unspecified &&
>>> +                        !DeclaratorInfo.isFunctionDeclarator());
>>>
>>> This check isn't reliable. Simple example: "typedef int func(); class
>>> C {func a,b;};".
>>>
>>
>> Ah, good find!
>> How about adding a Action::isFunctionTypeDeclarator for the parser to get
>> this kind of information:
>
> Having the parser query Sema is no good; it's a layering violation.
> The expectation is that the parser works the same way no matter what
> action handler it's hooked up to.

Bleh, I forgot that C is ambiguous anyway if you can't figure out
whether an identifier declares a type.  So this layering violation
exists anyway.

That said, it's a larger burden on additional Action implementations
to figure out the type of a identifier versus figuring out whether an
identifier refers to a type. Figuring out whether an identifier refers
to a type only requires limited resolution of declarations and the
type heirarchy (see MinimalAction.cpp).  Figuring out whether a type
is a function type is a bit more complicated because the Action
implementation has to track whether a typedef type is a function type.

This also affects the GNU typeof extension; for a typeof, determining
whether the type is a function type essentially requires a complete
Sema implementation.  (I guess it's worth noting for this that g++
doesn't accept "typeof(x)::a", which might complicate this depending
on how it were defined.)

-Eli



More information about the cfe-dev mailing list