Question about Attr.td

Richard Smith richard at metafoo.co.uk
Thu Jun 20 16:12:08 PDT 2013


On Thu, Jun 20, 2013 at 10:43 AM, Aaron Ballman <aaron at aaronballman.com> wrote:
> I am doing some attribute work, and I wanted to make sure I wasn't
> missing anything (and that I was heading in the right direction).

Attributes are rather unloved, and the transition to generating the
repetitive parts from .td files is far from complete. Work here is
definitely appreciated.

> It seems that the Subjects are not being used for anything.  The
> tablegen doesn't emit any code based on them, and the subjects in the
> td file are not particularly consistent.  I would like to correct this
> in the following ways:
>
> 1) I want to modify the tablegen to spit out some template functions:
>
> template <typename Subject>
> bool appertainsTo() const { return false; }
>
> template <>
> bool appertainsTo<TableGenSubject>() const { return true; }

Why a template? The subject needs to be either a Stmt or a Decl, and
appertainsTo may need to inspect the value of it (for a
SubsetSubject). Instead, how about something like:

bool appertainsTo(const Stmt *S) { return false; }
bool appertainsTo(const Decl *D) { return isa<VarDecl>(D); }

You'll presumably also need to generate information to use in the
'attribute 'xyzzy' can only be applied to foo, bar, and baz'
diagnostic.

> 2) If the attribute in the td file has no subjects, I want the default
> appertainsTo to return true (so it behaves in a backwards compatible
> manner).
>
> Between these two, we can start to do some things in Sema to determine
> what the attribtue appertains to.  For instance, my particular problem
> is with declarations.  If I have an attribute that I want to appertain
> to a statement (not a decl), I cannot do it because the attribute
> always attaches to the decl.  I want to be able to report that as an
> error for my statement attributes instead of generating an unknown
> attribute warning on the decl.
>
> 3) Currently, the subjects are a mixture of names based on other td
> files (like Var), and fully-formed named (like VarDecl).  I would like
> to change the file to consistently used full-formed names (VarDecl) --
> otherwise, the tablegen will have to guess at whether the type needs
> to be suffixed with Decl, or does not need any suffix at all (such as
> Stmt nodes).

I don't think there's a need for this. The TableGen backend can
determine whether the AttrSubject inherits from Decl.

> 4) Do something about SubsetSubjects so that I can emit tablegen code
> that works properly with them.
>
> Are there any issues with this?  Or suggestions?
>
> Thanks!
>
> ~Aaron
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list