summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/TypeLoc.cpp
diff options
context:
space:
mode:
authorAbramo Bagnara <abramo.bagnara@bugseng.com>2012-10-04 21:42:10 +0000
committerAbramo Bagnara <abramo.bagnara@bugseng.com>2012-10-04 21:42:10 +0000
commitaeeb989cc4dccddf1d73e53f40dc36227efd1629 (patch)
treeead8f06d734848127fb92ac9a5c56d6db6810957 /clang/lib/AST/TypeLoc.cpp
parent0d4fce1c2e1ddecf45cc906329f0f7de19e8d91b (diff)
Fixed FunctionTypeLoc source range.
llvm-svn: 165259
Diffstat (limited to 'clang/lib/AST/TypeLoc.cpp')
-rw-r--r--clang/lib/AST/TypeLoc.cpp50
1 files changed, 48 insertions, 2 deletions
diff --git a/clang/lib/AST/TypeLoc.cpp b/clang/lib/AST/TypeLoc.cpp
index 4c103dbf544a..de9d22ad9d13 100644
--- a/clang/lib/AST/TypeLoc.cpp
+++ b/clang/lib/AST/TypeLoc.cpp
@@ -98,6 +98,7 @@ void TypeLoc::initializeImpl(ASTContext &Context, TypeLoc TL,
SourceLocation TypeLoc::getBeginLoc() const {
TypeLoc Cur = *this;
+ SourceLocation SavedParenLoc;
while (true) {
switch (Cur.getTypeLocClass()) {
// FIXME: Currently QualifiedTypeLoc does not have a source range
@@ -106,6 +107,44 @@ SourceLocation TypeLoc::getBeginLoc() const {
case DependentName:
case DependentTemplateSpecialization:
break;
+
+ case Paren:
+ // Save local source begin, if still unset.
+ if (SavedParenLoc.isInvalid())
+ SavedParenLoc = Cur.getLocalSourceRange().getBegin();
+ Cur = Cur.getNextTypeLoc();
+ assert(!Cur.isNull());
+ continue;
+ break;
+
+ case Pointer:
+ case BlockPointer:
+ case MemberPointer:
+ case ObjCObjectPointer:
+ case LValueReference:
+ case RValueReference:
+ case ConstantArray:
+ case DependentSizedArray:
+ case IncompleteArray:
+ case VariableArray:
+ case FunctionNoProto:
+ // Discard previously saved paren loc, if any.
+ SavedParenLoc = SourceLocation();
+ Cur = Cur.getNextTypeLoc();
+ assert(!Cur.isNull());
+ continue;
+ break;
+
+ case FunctionProto:
+ // Discard previously saved paren loc, if any.
+ SavedParenLoc = SourceLocation();
+ if (cast<FunctionProtoTypeLoc>(&Cur)->getTypePtr()->hasTrailingReturn())
+ return Cur.getLocalSourceRange().getBegin();
+ Cur = Cur.getNextTypeLoc();
+ assert(!Cur.isNull());
+ continue;
+ break;
+
default:
TypeLoc Next = Cur.getNextTypeLoc();
if (Next.isNull()) break;
@@ -114,7 +153,9 @@ SourceLocation TypeLoc::getBeginLoc() const {
}
break;
}
- return Cur.getLocalSourceRange().getBegin();
+ return SavedParenLoc.isValid()
+ ? SavedParenLoc
+ : Cur.getLocalSourceRange().getBegin();
}
SourceLocation TypeLoc::getEndLoc() const {
@@ -131,10 +172,15 @@ SourceLocation TypeLoc::getEndLoc() const {
case DependentSizedArray:
case IncompleteArray:
case VariableArray:
- case FunctionProto:
case FunctionNoProto:
Last = Cur;
break;
+ case FunctionProto:
+ if (cast<FunctionProtoTypeLoc>(&Cur)->getTypePtr()->hasTrailingReturn())
+ Last = TypeLoc();
+ else
+ Last = Cur;
+ break;
case Pointer:
case BlockPointer:
case MemberPointer: