Question about Attr.td
Aaron Ballman
aaron at aaronballman.com
Fri Jun 21 06:17:20 PDT 2013
On Thu, Jun 20, 2013 at 7:12 PM, Richard Smith <richard at metafoo.co.uk> wrote:
> 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.
Different ways to skin the same cat, really. Ultimately, I want to be
able to pass in a "thing" and have it answer the "am I allowed to
attach to this" question automatically. Ultimately, I did end up
using a parameter (to support SubsetSubject), so the template isn't
required. I'll adjust the patch I submitted and resubmit later.
>> 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.
As I found out after more searching. ;-) I'm learning as I go with
the tablegen stuff.
~Aaron
More information about the cfe-commits
mailing list