Writing a tentative parser for C++0x attributes

Hey clang-folk!

I'm working on implementing the new C++0x attribute specification,
currently integrated into the working paper. Aside from a couple issues
in the specification which I've sent forward to the committee in hopes
they can be addressed, my biggest issue is adjusting
isCXXDeclarationStatement

The problem is that C++0x attributes can be the start of all
declarations as well as some statements. As a result, the tentative
parsers that disambiguate need to be able to work in the face of an
attribute-specifier.

Initially, I opened a TentativeParseAction in isCXXDeclarationSatement,
but that was causing crashes in the scope annotation system. Does anyone
have any better ideas for how to do this?

Sean Hunt

Hi Sean,

(Re-added cfe-dev)

Hi Sean,

Don't forget to do "Reply-all" so that cfe-dev is included.
Also, for future patches look into getting them attached instead of embedded into the email, so that they are easier to use.

About the patch, since attributes appear before statements & declarations, I suggest parsing them at
Parser::ParseStatementOrDeclaration() before going into the "stmt or decl" parsing part. That way you will parse them once
and then pass the AttributeList* to the statement parsing methods, instead of parsing them at each one.

Then for the decl/stmt ambiguity part, you only need to check for attributes in Parser::TryParseDeclarator().

-Argiris

Argyrios Kyrtzidis wrote:

Hi Sean,

Don't forget to do "Reply-all" so that cfe-dev is included.
Also, for future patches look into getting them attached instead of
embedded into the email, so that they are easier to use.

Ah, I wasn't familiar with that aspect of this list. Thanks! I thought
I'd attached the patch, though. Oh well.

About the patch, since attributes appear before statements &
declarations, I suggest parsing them at
Parser::ParseStatementOrDeclaration() before going into the "stmt or
decl" parsing part. That way you will parse them once
and then pass the AttributeList* to the statement parsing methods,
instead of parsing them at each one.

Then for the decl/stmt ambiguity part, you only need to check for
attributes in Parser::TryParseDeclarator().

The problem with this approach is that parsing them in
ParseStatementOrDeclaration() requires me to pass the attributes to
ParseDeclaration(), and then move the attribute check out of
ParseDeclaration() into its other two callers, when that check clearly
belongs in that function (it's called by
Parser::ParseStatementOrDeclaration(),
Parser::ParseCompoundStatementBody(), and
Parser::ParseExternalDeclaration(), and the latter calls
Parser::ParseDeclarationOrFunctionDefinition(), which currently does the
attribute check and itself has 2 other callers).

Sean Hunt

How about doing attribute checking in ParseDeclaration() unless the AttributeList* parameter is not null
which means that the caller already did attribute parsing (e.g the ParseStatementOrDeclaration() caller).

The main reason for doing attribute checking in ParseStatementOrDeclaration() is that it's much preferable to
avoid tentative parsing if possible. If we push attribute checking into the tentative parser then we will
start tentative parsing every time an attribute is encountered, and not just when there is an actual decl/stmt
ambiguity.

-Argiris