r195287 - Implemented DefaultIntArgument in the table generator and start using it in semantic analysis. Removes some magic numbers.

Aaron Ballman aaron at aaronballman.com
Wed Nov 20 16:28:23 PST 2013


Author: aaronballman
Date: Wed Nov 20 18:28:23 2013
New Revision: 195287

URL: http://llvm.org/viewvc/llvm-project?rev=195287&view=rev
Log:
Implemented DefaultIntArgument in the table generator and start using it in semantic analysis. Removes some magic numbers.

Modified:
    cfe/trunk/include/clang/Basic/Attr.td
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=195287&r1=195286&r2=195287&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Wed Nov 20 18:28:23 2013
@@ -321,7 +321,7 @@ def Const : InheritableAttr {
 
 def Constructor : InheritableAttr {
   let Spellings = [GNU<"constructor">, CXX11<"gnu", "constructor">];
-  let Args = [IntArgument<"Priority", 1>];
+  let Args = [DefaultIntArgument<"Priority", 65535>];
 }
 
 def CUDAConstant : InheritableAttr {
@@ -377,7 +377,7 @@ def Deprecated : InheritableAttr {
 
 def Destructor : InheritableAttr {
   let Spellings = [GNU<"destructor">, CXX11<"gnu", "destructor">];
-  let Args = [IntArgument<"Priority", 1>];
+  let Args = [DefaultIntArgument<"Priority", 65535>];
 }
 
 def ExtVectorType : Attr {

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=195287&r1=195286&r2=195287&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Nov 20 18:28:23 2013
@@ -2035,7 +2035,7 @@ static void handleConstructorAttr(Sema &
     return;
   }
 
-  int priority = 65535; // FIXME: Do not hardcode such constants.
+  int priority = ConstructorAttr::DefaultPriority;
   if (Attr.getNumArgs() > 0) {
     Expr *E = Attr.getArgAsExpr(0);
     llvm::APSInt Idx(32);
@@ -2067,7 +2067,7 @@ static void handleDestructorAttr(Sema &S
     return;
   }
 
-  int priority = 65535; // FIXME: Do not hardcode such constants.
+  int priority = DestructorAttr::DefaultPriority;
   if (Attr.getNumArgs() > 0) {
     Expr *E = Attr.getArgAsExpr(0);
     llvm::APSInt Idx(32);
@@ -2562,7 +2562,7 @@ static void handleSentinelAttr(Sema &S,
     return;
   }
 
-  unsigned sentinel = 0;
+  unsigned sentinel = (unsigned)SentinelAttr::DefaultSentinel;
   if (Attr.getNumArgs() > 0) {
     Expr *E = Attr.getArgAsExpr(0);
     llvm::APSInt Idx(32);
@@ -2583,7 +2583,7 @@ static void handleSentinelAttr(Sema &S,
     sentinel = Idx.getZExtValue();
   }
 
-  unsigned nullPos = 0;
+  unsigned nullPos = (unsigned)SentinelAttr::DefaultNullPos;
   if (Attr.getNumArgs() > 1) {
     Expr *E = Attr.getArgAsExpr(1);
     llvm::APSInt Idx(32);

Modified: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp?rev=195287&r1=195286&r2=195287&view=diff
==============================================================================
--- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Wed Nov 20 18:28:23 2013
@@ -222,6 +222,22 @@ namespace {
     }
   };
 
+  class DefaultSimpleArgument : public SimpleArgument {
+    int64_t Default;
+
+  public:
+    DefaultSimpleArgument(Record &Arg, StringRef Attr,
+                          std::string T, int64_t Default)
+      : SimpleArgument(Arg, Attr, T), Default(Default) {}
+
+    void writeAccessors(raw_ostream &OS) const {
+      SimpleArgument::writeAccessors(OS);
+
+      OS << "\n\n  static const " << getType() << " Default" << getUpperName()
+         << " = " << Default << ";";
+    }
+  };
+
   class StringArgument : public Argument {
   public:
     StringArgument(Record &Arg, StringRef Attr)
@@ -871,6 +887,9 @@ static Argument *createArgument(Record &
     Ptr = new SimpleArgument(Arg, Attr, "IdentifierInfo *");
   else if (ArgName == "BoolArgument") Ptr = new SimpleArgument(Arg, Attr, 
                                                                "bool");
+  else if (ArgName == "DefaultIntArgument")
+    Ptr = new DefaultSimpleArgument(Arg, Attr, "int",
+                                    Arg.getValueAsInt("Default"));
   else if (ArgName == "IntArgument") Ptr = new SimpleArgument(Arg, Attr, "int");
   else if (ArgName == "StringArgument") Ptr = new StringArgument(Arg, Attr);
   else if (ArgName == "TypeArgument") Ptr = new TypeArgument(Arg, Attr);
@@ -888,9 +907,10 @@ static Argument *createArgument(Record &
     Ptr = new VersionArgument(Arg, Attr);
 
   if (!Ptr) {
+    // Search in reverse order so that the most-derived type is handled first.
     std::vector<Record*> Bases = Search->getSuperClasses();
-    for (std::vector<Record*>::iterator i = Bases.begin(), e = Bases.end();
-         i != e; ++i) {
+    for (std::vector<Record*>::reverse_iterator i = Bases.rbegin(),
+         e = Bases.rend(); i != e; ++i) {
       Ptr = createArgument(Arg, Attr, *i);
       if (Ptr)
         break;





More information about the cfe-commits mailing list