]> granicus.if.org Git - clang/commitdiff
Record the full source range of an attribute.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 13 Sep 2011 16:05:53 +0000 (16:05 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 13 Sep 2011 16:05:53 +0000 (16:05 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139599 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Attr.h
include/clang/Sema/AttributeList.h
lib/Parse/ParseDecl.cpp
lib/Sema/SemaDeclAttr.cpp

index 17f0218a8b4ac8fec5454e34cbc8cfc87b7b2431..7d57cd883fdb858668bae5a00c98cd180632b078 100644 (file)
@@ -57,7 +57,7 @@ namespace clang {
 /// Attr - This represents one attribute.
 class Attr {
 private:
-  SourceLocation Loc;
+  SourceRange Range;
   unsigned AttrKind : 16;
 
 protected:
@@ -85,8 +85,8 @@ public:
   }
 
 protected:
-  Attr(attr::Kind AK, SourceLocation L)
-    : Loc(L), AttrKind(AK), Inherited(false) {}
+  Attr(attr::Kind AK, SourceRange R)
+    : Range(R), AttrKind(AK), Inherited(false) {}
 
 public:
 
@@ -94,8 +94,9 @@ public:
     return static_cast<attr::Kind>(AttrKind);
   }
 
-  SourceLocation getLocation() const { return Loc; }
-  void setLocation(SourceLocation L) { Loc = L; }
+  SourceLocation getLocation() const { return Range.getBegin(); }
+  SourceRange getRange() const { return Range; }
+  void setRange(SourceRange R) { Range = R; }
 
   bool isInherited() const { return Inherited; }
 
index 674e13a3dff7801cd19f779d65514b4628891485..a44f6fae3324a80a11a1e4d73ec302e1973b30c7 100644 (file)
@@ -56,7 +56,7 @@ private:
   IdentifierInfo *AttrName;
   IdentifierInfo *ScopeName;
   IdentifierInfo *ParmName;
-  SourceLocation AttrLoc;
+  SourceRange AttrRange;
   SourceLocation ScopeLoc;
   SourceLocation ParmLoc;
 
@@ -114,13 +114,13 @@ private:
 
   size_t allocated_size() const;
 
-  AttributeList(IdentifierInfo *attrName, SourceLocation attrLoc,
+  AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
                 IdentifierInfo *scopeName, SourceLocation scopeLoc,
                 IdentifierInfo *parmName, SourceLocation parmLoc,
                 Expr **args, unsigned numArgs,
                 bool declspec, bool cxx0x)
     : AttrName(attrName), ScopeName(scopeName), ParmName(parmName),
-      AttrLoc(attrLoc), ScopeLoc(scopeLoc), ParmLoc(parmLoc),
+      AttrRange(attrRange), ScopeLoc(scopeLoc), ParmLoc(parmLoc),
       NumArgs(numArgs),
       DeclspecAttribute(declspec), CXX0XAttribute(cxx0x), Invalid(false),
       IsAvailability(false), NextInPosition(0), NextInPool(0) {
@@ -128,7 +128,7 @@ private:
     AttrKind = getKind(getName());
   }
 
-  AttributeList(IdentifierInfo *attrName, SourceLocation attrLoc,
+  AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
                 IdentifierInfo *scopeName, SourceLocation scopeLoc,
                 IdentifierInfo *parmName, SourceLocation parmLoc,
                 const AvailabilityChange &introduced,
@@ -137,7 +137,7 @@ private:
                 SourceLocation unavailable,
                 bool declspec, bool cxx0x)
     : AttrName(attrName), ScopeName(scopeName), ParmName(parmName),
-      AttrLoc(attrLoc), ScopeLoc(scopeLoc), ParmLoc(parmLoc),
+      AttrRange(attrRange), ScopeLoc(scopeLoc), ParmLoc(parmLoc),
       NumArgs(0), DeclspecAttribute(declspec), CXX0XAttribute(cxx0x),
       Invalid(false), IsAvailability(true), UnavailableLoc(unavailable),
       NextInPosition(0), NextInPool(0) {
@@ -268,7 +268,8 @@ public:
   };
 
   IdentifierInfo *getName() const { return AttrName; }
-  SourceLocation getLoc() const { return AttrLoc; }
+  SourceLocation getLoc() const { return AttrRange.getBegin(); }
+  SourceRange getRange() const { return AttrRange; }
   
   bool hasScope() const { return ScopeName; }
   IdentifierInfo *getScopeName() const { return ScopeName; }
@@ -459,21 +460,21 @@ public:
     if (Head) Factory.reclaimPool(Head);
   }
 
-  AttributeList *create(IdentifierInfo *attrName, SourceLocation attrLoc,
+  AttributeList *create(IdentifierInfo *attrName, SourceRange attrRange,
                         IdentifierInfo *scopeName, SourceLocation scopeLoc,
                         IdentifierInfo *parmName, SourceLocation parmLoc,
                         Expr **args, unsigned numArgs,
                         bool declspec = false, bool cxx0x = false) {
     void *memory = allocate(sizeof(AttributeList)
                             + numArgs * sizeof(Expr*));
-    return add(new (memory) AttributeList(attrName, attrLoc,
+    return add(new (memory) AttributeList(attrName, attrRange,
                                           scopeName, scopeLoc,
                                           parmName, parmLoc,
                                           args, numArgs,
                                           declspec, cxx0x));
   }
 
-  AttributeList *create(IdentifierInfo *attrName, SourceLocation attrLoc,
+  AttributeList *create(IdentifierInfo *attrName, SourceRange attrRange,
                         IdentifierInfo *scopeName, SourceLocation scopeLoc,
                         IdentifierInfo *parmName, SourceLocation parmLoc,
                         const AvailabilityChange &introduced,
@@ -482,7 +483,7 @@ public:
                         SourceLocation unavailable,
                         bool declspec = false, bool cxx0x = false) {
     void *memory = allocate(AttributeFactory::AvailabilityAllocSize);
-    return add(new (memory) AttributeList(attrName, attrLoc,
+    return add(new (memory) AttributeList(attrName, attrRange,
                                           scopeName, scopeLoc,
                                           parmName, parmLoc,
                                           introduced, deprecated, obsoleted,
@@ -585,19 +586,19 @@ public:
   AttributeList *&getListRef() { return list; }
 
 
-  AttributeList *addNew(IdentifierInfo *attrName, SourceLocation attrLoc,
+  AttributeList *addNew(IdentifierInfo *attrName, SourceRange attrRange,
                         IdentifierInfo *scopeName, SourceLocation scopeLoc,
                         IdentifierInfo *parmName, SourceLocation parmLoc,
                         Expr **args, unsigned numArgs,
                         bool declspec = false, bool cxx0x = false) {
     AttributeList *attr =
-      pool.create(attrName, attrLoc, scopeName, scopeLoc, parmName, parmLoc,
+      pool.create(attrName, attrRange, scopeName, scopeLoc, parmName, parmLoc,
                   args, numArgs, declspec, cxx0x);
     add(attr);
     return attr;
   }
 
-  AttributeList *addNew(IdentifierInfo *attrName, SourceLocation attrLoc,
+  AttributeList *addNew(IdentifierInfo *attrName, SourceRange attrRange,
                         IdentifierInfo *scopeName, SourceLocation scopeLoc,
                         IdentifierInfo *parmName, SourceLocation parmLoc,
                         const AvailabilityChange &introduced,
@@ -606,7 +607,7 @@ public:
                         SourceLocation unavailable,
                         bool declspec = false, bool cxx0x = false) {
     AttributeList *attr =
-      pool.create(attrName, attrLoc, scopeName, scopeLoc, parmName, parmLoc,
+      pool.create(attrName, attrRange, scopeName, scopeLoc, parmName, parmLoc,
                   introduced, deprecated, obsoleted, unavailable,
                   declspec, cxx0x);
     add(attr);
index 197e446fd383a7a76f1e0cf6e5cd08f9f06480e9..16c25a47904fb37dffeb999f81158728ca4804ea 100644 (file)
@@ -195,8 +195,8 @@ void Parser::ParseGNUAttributeArgs(IdentifierInfo *AttrName,
 
     if (Tok.is(tok::r_paren)) {
       // __attribute__(( mode(byte) ))
-      ConsumeParen(); // ignore the right paren loc for now
-      Attrs.addNew(AttrName, AttrNameLoc, 0, AttrNameLoc,
+      SourceLocation RParen = ConsumeParen();
+      Attrs.addNew(AttrName, SourceRange(AttrNameLoc, RParen), 0, AttrNameLoc,
                    ParmName, ParmLoc, 0, 0);
     } else if (Tok.is(tok::comma)) {
       ConsumeToken();
@@ -219,20 +219,21 @@ void Parser::ParseGNUAttributeArgs(IdentifierInfo *AttrName,
         ConsumeToken(); // Eat the comma, move to the next argument
       }
       if (ArgExprsOk && Tok.is(tok::r_paren)) {
-        ConsumeParen(); // ignore the right paren loc for now
-        Attrs.addNew(AttrName, AttrNameLoc, 0, AttrNameLoc,
+        SourceLocation RParen = ConsumeParen();
+        Attrs.addNew(AttrName, SourceRange(AttrNameLoc, RParen), 0, AttrNameLoc,
                      ParmName, ParmLoc, ArgExprs.take(), ArgExprs.size());
       }
     }
   } else { // not an identifier
     switch (Tok.getKind()) {
-    case tok::r_paren:
+    case tok::r_paren: {
     // parse a possibly empty comma separated list of expressions
       // __attribute__(( nonnull() ))
-      ConsumeParen(); // ignore the right paren loc for now
-      Attrs.addNew(AttrName, AttrNameLoc, 0, AttrNameLoc,
+      SourceLocation RParen = ConsumeParen();
+      Attrs.addNew(AttrName, SourceRange(AttrNameLoc, RParen), 0, AttrNameLoc,
                    0, SourceLocation(), 0, 0);
       break;
+    }
     case tok::kw_char:
     case tok::kw_wchar_t:
     case tok::kw_char16_t:
@@ -248,16 +249,16 @@ void Parser::ParseGNUAttributeArgs(IdentifierInfo *AttrName,
     case tok::kw_double:
     case tok::kw_void:
     case tok::kw_typeof: {
-      AttributeList *attr
-        = Attrs.addNew(AttrName, AttrNameLoc, 0, AttrNameLoc,
-                       0, SourceLocation(), 0, 0);
-      if (attr->getKind() == AttributeList::AT_IBOutletCollection)
-        Diag(Tok, diag::err_iboutletcollection_builtintype);
       // If it's a builtin type name, eat it and expect a rparen
       // __attribute__(( vec_type_hint(char) ))
-      ConsumeToken();
+      SourceLocation EndLoc = ConsumeToken();
       if (Tok.is(tok::r_paren))
-        ConsumeParen();
+        EndLoc = ConsumeParen();
+      AttributeList *attr
+        = Attrs.addNew(AttrName, SourceRange(AttrNameLoc, EndLoc), 0,
+                       AttrNameLoc, 0, SourceLocation(), 0, 0);
+      if (attr->getKind() == AttributeList::AT_IBOutletCollection)
+        Diag(Tok, diag::err_iboutletcollection_builtintype);
       break;
     }
     default:
@@ -281,8 +282,8 @@ void Parser::ParseGNUAttributeArgs(IdentifierInfo *AttrName,
       }
       // Match the ')'.
       if (ArgExprsOk && Tok.is(tok::r_paren)) {
-        ConsumeParen(); // ignore the right paren loc for now
-        Attrs.addNew(AttrName, AttrNameLoc, 0,
+        SourceLocation RParen = ConsumeParen();
+        Attrs.addNew(AttrName, SourceRange(AttrNameLoc, RParen), 0,
                      AttrNameLoc, 0, SourceLocation(),
                      ArgExprs.take(), ArgExprs.size());
       }
@@ -695,7 +696,7 @@ void Parser::ParseAvailabilityAttribute(IdentifierInfo &Availability,
   }
 
   // Record this attribute
-  attrs.addNew(&Availability, AvailabilityLoc
+  attrs.addNew(&Availability, SourceRange(AvailabilityLoc, RParenLoc)
                0, SourceLocation(),
                Platform, PlatformLoc,
                Changes[Introduced],
index 2f2e280f714d4b6d8de9c0aea637aa19afbe8c28..fc8583229bbcdfc73a272d1408c8d74b802bab91 100644 (file)
@@ -1998,7 +1998,7 @@ static void handleNothrowAttr(Sema &S, Decl *D, const AttributeList &Attr) {
   
   if (NoThrowAttr *Existing = D->getAttr<NoThrowAttr>()) {
     if (Existing->getLocation().isInvalid())
-      Existing->setLocation(Attr.getLoc());
+      Existing->setRange(Attr.getRange());
   } else {
     D->addAttr(::new (S.Context) NoThrowAttr(Attr.getLoc(), S.Context));
   }
@@ -2013,7 +2013,7 @@ static void handleConstAttr(Sema &S, Decl *D, const AttributeList &Attr) {
 
   if (ConstAttr *Existing = D->getAttr<ConstAttr>()) {
    if (Existing->getLocation().isInvalid())
-     Existing->setLocation(Attr.getLoc());
+     Existing->setRange(Attr.getRange());
   } else {
     D->addAttr(::new (S.Context) ConstAttr(Attr.getLoc(), S.Context));
   }
@@ -2393,7 +2393,7 @@ static void handleFormatAttr(Sema &S, Decl *D, const AttributeList &Attr) {
       // If we don't have a valid location for this attribute, adopt the
       // location.
       if (f->getLocation().isInvalid())
-        f->setLocation(Attr.getLoc());
+        f->setRange(Attr.getRange());
       return;
     }
   }