]> granicus.if.org Git - clang/commitdiff
Fixed end source location for LinkageSpecDecl.
authorAbramo Bagnara <abramo.bagnara@gmail.com>
Thu, 3 Mar 2011 14:52:38 +0000 (14:52 +0000)
committerAbramo Bagnara <abramo.bagnara@gmail.com>
Thu, 3 Mar 2011 14:52:38 +0000 (14:52 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126943 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclCXX.h
lib/AST/DeclCXX.cpp
lib/Sema/SemaDeclCXX.cpp
lib/Serialization/ASTReaderDecl.cpp
lib/Serialization/ASTWriterDecl.cpp
test/Index/recursive-cxx-member-calls.cpp

index 869ab3b1538cfe4e4694705bed6cc883380b1f79..499f3c822ccd65b1c2f7006374ca39484648323b 100644 (file)
@@ -1711,18 +1711,21 @@ private:
   /// Language - The language for this linkage specification.
   LanguageIDs Language;
 
-  /// HadBraces - Whether this linkage specification had curly braces or not.
-  bool HadBraces : 1;
+  /// LBraceLoc - The source location for the left brace (if valid).
+  SourceLocation LBraceLoc;
+  /// RBraceLoc - The source location for the right brace (if valid).
+  SourceLocation RBraceLoc;
 
   LinkageSpecDecl(DeclContext *DC, SourceLocation L, LanguageIDs lang,
-                  bool Braces)
-    : Decl(LinkageSpec, DC, L),
-      DeclContext(LinkageSpec), Language(lang), HadBraces(Braces) { }
+                  SourceLocation LBLoc, SourceLocation RBLoc)
+    : Decl(LinkageSpec, DC, L), DeclContext(LinkageSpec),
+      Language(lang), LBraceLoc(LBLoc), RBraceLoc(RBLoc) { }
 
 public:
   static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
                                  SourceLocation L, LanguageIDs Lang,
-                                 bool Braces);
+                                 SourceLocation LBraceLoc,
+                                 SourceLocation RBraceLoc = SourceLocation());
 
   /// \brief Return the language specified by this linkage specification.
   LanguageIDs getLanguage() const { return Language; }
@@ -1732,11 +1735,23 @@ public:
 
   /// \brief Determines whether this linkage specification had braces in
   /// its syntactic form.
-  bool hasBraces() const { return HadBraces; }
+  bool hasBraces() const { return RBraceLoc.isValid(); }
+  SourceLocation getLBraceLoc() const { return LBraceLoc; }
+  SourceLocation getRBraceLoc() const { return RBraceLoc; }
+  void setLBraceLoc(SourceLocation L) { LBraceLoc = L; }
+  void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
 
-  /// \brief Set whether this linkage specification has braces in its
-  /// syntactic form.
-  void setHasBraces(bool B) { HadBraces = B; }
+  SourceLocation getLocEnd() const {
+    if (hasBraces())
+      return getRBraceLoc();
+    // No braces: get the end location of the (only) declaration in context
+    // (if present).
+    return decls_empty() ? getLocation() : decls_begin()->getLocEnd();
+  }
+
+  SourceRange getSourceRange() const {
+    return SourceRange(getLocation(), getLocEnd());
+  }
 
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const LinkageSpecDecl *D) { return true; }
index 1b849a58ad2908d15b2a076e32704cf5a0bb49b6..8bd0ae7611ded10b6f179db8ac85c77886600beb 100644 (file)
@@ -1270,8 +1270,10 @@ CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD,
 LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C,
                                          DeclContext *DC,
                                          SourceLocation L,
-                                         LanguageIDs Lang, bool Braces) {
-  return new (C) LinkageSpecDecl(DC, L, Lang, Braces);
+                                         LanguageIDs Lang,
+                                         SourceLocation LBraceLoc,
+                                         SourceLocation RBraceLoc) {
+  return new (C) LinkageSpecDecl(DC, L, Lang, LBraceLoc, RBraceLoc);
 }
 
 UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC,
index f760f3f8710847d79d3d0489765368f25446befa..82cf031c698b67d907ec0b0badbc6c4a2329d862 100644 (file)
@@ -6576,7 +6576,7 @@ Decl *Sema::ActOnStartLinkageSpecification(Scope *S, SourceLocation ExternLoc,
 
   LinkageSpecDecl *D = LinkageSpecDecl::Create(Context, CurContext,
                                                LangLoc, Language,
-                                               LBraceLoc.isValid());
+                                               LBraceLoc);
   CurContext->addDecl(D);
   PushDeclContext(S, D);
   return D;
@@ -6587,10 +6587,15 @@ Decl *Sema::ActOnStartLinkageSpecification(Scope *S, SourceLocation ExternLoc,
 /// valid, it's the position of the closing '}' brace in a linkage
 /// specification that uses braces.
 Decl *Sema::ActOnFinishLinkageSpecification(Scope *S,
-                                                      Decl *LinkageSpec,
-                                                      SourceLocation RBraceLoc) {
-  if (LinkageSpec)
+                                            Decl *LinkageSpec,
+                                            SourceLocation RBraceLoc) {
+  if (LinkageSpec) {
+    if (RBraceLoc.isValid()) {
+      LinkageSpecDecl* LSDecl = cast<LinkageSpecDecl>(LinkageSpec);
+      LSDecl->setRBraceLoc(RBraceLoc);
+    }
     PopDeclContext();
+  }
   return LinkageSpec;
 }
 
index 590f36bc4681ab1e2422f58360189ef522d76ec8..8f1d9a53956a687c900e0c1fa0087b8e16027ebe 100644 (file)
@@ -721,7 +721,8 @@ void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
 void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
   VisitDecl(D);
   D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
-  D->setHasBraces(Record[Idx++]);
+  D->setLBraceLoc(ReadSourceLocation(Record, Idx));
+  D->setRBraceLoc(ReadSourceLocation(Record, Idx));
 }
 
 void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
@@ -1418,7 +1419,7 @@ Decl *ASTReader::ReadDeclRecord(unsigned Index, DeclID ID) {
   case DECL_LINKAGE_SPEC:
     D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
                                 (LinkageSpecDecl::LanguageIDs)0,
-                                false);
+                                SourceLocation(), SourceLocation());
     break;
   case DECL_LABEL:
     D = LabelDecl::Create(*Context, 0, SourceLocation(), 0);
index 8fef6fb77fa30563f8a638e95f4c178d9dc881a8..bfd343a7d490e01939231394bd32f06d09ed32a7 100644 (file)
@@ -646,10 +646,9 @@ void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) {
 
 void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
   VisitDecl(D);
-  // FIXME: It might be nice to serialize the brace locations for this
-  // declaration, which don't seem to be readily available in the AST.
   Record.push_back(D->getLanguage());
-  Record.push_back(D->hasBraces());
+  Writer.AddSourceLocation(D->getLBraceLoc(), Record);
+  Writer.AddSourceLocation(D->getRBraceLoc(), Record);
   Code = serialization::DECL_LINKAGE_SPEC;
 }
 
index c5d7bab4cc5ff254b0b43526acae5ae41922c5c2..d47ea97bfdb379c6e08af86b89ff6825d00e08c4 100644 (file)
@@ -1532,7 +1532,7 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo * Name) {
 // CHECK: 4:20: TemplateTypeParameter=_T1:4:20 (Definition) Extent=[4:20 - 4:23]
 // CHECK: 4:31: TemplateTypeParameter=_T2:4:31 (Definition) Extent=[4:31 - 4:34]
 // CHECK: 4:55: FieldDecl=second:4:55 (Definition) Extent=[4:55 - 4:61]
-// CHECK: 6:8: UnexposedDecl=:6:8 (Definition) Extent=[6:8 - 6:11]
+// CHECK: 6:8: UnexposedDecl=:6:8 (Definition) Extent=[6:8 - 9:2]
 // CHECK: 7:7: FunctionDecl=memcmp:7:7 Extent=[7:7 - 7:49]
 // CHECK: 7:26: ParmDecl=:7:26 (Definition) Extent=[7:20 - 7:27]
 // CHECK: 7:40: ParmDecl=:7:40 (Definition) Extent=[7:34 - 7:41]