| Summary: | Need representation of gcc attributes in AST | ||
|---|---|---|---|
| Product: | [Tools] CDT | Reporter: | Elena Laskavaia <elaskavaia.cdt> |
| Component: | cdt-parser | Assignee: | Sergey Prigogin <eclipse.sprigogin> |
| Status: | RESOLVED FIXED | QA Contact: | Mike Kucera <mikekucera> |
| Severity: | normal | ||
| Priority: | P3 | CC: | eclipse.sprigogin, paedu.hofer, yevshif |
| Version: | 7.0 | Flags: | eclipse.sprigogin:
review?
(mschorn.eclipse) |
| Target Milestone: | 8.1.0 | ||
| Hardware: | PC | ||
| OS: | Windows 7 | ||
| Whiteboard: | |||
| Bug Depends on: | |||
| Bug Blocks: | 316076, 330635 | ||
|
Description
Elena Laskavaia
C++0x specifies support for c++-attributes (with a different syntax). We need to model the AST along this specification and can (that's my hope) treat the __attribute__ syntax as a special case. See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2761.pdf The proposed fix is in https://git.eclipse.org/r/#/c/5554/. Markus could you please review IASTGCCAttribute and parser changes. Thanks. (In reply to comment #2) > The proposed fix is in https://git.eclipse.org/r/#/c/5554/. Markus could you > please review IASTGCCAttribute and parser changes. Thanks. I have some recommondations: 1) The new standard for c++ defines attributes that are more general than your interface (they allow for a balanced token sequence rather than an expression). We should model the attributes of the new standard. Gcc attributes are a special case of those. 2) I am uncertain on whether the name of an attribute shall be represented with an IASTName. A simple string might be sufficient. 3) Attributes can be used in quite a lot of places (the new standard provides a definition for c++). I suggest to introduce a new interface (IASTAttributeOwner) similar to IASTImplicitNameOwner, which can be implemented by IASTDeclarator but also by ICPPASTNamespace, .... It'd be certainly best to provide the attributes for all places where they can be used. 4)It'd be good to support the new c++11 syntax for attributes, however this may be a separate effort. (In reply to comment #3) I've updated the proposed fix in Gerrit (https://git.eclipse.org/r/#/c/5554/). > 1) The new standard for c++ defines attributes that are more general than your > interface (they allow for a balanced token sequence rather than an expression). > We should model the attributes of the new standard. Gcc attributes are a > special case of those. Done. > 2) I am uncertain on whether the name of an attribute shall be represented with > an IASTName. A simple string might be sufficient. Changed to char[]. Initially I got confused by qualified attribute names. > 3) Attributes can be used in quite a lot of places (the new standard provides a > definition for c++). I suggest to introduce a new interface > (IASTAttributeOwner) similar to IASTImplicitNameOwner, which can be implemented > by IASTDeclarator but also by ICPPASTNamespace, .... It'd be certainly best to > provide the attributes for all places where they can be used. I've added IASTAttributeOwner interface and ASTAttributeOwner abstract class to make implementation of the interface easier. My attempt to add attributes to all places where they are allowed encountered some difficulties: 1. There seem to be differences between places where GCC-style and C++11-style attributes are allowed. In the GCC case it's not always clear what the attribute applies to. 2. Current structure of the parser code makes it difficult to propagate attributes from the place where they are parsed to the place where they can be applied to their owner node. 3. I'm not sure how to treat attributes in CASTAmbiguousStatement, CPPASTAmbiguousStatement and CPPASTAmbiguousDeclaration classes. 4. It's not clear how to order visiting of attributes relative to their sibling nodes. I'm currently visiting them before their siblings, which matches the C++11 syntax, but it means that nodes are not visited in a monotonic offset order when GCC attributes are present. > 4)It'd be good to support the new c++11 syntax for attributes, however this > may be a separate effort. This is indeed a separate effort. The library of GCC 4.6 doesn't yet use C++11-style attributes. Fixed in master. |