[cfe-dev] parsing code snippets
Olaf Krzikalla
Olaf.Krzikalla at tu-dresden.de
Fri May 6 08:46:19 PDT 2011
Am 06.05.2011 16:12, schrieb Douglas Gregor:
> To put this into the open-source tree, I'd want some evidence that this is the right way to support the kind of extensibility you're looking for. I think there's probably a better way.
Yep, I'm unsure about the proper approach either...
>> 2. How can we expose the current parser obejct to custom handlers
>> (attribute or pragma)?
>
> I don't have a good answer. For attributes, the idea was that we would have a way to describe the grammar of the attribute (with a *very* restrictive syntax), and have tblgen generate the attribute parsers from that. But, as far as I know, nobody is working on this at the moment.
... but maybe we can tie and handle both issues together.
I wouldn't mind about the handling of expressions inside pragmas (which
actually is part of the preprocessor!) if I have the freedom to handle
them in attribute lists. And if nobody is working an that issue and I
need it, then... well, I will be the one (I hesitated mainly because
actually Sean Hunt had worked on that issue and there is already some
handling of C0xx attributes in clang at various locations).
I'm sure, attributes were initially and still are intendend for the use
with expressions (N2418 clearly mentions expressions and
according to the draft n3242 the grammar for arguments is broadened even
further).
That said, IMHO we need
1. a callback mechanism for attributes similiar to the PragmaHandler (I
would restrict customization to scoped attributes and use the scope name
similiar tho the pragma ns).
2. a map from Stmts to Attrs in the ASTContext similiar to DeclAttrs.
3. an attr::Kind "UserDefined" and an appropriate Attr subclass.
4. means in the attribute handler in order to conveniently parse
attribute arguments.
I think that we can reach an agreement about approaches for pt.1-3
rather quickly.
For pt.4 my first idea would be an attribute handler which has some
(protected) functions which supports the parsing of argument lists.
Or we pass the parser as an argument to the handler function (like it is
done with the preprocessor in the pragma handler) but then we have to
publish the parser interface.
Of course the other way is a somewhat declarative interface. However I
don't know how to design it open and extensible. Is there any
preliminary work in that direction?
Best regards
Olaf Krzikalla
The fine print: If I work on attributes, I want a bit in LangOptions in
order to enable attributes beyond C++0x :-)
More information about the cfe-dev
mailing list