[PATCH] Initial support for Attribute subjects

Richard Smith richard at metafoo.co.uk
Wed Jul 10 12:53:12 PDT 2013

+      else if ((*I)->isSubClassOf("SubsetSubject")) {
+        std::string FN, TN;
+        bool IsDecl = writeAppertainsToSubjectSubsetDefinition(OS, *I, FN, TN);
+        std::string C = FN + "(cast<" + TN + ">(P))";

This cast<> doesn't look right: we can get here if the potential
subject is not a TN, can't we?

How are you intending that process of creating and adding attributes
will work once this lands? Right now, the usual flow of handleFooAttr

For each entity where we want to apply the attribute:
 * Check attribute appertains to entity
 * Perform other semantic checks on the attribute and on whether it
can be attached to the entity
 * Create FooAttr instance and add it

With appertainsTo being a method on FooAttr, that won't work. Perhaps
we can flip this around:

 * Perform semantic checks on the attribute by itself
 * Create FooAttr from the AttributeList
 * For each entity where we want to apply the attribute:
    * Check whether it appertains to the entity
    * Perform semantic checks on the (attribute, entity) pair
    * Add it

There are a couple of cases where we need to modify the attribute once
we see what it's being applied to; those don't look too hard to
support but are something to keep in mind.

On Mon, Jun 24, 2013 at 10:34 AM, Aaron Ballman <aaron at aaronballman.com> wrote:
> Based on feedback from Richard, here is another pass at modifying
> tablegen for Subjects support.  The delta here is that templates have
> been removed and replaced by a method pair (one for Decl and one for
> Stmt).  The usage is still the same as before: you can call
> appertainsTo and pass in something you want to know whether the
> attribute appertains to it or not, and it will return a Boolean.
> ~Aaron
> On Thu, Jun 20, 2013 at 5:34 PM, Aaron Ballman <aaron at aaronballman.com> wrote:
>> This patch adds support for the Subjects part of the Attr tablegen
>> file.  Specifically, it modifies tablegen to pay attention to
>> Subjects, and emit a templated member function for attribute
>> subclasses called appertainTo.  The purpose is to be able to determine
>> whether a given attribute appertains to a particular subject.
>> template <typename Subject>
>> bool appertainTo(const Subject *S) const;
>> If the attribute has no subjects, then the default behavior of
>> appertainTo is to return true.  This makes it backwards compatible
>> with the fact that we've always ignored subjects previously (and many
>> attributes do not have a specific subject specified).
>> If the attribute does have subjects, then the default appertainTo will
>> return false, but specializations will be generated that return true
>> for each subject case.  If the subject happens to be a SubsetSubject,
>> the code from CheckCode is emitted (hence the reason for having the
>> subject passed into the function) and the proper base is taken from
>> the subject.
>> ~Aaron

More information about the cfe-commits mailing list