[cfe-commits] r165974 - in /cfe/trunk/lib: AST/TypeLoc.cpp Parse/ParseDecl.cpp
Abramo Bagnara
abramo.bagnara at bugseng.com
Mon Oct 15 14:05:47 PDT 2012
Author: abramo
Date: Mon Oct 15 16:05:46 2012
New Revision: 165974
URL: http://llvm.org/viewvc/llvm-project?rev=165974&view=rev
Log:
Fixed FunctionTypeLoc range for trailing return type.
Modified:
cfe/trunk/lib/AST/TypeLoc.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
Modified: cfe/trunk/lib/AST/TypeLoc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypeLoc.cpp?rev=165974&r1=165973&r2=165974&view=diff
==============================================================================
--- cfe/trunk/lib/AST/TypeLoc.cpp (original)
+++ cfe/trunk/lib/AST/TypeLoc.cpp Mon Oct 15 16:05:46 2012
@@ -98,64 +98,27 @@
SourceLocation TypeLoc::getBeginLoc() const {
TypeLoc Cur = *this;
- SourceLocation SavedParenLoc;
while (true) {
switch (Cur.getTypeLocClass()) {
- // FIXME: Currently QualifiedTypeLoc does not have a source range
- // case Qualified:
- case Elaborated:
- 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;
+
+ // FIXME: Currently QualifiedTypeLoc does not have a source range
+ // case Qualified:
+ case Elaborated:
+ return Cur.getLocalSourceRange().getBegin();
default:
- TypeLoc Next = Cur.getNextTypeLoc();
- if (Next.isNull()) break;
- Cur = Next;
+ if (Cur.getNextTypeLoc().isNull())
+ return Cur.getLocalSourceRange().getBegin();
+ Cur = Cur.getNextTypeLoc();
continue;
- }
- break;
- }
- return SavedParenLoc.isValid()
- ? SavedParenLoc
- : Cur.getLocalSourceRange().getBegin();
+ } // switch
+ } // while
}
SourceLocation TypeLoc::getEndLoc() const {
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=165974&r1=165973&r2=165974&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Mon Oct 15 16:05:46 2012
@@ -4582,7 +4582,10 @@
Actions.ActOnStartFunctionDeclarator();
- SourceLocation StartLoc, EndLoc;
+ /* LocalEndLoc is the end location for the local FunctionTypeLoc.
+ EndLoc is the end location for the function declarator.
+ They differ for trailing return types. */
+ SourceLocation StartLoc, LocalEndLoc, EndLoc;
SourceLocation LParenLoc, RParenLoc;
LParenLoc = Tracker.getOpenLocation();
StartLoc = LParenLoc;
@@ -4595,6 +4598,7 @@
Tracker.consumeClose();
RParenLoc = Tracker.getCloseLocation();
+ LocalEndLoc = RParenLoc;
EndLoc = RParenLoc;
} else {
if (Tok.isNot(tok::r_paren))
@@ -4607,6 +4611,7 @@
// If we have the closing ')', eat it.
Tracker.consumeClose();
RParenLoc = Tracker.getCloseLocation();
+ LocalEndLoc = RParenLoc;
EndLoc = RParenLoc;
if (getLangOpts().CPlusPlus) {
@@ -4663,13 +4668,15 @@
MaybeParseCXX0XAttributes(FnAttrs);
// Parse trailing-return-type[opt].
+ LocalEndLoc = EndLoc;
if (getLangOpts().CPlusPlus0x && Tok.is(tok::arrow)) {
Diag(Tok, diag::warn_cxx98_compat_trailing_return_type);
if (D.getDeclSpec().getTypeSpecType() == TST_auto)
StartLoc = D.getDeclSpec().getTypeSpecTypeLoc();
- EndLoc = Tok.getLocation();
+ LocalEndLoc = Tok.getLocation();
SourceRange Range;
TrailingReturnType = ParseTrailingReturnType(Range);
+ EndLoc = Range.getEnd();
}
}
}
@@ -4691,7 +4698,7 @@
DynamicExceptions.size(),
NoexceptExpr.isUsable() ?
NoexceptExpr.get() : 0,
- StartLoc, EndLoc, D,
+ StartLoc, LocalEndLoc, D,
TrailingReturnType),
FnAttrs, EndLoc);
More information about the cfe-commits
mailing list