[cfe-dev] parsing code snippets

Olaf Krzikalla Olaf.Krzikalla at tu-dresden.de
Tue May 10 03:59:56 PDT 2011


At first I second Sebastian. If you provide a plugin interface then you 
definitely want to support dynamic handling of attributes.

At second, if you think about the general picture, then dynamic handling 
actually boils down to two customizeable steps: parsing and semantic 
checking of arguments.
Up to the parsing of arguments: IMHO there are three types of arguments: 
no argument, expressions and type-ids (which one did I forget? - ah, 
yes, a special one: VersionTuple). For arguments of these types simply 
declarations in one way or another have to be sufficient. A fourth type 
would be "user-defined". In that case a handler function similiar to 
PragmaHandler::HandlePragma is called with the Preprocessor as an 
argument enabling the user to parse the argument by its own.
Now to the semantic checking: I don't know if we should try to make the 
semantic checking declarative at all. It is of course possible to check 
the proper number of arguments, but whether an expression has to be an 
ICE or the proper type (see e.g. IBOutletCollection) should be checked 
in handler functions.

OK. I haven't talked about the current implementation yet. To make it 
short: I don't like it. Not at all. In fact it is the reason for my 
delayed response. I have digged into code and tried to understand what's 
going on. It took a while. All the semantic checking is in SemaDeclAttr 
but IMHO needs to be better tied to the attributes (there is also an 
appropriate comment in SemaDeclAttr.cpp). Then the Attr factory is the 
AttributeList. But it looks to me like it mirrors the attribute kinds 
generated from Attr.td.

Couldn't we stuff all this together? So that for each attribute we get a 
subclass of Attr holding the data (like now) and in addition a factory 
object which knows about the syntax and semantic of the attribute 
arguments. Then we can use tblgen to create the Attr taxonomy and the 
factories in one step. And of course we would provide an option for 
ASTConsumer to register own Attr factories.


Best regards
Olaf Krzikalla






More information about the cfe-dev mailing list