summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorAbramo Bagnara <abramo.bagnara@gmail.com>2011-03-08 16:41:52 +0000
committerAbramo Bagnara <abramo.bagnara@gmail.com>2011-03-08 16:41:52 +0000
commitea94788cf4ed2b7470ecc85103035d25887ee8e8 (patch)
tree564467b3f113ab7034703788bf6df44d7fb0d699 /clang/lib
parente1aa67cff57e3185a56613950a10a83b4523b352 (diff)
downloadbcm5719-llvm-ea94788cf4ed2b7470ecc85103035d25887ee8e8.tar.gz
bcm5719-llvm-ea94788cf4ed2b7470ecc85103035d25887ee8e8.zip
Fixed source range for StaticAssertDecl and LinkageSpecDecl. Fixed source range for declarations using postfix types.
llvm-svn: 127251
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/AST/Decl.cpp69
-rw-r--r--clang/lib/AST/DeclCXX.cpp14
-rw-r--r--clang/lib/AST/DeclTemplate.cpp6
-rw-r--r--clang/lib/AST/TypeLoc.cpp27
-rw-r--r--clang/lib/Parse/ParseDeclCXX.cpp9
-rw-r--r--clang/lib/Sema/SemaDecl.cpp2
-rw-r--r--clang/lib/Sema/SemaDeclCXX.cpp16
-rw-r--r--clang/lib/Sema/SemaTemplateInstantiateDecl.cpp3
-rw-r--r--clang/lib/Serialization/ASTReaderDecl.cpp7
-rw-r--r--clang/lib/Serialization/ASTWriterDecl.cpp2
10 files changed, 125 insertions, 30 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index c6d9391e0a8..a7f6c45dd49 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -975,6 +975,55 @@ SourceLocation DeclaratorDecl::getOuterLocStart() const {
return getTemplateOrInnerLocStart(this);
}
+namespace {
+
+// Helper function: returns true if QT is or contains a type
+// having a postfix component.
+bool typeIsPostfix(clang::QualType QT) {
+ while (true) {
+ const Type* T = QT.getTypePtr();
+ switch (T->getTypeClass()) {
+ default:
+ return false;
+ case Type::Pointer:
+ QT = cast<PointerType>(T)->getPointeeType();
+ break;
+ case Type::BlockPointer:
+ QT = cast<BlockPointerType>(T)->getPointeeType();
+ break;
+ case Type::MemberPointer:
+ QT = cast<MemberPointerType>(T)->getPointeeType();
+ break;
+ case Type::LValueReference:
+ case Type::RValueReference:
+ QT = cast<ReferenceType>(T)->getPointeeType();
+ break;
+ case Type::PackExpansion:
+ QT = cast<PackExpansionType>(T)->getPattern();
+ break;
+ case Type::Paren:
+ case Type::ConstantArray:
+ case Type::DependentSizedArray:
+ case Type::IncompleteArray:
+ case Type::VariableArray:
+ case Type::FunctionProto:
+ case Type::FunctionNoProto:
+ return true;
+ }
+ }
+}
+
+} // namespace
+
+SourceRange DeclaratorDecl::getSourceRange() const {
+ SourceLocation RangeEnd = getLocation();
+ if (TypeSourceInfo *TInfo = getTypeSourceInfo()) {
+ if (typeIsPostfix(TInfo->getType()))
+ RangeEnd = TInfo->getTypeLoc().getSourceRange().getEnd();
+ }
+ return SourceRange(getOuterLocStart(), RangeEnd);
+}
+
void
QualifierInfo::setTemplateParameterListsInfo(ASTContext &Context,
unsigned NumTPLists,
@@ -1035,7 +1084,7 @@ void VarDecl::setStorageClass(StorageClass SC) {
SourceRange VarDecl::getSourceRange() const {
if (getInit())
return SourceRange(getOuterLocStart(), getInit()->getLocEnd());
- return SourceRange(getOuterLocStart(), getLocation());
+ return DeclaratorDecl::getSourceRange();
}
bool VarDecl::isExternC() const {
@@ -1927,6 +1976,10 @@ bool FunctionDecl::isOutOfLine() const {
return false;
}
+SourceRange FunctionDecl::getSourceRange() const {
+ return SourceRange(getOuterLocStart(), EndRangeLoc);
+}
+
//===----------------------------------------------------------------------===//
// FieldDecl Implementation
//===----------------------------------------------------------------------===//
@@ -1969,8 +2022,9 @@ unsigned FieldDecl::getFieldIndex() const {
}
SourceRange FieldDecl::getSourceRange() const {
- return SourceRange(getInnerLocStart(),
- isBitField() ? BitWidth->getLocEnd() : getLocation());
+ if (isBitField())
+ return SourceRange(getInnerLocStart(), BitWidth->getLocEnd());
+ return DeclaratorDecl::getSourceRange();
}
//===----------------------------------------------------------------------===//
@@ -2284,6 +2338,15 @@ TypedefDecl *TypedefDecl::Create(ASTContext &C, DeclContext *DC,
return new (C) TypedefDecl(DC, StartLoc, IdLoc, Id, TInfo);
}
+SourceRange TypedefDecl::getSourceRange() const {
+ SourceLocation RangeEnd = getLocation();
+ if (TypeSourceInfo *TInfo = getTypeSourceInfo()) {
+ if (typeIsPostfix(TInfo->getType()))
+ RangeEnd = TInfo->getTypeLoc().getSourceRange().getEnd();
+ }
+ return SourceRange(getLocStart(), RangeEnd);
+}
+
FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C, DeclContext *DC,
StringLiteral *Str,
SourceLocation AsmLoc,
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index abed12de2e0..14e81231bfc 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -1273,10 +1273,11 @@ CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD,
LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C,
DeclContext *DC,
- SourceLocation L,
+ SourceLocation ExternLoc,
+ SourceLocation LangLoc,
LanguageIDs Lang,
SourceLocation RBraceLoc) {
- return new (C) LinkageSpecDecl(DC, L, Lang, RBraceLoc);
+ return new (C) LinkageSpecDecl(DC, ExternLoc, LangLoc, Lang, RBraceLoc);
}
UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC,
@@ -1379,9 +1380,12 @@ UnresolvedUsingTypenameDecl::Create(ASTContext &C, DeclContext *DC,
}
StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC,
- SourceLocation L, Expr *AssertExpr,
- StringLiteral *Message) {
- return new (C) StaticAssertDecl(DC, L, AssertExpr, Message);
+ SourceLocation StaticAssertLoc,
+ Expr *AssertExpr,
+ StringLiteral *Message,
+ SourceLocation RParenLoc) {
+ return new (C) StaticAssertDecl(DC, StaticAssertLoc, AssertExpr, Message,
+ RParenLoc);
}
static const char *getAccessName(AccessSpecifier AS) {
diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index 6fd4d7ec076..de0e71ebace 100644
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -508,10 +508,10 @@ NonTypeTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC,
}
SourceRange NonTypeTemplateParmDecl::getSourceRange() const {
- SourceLocation End = getLocation();
if (hasDefaultArgument() && !defaultArgumentWasInherited())
- End = getDefaultArgument()->getSourceRange().getEnd();
- return SourceRange(getOuterLocStart(), End);
+ return SourceRange(getOuterLocStart(),
+ getDefaultArgument()->getSourceRange().getEnd());
+ return DeclaratorDecl::getSourceRange();
}
SourceLocation NonTypeTemplateParmDecl::getDefaultArgumentLoc() const {
diff --git a/clang/lib/AST/TypeLoc.cpp b/clang/lib/AST/TypeLoc.cpp
index d42f42ed154..0873e837d82 100644
--- a/clang/lib/AST/TypeLoc.cpp
+++ b/clang/lib/AST/TypeLoc.cpp
@@ -118,18 +118,37 @@ SourceLocation TypeLoc::getBeginLoc() const {
SourceLocation TypeLoc::getEndLoc() const {
TypeLoc Cur = *this;
+ TypeLoc Last;
while (true) {
switch (Cur.getTypeLocClass()) {
default:
+ if (!Last)
+ Last = Cur;
+ return Last.getLocalSourceRange().getEnd();
+ case Paren:
+ case ConstantArray:
+ case DependentSizedArray:
+ case IncompleteArray:
+ case VariableArray:
+ case FunctionProto:
+ case FunctionNoProto:
+ Last = Cur;
+ break;
+ case Pointer:
+ case BlockPointer:
+ case MemberPointer:
+ case LValueReference:
+ case RValueReference:
+ case PackExpansion:
+ if (!Last)
+ Last = Cur;
break;
case Qualified:
case Elaborated:
- Cur = Cur.getNextTypeLoc();
- continue;
+ break;
}
- break;
+ Cur = Cur.getNextTypeLoc();
}
- return Cur.getLocalSourceRange().getEnd();
}
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 1f0e2828221..c214610f644 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -194,9 +194,9 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, unsigned Context) {
ParseScope LinkageScope(this, Scope::DeclScope);
Decl *LinkageSpec
= Actions.ActOnStartLinkageSpecification(getCurScope(),
- /*FIXME: */SourceLocation(),
+ DS.getSourceRange().getBegin(),
Loc, Lang,
- Tok.is(tok::l_brace)? Tok.getLocation()
+ Tok.is(tok::l_brace) ? Tok.getLocation()
: SourceLocation());
ParsedAttributesWithRange attrs;
@@ -441,14 +441,15 @@ Decl *Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd){
if (AssertMessage.isInvalid())
return 0;
- MatchRHSPunctuation(tok::r_paren, LParenLoc);
+ SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
DeclEnd = Tok.getLocation();
ExpectAndConsumeSemi(diag::err_expected_semi_after_static_assert);
return Actions.ActOnStaticAssertDeclaration(StaticAssertLoc,
AssertExpr.take(),
- AssertMessage.take());
+ AssertMessage.take(),
+ RParenLoc);
}
/// ParseDecltypeSpecifier - Parse a C++0x decltype specifier.
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 995b2b9ef6b..978e7a2e1e9 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -4254,7 +4254,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
RegisterLocallyScopedExternCDecl(NewFD, Previous, S);
// Set this FunctionDecl's range up to the right paren.
- NewFD->setLocEnd(D.getSourceRange().getEnd());
+ NewFD->setRangeEnd(D.getSourceRange().getEnd());
if (getLangOptions().CPlusPlus) {
if (FunctionTemplate) {
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index bdfdb177043..a2528a6140c 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -6588,7 +6588,7 @@ Decl *Sema::ActOnStartLinkageSpecification(Scope *S, SourceLocation ExternLoc,
// FIXME: Add all the various semantics of linkage specifications
LinkageSpecDecl *D = LinkageSpecDecl::Create(Context, CurContext,
- LangLoc, Language);
+ ExternLoc, LangLoc, Language);
CurContext->addDecl(D);
PushDeclContext(S, D);
return D;
@@ -6788,21 +6788,23 @@ Decl *Sema::ActOnExceptionDeclarator(Scope *S, Declarator &D) {
return ExDecl;
}
-Decl *Sema::ActOnStaticAssertDeclaration(SourceLocation AssertLoc,
+Decl *Sema::ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc,
Expr *AssertExpr,
- Expr *AssertMessageExpr_) {
+ Expr *AssertMessageExpr_,
+ SourceLocation RParenLoc) {
StringLiteral *AssertMessage = cast<StringLiteral>(AssertMessageExpr_);
if (!AssertExpr->isTypeDependent() && !AssertExpr->isValueDependent()) {
llvm::APSInt Value(32);
if (!AssertExpr->isIntegerConstantExpr(Value, Context)) {
- Diag(AssertLoc, diag::err_static_assert_expression_is_not_constant) <<
+ Diag(StaticAssertLoc,
+ diag::err_static_assert_expression_is_not_constant) <<
AssertExpr->getSourceRange();
return 0;
}
if (Value == 0) {
- Diag(AssertLoc, diag::err_static_assert_failed)
+ Diag(StaticAssertLoc, diag::err_static_assert_failed)
<< AssertMessage->getString() << AssertExpr->getSourceRange();
}
}
@@ -6810,8 +6812,8 @@ Decl *Sema::ActOnStaticAssertDeclaration(SourceLocation AssertLoc,
if (DiagnoseUnexpandedParameterPack(AssertExpr, UPPC_StaticAssertExpression))
return 0;
- Decl *Decl = StaticAssertDecl::Create(Context, CurContext, AssertLoc,
- AssertExpr, AssertMessage);
+ Decl *Decl = StaticAssertDecl::Create(Context, CurContext, StaticAssertLoc,
+ AssertExpr, AssertMessage, RParenLoc);
CurContext->addDecl(Decl);
return Decl;
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index d3672689fae..1d4f3359ed0 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -528,7 +528,8 @@ Decl *TemplateDeclInstantiator::VisitStaticAssertDecl(StaticAssertDecl *D) {
D->getMessage();
return SemaRef.ActOnStaticAssertDeclaration(D->getLocation(),
InstantiatedAssertExpr.get(),
- Message.get());
+ Message.get(),
+ D->getRParenLoc());
}
Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) {
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp
index e07bba4f6b6..8d32bde5fca 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -744,6 +744,7 @@ void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
VisitDecl(D);
D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
+ D->setExternLoc(ReadSourceLocation(Record, Idx));
D->setRBraceLoc(ReadSourceLocation(Record, Idx));
}
@@ -1241,6 +1242,7 @@ void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
VisitDecl(D);
D->AssertExpr = Reader.ReadExpr(F);
D->Message = cast<StringLiteral>(Reader.ReadExpr(F));
+ D->RParenLoc = ReadSourceLocation(Record, Idx);
}
std::pair<uint64_t, uint64_t>
@@ -1440,7 +1442,7 @@ Decl *ASTReader::ReadDeclRecord(unsigned Index, DeclID ID) {
DeclarationName(), QualType(), 0);
break;
case DECL_LINKAGE_SPEC:
- D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
+ D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(), SourceLocation(),
(LinkageSpecDecl::LanguageIDs)0,
SourceLocation());
break;
@@ -1538,7 +1540,8 @@ Decl *ASTReader::ReadDeclRecord(unsigned Index, DeclID ID) {
false, 0, 0);
break;
case DECL_STATIC_ASSERT:
- D = StaticAssertDecl::Create(*Context, 0, SourceLocation(), 0, 0);
+ D = StaticAssertDecl::Create(*Context, 0, SourceLocation(), 0, 0,
+ SourceLocation());
break;
case DECL_OBJC_METHOD:
diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp
index 128361e4bb2..a5c43980420 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -648,6 +648,7 @@ void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) {
void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
VisitDecl(D);
Record.push_back(D->getLanguage());
+ Writer.AddSourceLocation(D->getExternLoc(), Record);
Writer.AddSourceLocation(D->getRBraceLoc(), Record);
Code = serialization::DECL_LINKAGE_SPEC;
}
@@ -1054,6 +1055,7 @@ void ASTDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) {
VisitDecl(D);
Writer.AddStmt(D->getAssertExpr());
Writer.AddStmt(D->getMessage());
+ Writer.AddSourceLocation(D->getRParenLoc(), Record);
Code = serialization::DECL_STATIC_ASSERT;
}
OpenPOWER on IntegriCloud