Improve the accuracy of getSourceRange() for DeclaratorDecl and

TagDecl subclasses when out-of-line template declaration information
is available, from Peter Collingbourne!

llvm-svn: 107686
This commit is contained in:
Douglas Gregor 2010-07-06 18:42:40 +00:00
parent 13d85ea43c
commit ec9c6ae1cb
3 changed files with 46 additions and 6 deletions

View File

@ -436,6 +436,17 @@ public:
DeclInfo = TI;
}
/// getInnerLocStart - Return SourceLocation representing start of source
/// range ignoring outer template declarations.
virtual SourceLocation getInnerLocStart() const { return getLocation(); }
/// getOuterLocStart - Return SourceLocation representing start of source
/// range taking into account any outer template declarations.
SourceLocation getOuterLocStart() const;
SourceRange getSourceRange() const {
return SourceRange(getOuterLocStart(), getLocation());
}
NestedNameSpecifier *getQualifier() const {
return hasExtInfo() ? getExtInfo()->NNS : 0;
}
@ -601,6 +612,7 @@ public:
virtual void Destroy(ASTContext& C);
virtual ~VarDecl();
virtual SourceLocation getInnerLocStart() const;
virtual SourceRange getSourceRange() const;
StorageClass getStorageClass() const { return (StorageClass)SClass; }
@ -1209,7 +1221,7 @@ public:
bool Qualified) const;
virtual SourceRange getSourceRange() const {
return SourceRange(getLocation(), EndRangeLoc);
return SourceRange(getOuterLocStart(), EndRangeLoc);
}
void setLocEnd(SourceLocation E) {
EndRangeLoc = E;
@ -1865,6 +1877,13 @@ public:
SourceLocation getTagKeywordLoc() const { return TagKeywordLoc; }
void setTagKeywordLoc(SourceLocation TKL) { TagKeywordLoc = TKL; }
/// getInnerLocStart - Return SourceLocation representing start of source
/// range ignoring outer template declarations.
virtual SourceLocation getInnerLocStart() const { return TagKeywordLoc; }
/// getOuterLocStart - Return SourceLocation representing start of source
/// range taking into account any outer template declarations.
SourceLocation getOuterLocStart() const;
virtual SourceRange getSourceRange() const;
virtual TagDecl* getCanonicalDecl();

View File

@ -1149,6 +1149,8 @@ public:
return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation();
}
SourceLocation getInnerLocStart() const { return getTemplateKeywordLoc(); }
void Profile(llvm::FoldingSetNodeID &ID) const {
Profile(ID, TemplateArgs.getFlatArgumentList(), TemplateArgs.flat_size(),
getASTContext());

View File

@ -523,6 +523,14 @@ bool NamedDecl::isCXXInstanceMember() const {
// DeclaratorDecl Implementation
//===----------------------------------------------------------------------===//
template <typename DeclT>
static SourceLocation getTemplateOrInnerLocStart(const DeclT *decl) {
if (decl->getNumTemplateParameterLists() > 0)
return decl->getTemplateParameterList(0)->getTemplateLoc();
else
return decl->getInnerLocStart();
}
DeclaratorDecl::~DeclaratorDecl() {}
void DeclaratorDecl::Destroy(ASTContext &C) {
if (hasExtInfo())
@ -566,6 +574,10 @@ void DeclaratorDecl::setQualifierInfo(NestedNameSpecifier *Qualifier,
}
}
SourceLocation DeclaratorDecl::getOuterLocStart() const {
return getTemplateOrInnerLocStart(this);
}
void
QualifierInfo::setTemplateParameterListsInfo(ASTContext &Context,
unsigned NumTPLists,
@ -636,14 +648,17 @@ void VarDecl::Destroy(ASTContext& C) {
VarDecl::~VarDecl() {
}
SourceRange VarDecl::getSourceRange() const {
SourceLocation VarDecl::getInnerLocStart() const {
SourceLocation Start = getTypeSpecStartLoc();
if (Start.isInvalid())
Start = getLocation();
return Start;
}
SourceRange VarDecl::getSourceRange() const {
if (getInit())
return SourceRange(Start, getInit()->getLocEnd());
return SourceRange(Start, getLocation());
return SourceRange(getOuterLocStart(), getInit()->getLocEnd());
return SourceRange(getOuterLocStart(), getLocation());
}
bool VarDecl::isExternC() const {
@ -1544,9 +1559,13 @@ void TagDecl::Destroy(ASTContext &C) {
TypeDecl::Destroy(C);
}
SourceLocation TagDecl::getOuterLocStart() const {
return getTemplateOrInnerLocStart(this);
}
SourceRange TagDecl::getSourceRange() const {
SourceLocation E = RBraceLoc.isValid() ? RBraceLoc : getLocation();
return SourceRange(TagKeywordLoc, E);
return SourceRange(getOuterLocStart(), E);
}
TagDecl* TagDecl::getCanonicalDecl() {