From: Abramo Bagnara Date: Thu, 3 Mar 2011 14:52:38 +0000 (+0000) Subject: Fixed end source location for LinkageSpecDecl. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5f6bcbebedb85ee745cbd9a3ca51ca8c766a6117;p=clang Fixed end source location for LinkageSpecDecl. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126943 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclCXX.h b/include/clang/AST/DeclCXX.h index 869ab3b153..499f3c822c 100644 --- a/include/clang/AST/DeclCXX.h +++ b/include/clang/AST/DeclCXX.h @@ -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; } diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index 1b849a58ad..8bd0ae7611 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -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, diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index f760f3f871..82cf031c69 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -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(LinkageSpec); + LSDecl->setRBraceLoc(RBraceLoc); + } PopDeclContext(); + } return LinkageSpec; } diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 590f36bc46..8f1d9a5395 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -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); diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp index 8fef6fb77f..bfd343a7d4 100644 --- a/lib/Serialization/ASTWriterDecl.cpp +++ b/lib/Serialization/ASTWriterDecl.cpp @@ -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; } diff --git a/test/Index/recursive-cxx-member-calls.cpp b/test/Index/recursive-cxx-member-calls.cpp index c5d7bab4cc..d47ea97bfd 100644 --- a/test/Index/recursive-cxx-member-calls.cpp +++ b/test/Index/recursive-cxx-member-calls.cpp @@ -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]