[cfe-commits] r139599 - in /cfe/trunk: include/clang/AST/Attr.h include/clang/Sema/AttributeList.h lib/Parse/ParseDecl.cpp lib/Sema/SemaDeclAttr.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Tue Sep 13 09:05:53 PDT 2011
Author: akirtzidis
Date: Tue Sep 13 11:05:53 2011
New Revision: 139599
URL: http://llvm.org/viewvc/llvm-project?rev=139599&view=rev
Log:
Record the full source range of an attribute.
Modified:
cfe/trunk/include/clang/AST/Attr.h
cfe/trunk/include/clang/Sema/AttributeList.h
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
Modified: cfe/trunk/include/clang/AST/Attr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Attr.h?rev=139599&r1=139598&r2=139599&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Tue Sep 13 11:05:53 2011
@@ -57,7 +57,7 @@
/// Attr - This represents one attribute.
class Attr {
private:
- SourceLocation Loc;
+ SourceRange Range;
unsigned AttrKind : 16;
protected:
@@ -85,8 +85,8 @@
}
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 @@
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; }
Modified: cfe/trunk/include/clang/Sema/AttributeList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/AttributeList.h?rev=139599&r1=139598&r2=139599&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/AttributeList.h (original)
+++ cfe/trunk/include/clang/Sema/AttributeList.h Tue Sep 13 11:05:53 2011
@@ -56,7 +56,7 @@
IdentifierInfo *AttrName;
IdentifierInfo *ScopeName;
IdentifierInfo *ParmName;
- SourceLocation AttrLoc;
+ SourceRange AttrRange;
SourceLocation ScopeLoc;
SourceLocation ParmLoc;
@@ -114,13 +114,13 @@
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 @@
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 @@
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 @@
};
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 @@
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 @@
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 @@
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 @@
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);
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=139599&r1=139598&r2=139599&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Tue Sep 13 11:05:53 2011
@@ -195,8 +195,8 @@
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 @@
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 @@
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 @@
}
// 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 @@
}
// Record this attribute
- attrs.addNew(&Availability, AvailabilityLoc,
+ attrs.addNew(&Availability, SourceRange(AvailabilityLoc, RParenLoc),
0, SourceLocation(),
Platform, PlatformLoc,
Changes[Introduced],
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=139599&r1=139598&r2=139599&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Tue Sep 13 11:05:53 2011
@@ -1998,7 +1998,7 @@
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 @@
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 @@
// 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;
}
}
More information about the cfe-commits
mailing list