[PATCH] Alignment attribute printing.

Richard Smith richard at metafoo.co.uk
Wed Jan 30 12:40:37 PST 2013


Hi!

On Mon, Jan 28, 2013 at 9:20 PM, Michael Han <fragmentshaders at gmail.com> wrote:
> Hi,
>
> Attached patch fixes alignment attribute printing. It removes the
> "IsMSDeclSpec" argument of alignment attribute, and uses the spelling list
> index to decide if an alignment attribute is in the form of
> __declspec(align()) or not. Please review, thanks!

I'm not happy with hardcoding a spelling index here. I suggest you
teach TableGen to generate additional members of AlignedAttr to
identify which form of spelling was used. Strawman:

--- include/clang/Basic/Attr.td (revision 173899)
+++ include/clang/Basic/Attr.td (working copy)
@@ -93,11 +93,18 @@
 }
 class Keyword<string name> : Spelling<name, "Keyword">;

+class Accessor<string name, list<Spelling> spellings> {
+  string Name = name;
+  list<Spelling> Spellings = spellings;
+}
+
 class Attr {
   // The various ways in which an attribute can be spelled in source
   list<Spelling> Spellings;
   // The things to which an attribute can appertain
   list<AttrSubject> Subjects;
+  // Accessors which should be generated for the attribute
+  list<Accessor> Accessors;
   // The arguments allowed on an attribute
   list<Argument> Args = [];
   // Set to true for attributes with arguments which require delayed parsing.
@@ -151,6 +158,8 @@
 def Aligned : InheritableAttr {
   let Spellings = [GNU<"aligned">, Declspec<"align">, CXX11<"gnu", "aligned">,
                    Keyword<"alignas">, Keyword<"_Alignas">];
+  let Accessors = [Accessor<"isGNU", [GNU<"aligned">, CXX11<"gnu",
"aligned">]>,
+                   Accessor<"isAlignas", [Keyword<"alignas">,
Keyword<"_Alignas">]>];
   let Subjects = [NonBitField, NormalVar, Tag];
   let Args = [AlignedArgument<"Alignment">, BoolArgument<"IsMSDeclSpec">];
 }


... generating something like ...

class AlignedAttr {
  /* ... */
  bool isGNU() const { return SpellingListIndex == 0 ||
SpellingListIndex == 2; }
  bool isAlignas() const { return SpellingListIndex == 3 ||
SpellingListIndex == 4; }
  /* ... */
};



More information about the cfe-commits mailing list