Fixed FunctionTypeLoc range for trailing return type.
authorAbramo Bagnara <abramo.bagnara@bugseng.com>
Mon, 15 Oct 2012 21:05:46 +0000 (21:05 +0000)
committerAbramo Bagnara <abramo.bagnara@bugseng.com>
Mon, 15 Oct 2012 21:05:46 +0000 (21:05 +0000)
llvm-svn: 165974

clang/lib/AST/TypeLoc.cpp
clang/lib/Parse/ParseDecl.cpp

index de9d22a..c9c084a 100644 (file)
@@ -98,64 +98,27 @@ 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
-    // 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 {
index 3ef4f38..3e4d92a 100644 (file)
@@ -4582,7 +4582,10 @@ void Parser::ParseFunctionDeclarator(Declarator &D,
 
   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 @@ void Parser::ParseFunctionDeclarator(Declarator &D,
 
     Tracker.consumeClose();
     RParenLoc = Tracker.getCloseLocation();
+    LocalEndLoc = RParenLoc;
     EndLoc = RParenLoc;
   } else {
     if (Tok.isNot(tok::r_paren))
@@ -4607,6 +4611,7 @@ void Parser::ParseFunctionDeclarator(Declarator &D,
     // If we have the closing ')', eat it.
     Tracker.consumeClose();
     RParenLoc = Tracker.getCloseLocation();
+    LocalEndLoc = RParenLoc;
     EndLoc = RParenLoc;
 
     if (getLangOpts().CPlusPlus) {
@@ -4663,13 +4668,15 @@ void Parser::ParseFunctionDeclarator(Declarator &D,
       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 @@ void Parser::ParseFunctionDeclarator(Declarator &D,
                                              DynamicExceptions.size(),
                                              NoexceptExpr.isUsable() ?
                                                NoexceptExpr.get() : 0,
-                                             StartLoc, EndLoc, D,
+                                             StartLoc, LocalEndLoc, D,
                                              TrailingReturnType),
                 FnAttrs, EndLoc);