Author: akirtzidis Date: Fri Jul 15 13:11:33 2016 New Revision: 275590 URL: http://llvm.org/viewvc/llvm-project?rev=275590&view=rev Log: [AST] Keep track of the left brace source location of a tag decl.
This is useful for source modification tools. There will be a follow-up commit using it. Modified: cfe/trunk/include/clang/AST/Decl.h cfe/trunk/include/clang/Sema/Sema.h cfe/trunk/lib/AST/Decl.cpp cfe/trunk/lib/AST/DeclTemplate.cpp cfe/trunk/lib/Parse/ParseDecl.cpp cfe/trunk/lib/Parse/ParseDeclCXX.cpp cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/lib/Sema/SemaTemplate.cpp cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp cfe/trunk/lib/Serialization/ASTReaderDecl.cpp cfe/trunk/lib/Serialization/ASTWriter.cpp cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Modified: cfe/trunk/include/clang/AST/Decl.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=275590&r1=275589&r2=275590&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/Decl.h (original) +++ cfe/trunk/include/clang/AST/Decl.h Fri Jul 15 13:11:33 2016 @@ -2781,7 +2781,7 @@ protected: /// the TU. unsigned IsCompleteDefinitionRequired : 1; private: - SourceLocation RBraceLoc; + SourceRange BraceRange; // A struct representing syntactic qualifier info, // to be used for the (uncommon) case of out-of-line declarations. @@ -2843,8 +2843,8 @@ public: using redeclarable_base::getMostRecentDecl; using redeclarable_base::isFirstDecl; - SourceLocation getRBraceLoc() const { return RBraceLoc; } - void setRBraceLoc(SourceLocation L) { RBraceLoc = L; } + SourceRange getBraceRange() const { return BraceRange; } + void setBraceRange(SourceRange R) { BraceRange = R; } /// getInnerLocStart - Return SourceLocation representing start of source /// range ignoring outer template declarations. Modified: cfe/trunk/include/clang/Sema/Sema.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=275590&r1=275589&r2=275590&view=diff ============================================================================== --- cfe/trunk/include/clang/Sema/Sema.h (original) +++ cfe/trunk/include/clang/Sema/Sema.h Fri Jul 15 13:11:33 2016 @@ -2039,7 +2039,7 @@ public: /// ActOnTagFinishDefinition - Invoked once we have finished parsing /// the definition of a tag (enumeration, class, struct, or union). void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl, - SourceLocation RBraceLoc); + SourceRange BraceRange); void ActOnTagFinishSkippedDefinition(SkippedDefinitionContext Context); @@ -2076,8 +2076,8 @@ public: SourceLocation IdLoc, IdentifierInfo *Id, AttributeList *Attrs, SourceLocation EqualLoc, Expr *Val); - void ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc, - SourceLocation RBraceLoc, Decl *EnumDecl, + void ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange, + Decl *EnumDecl, ArrayRef<Decl *> Elements, Scope *S, AttributeList *Attr); Modified: cfe/trunk/lib/AST/Decl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=275590&r1=275589&r2=275590&view=diff ============================================================================== --- cfe/trunk/lib/AST/Decl.cpp (original) +++ cfe/trunk/lib/AST/Decl.cpp Fri Jul 15 13:11:33 2016 @@ -3525,6 +3525,7 @@ SourceLocation TagDecl::getOuterLocStart } SourceRange TagDecl::getSourceRange() const { + SourceLocation RBraceLoc = BraceRange.getEnd(); SourceLocation E = RBraceLoc.isValid() ? RBraceLoc : getLocation(); return SourceRange(getOuterLocStart(), E); } Modified: cfe/trunk/lib/AST/DeclTemplate.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclTemplate.cpp?rev=275590&r1=275589&r2=275590&view=diff ============================================================================== --- cfe/trunk/lib/AST/DeclTemplate.cpp (original) +++ cfe/trunk/lib/AST/DeclTemplate.cpp Fri Jul 15 13:11:33 2016 @@ -778,7 +778,7 @@ ClassTemplateSpecializationDecl::getSour getSpecializationKind() == TSK_ExplicitInstantiationDefinition); if (getExternLoc().isValid()) Begin = getExternLoc(); - SourceLocation End = getRBraceLoc(); + SourceLocation End = getBraceRange().getEnd(); if (End.isInvalid()) End = getTypeAsWritten()->getTypeLoc().getEndLoc(); return SourceRange(Begin, End); Modified: cfe/trunk/lib/Parse/ParseDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=275590&r1=275589&r2=275590&view=diff ============================================================================== --- cfe/trunk/lib/Parse/ParseDecl.cpp (original) +++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Jul 15 13:11:33 2016 @@ -3773,8 +3773,7 @@ void Parser::ParseStructUnionBody(Source T.getOpenLocation(), T.getCloseLocation(), attrs.getList()); StructScope.Exit(); - Actions.ActOnTagFinishDefinition(getCurScope(), TagDecl, - T.getCloseLocation()); + Actions.ActOnTagFinishDefinition(getCurScope(), TagDecl, T.getRange()); } /// ParseEnumSpecifier @@ -4269,7 +4268,7 @@ void Parser::ParseEnumBody(SourceLocatio ParsedAttributes attrs(AttrFactory); MaybeParseGNUAttributes(attrs); - Actions.ActOnEnumBody(StartLoc, T.getOpenLocation(), T.getCloseLocation(), + Actions.ActOnEnumBody(StartLoc, T.getRange(), EnumDecl, EnumConstantDecls, getCurScope(), attrs.getList()); @@ -4283,8 +4282,7 @@ void Parser::ParseEnumBody(SourceLocatio } EnumScope.Exit(); - Actions.ActOnTagFinishDefinition(getCurScope(), EnumDecl, - T.getCloseLocation()); + Actions.ActOnTagFinishDefinition(getCurScope(), EnumDecl, T.getRange()); // The next token must be valid after an enum definition. If not, a ';' // was probably forgotten. Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=275590&r1=275589&r2=275590&view=diff ============================================================================== --- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original) +++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Fri Jul 15 13:11:33 2016 @@ -3143,8 +3143,7 @@ void Parser::ParseCXXMemberSpecification } if (TagDecl) - Actions.ActOnTagFinishDefinition(getCurScope(), TagDecl, - T.getCloseLocation()); + Actions.ActOnTagFinishDefinition(getCurScope(), TagDecl, T.getRange()); // Leave the class scope. ParsingDef.Pop(); Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=275590&r1=275589&r2=275590&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Jul 15 13:11:33 2016 @@ -13176,10 +13176,10 @@ void Sema::ActOnStartCXXMemberDeclaratio } void Sema::ActOnTagFinishDefinition(Scope *S, Decl *TagD, - SourceLocation RBraceLoc) { + SourceRange BraceRange) { AdjustDeclIfTemplate(TagD); TagDecl *Tag = cast<TagDecl>(TagD); - Tag->setRBraceLoc(RBraceLoc); + Tag->setBraceRange(BraceRange); // Make sure we "complete" the definition even it is invalid. if (Tag->isBeingDefined()) { @@ -14775,8 +14775,8 @@ bool Sema::IsValueInFlagEnum(const EnumD return !(FlagMask & Val) || (AllowMask && !(FlagMask & ~Val)); } -void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc, - SourceLocation RBraceLoc, Decl *EnumDeclX, +void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange, + Decl *EnumDeclX, ArrayRef<Decl *> Elements, Scope *S, AttributeList *Attr) { EnumDecl *Enum = cast<EnumDecl>(EnumDeclX); Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=275590&r1=275589&r2=275590&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaTemplate.cpp (original) +++ cfe/trunk/lib/Sema/SemaTemplate.cpp Fri Jul 15 13:11:33 2016 @@ -7509,7 +7509,7 @@ Sema::ActOnExplicitInstantiation(Scope * // Set source locations for keywords. Specialization->setExternLoc(ExternLoc); Specialization->setTemplateKeywordLoc(TemplateLoc); - Specialization->setRBraceLoc(SourceLocation()); + Specialization->setBraceRange(SourceRange()); if (Attr) ProcessDeclAttributeList(S, Specialization, Attr); Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=275590&r1=275589&r2=275590&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original) +++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Fri Jul 15 13:11:33 2016 @@ -2090,7 +2090,7 @@ Sema::InstantiateClass(SourceLocation Po if (TSK == TSK_ImplicitInstantiation) { Instantiation->setLocation(Pattern->getLocation()); Instantiation->setLocStart(Pattern->getInnerLocStart()); - Instantiation->setRBraceLoc(Pattern->getRBraceLoc()); + Instantiation->setBraceRange(Pattern->getBraceRange()); } if (!Instantiation->isInvalidDecl()) { Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=275590&r1=275589&r2=275590&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Fri Jul 15 13:11:33 2016 @@ -1018,9 +1018,7 @@ void TemplateDeclInstantiator::Instantia } } - // FIXME: Fixup LBraceLoc - SemaRef.ActOnEnumBody(Enum->getLocation(), SourceLocation(), - Enum->getRBraceLoc(), Enum, + SemaRef.ActOnEnumBody(Enum->getLocation(), Enum->getBraceRange(), Enum, Enumerators, nullptr, nullptr); } Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=275590&r1=275589&r2=275590&view=diff ============================================================================== --- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original) +++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Fri Jul 15 13:11:33 2016 @@ -647,7 +647,7 @@ ASTDeclReader::RedeclarableResult ASTDec TD->setEmbeddedInDeclarator(Record[Idx++]); TD->setFreeStanding(Record[Idx++]); TD->setCompleteDefinitionRequired(Record[Idx++]); - TD->setRBraceLoc(ReadSourceLocation(Record, Idx)); + TD->setBraceRange(ReadSourceRange(Record, Idx)); switch (Record[Idx++]) { case 0: @@ -3846,7 +3846,7 @@ void ASTDeclReader::UpdateDecl(Decl *D, RD->setTagKind((TagTypeKind)Record[Idx++]); RD->setLocation(Reader.ReadSourceLocation(ModuleFile, Record, Idx)); RD->setLocStart(Reader.ReadSourceLocation(ModuleFile, Record, Idx)); - RD->setRBraceLoc(Reader.ReadSourceLocation(ModuleFile, Record, Idx)); + RD->setBraceRange(Reader.ReadSourceRange(ModuleFile, Record, Idx)); if (Record[Idx++]) { AttrVec Attrs; Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=275590&r1=275589&r2=275590&view=diff ============================================================================== --- cfe/trunk/lib/Serialization/ASTWriter.cpp (original) +++ cfe/trunk/lib/Serialization/ASTWriter.cpp Fri Jul 15 13:11:33 2016 @@ -4716,7 +4716,7 @@ void ASTWriter::WriteDeclUpdatesBlocks(R Record.push_back(RD->getTagKind()); Record.AddSourceLocation(RD->getLocation()); Record.AddSourceLocation(RD->getLocStart()); - Record.AddSourceLocation(RD->getRBraceLoc()); + Record.AddSourceRange(RD->getBraceRange()); // Instantiation may change attributes; write them all out afresh. Record.push_back(D->hasAttrs()); Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=275590&r1=275589&r2=275590&view=diff ============================================================================== --- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original) +++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Fri Jul 15 13:11:33 2016 @@ -399,7 +399,7 @@ void ASTDeclWriter::VisitTagDecl(TagDecl Record.push_back(D->isEmbeddedInDeclarator()); Record.push_back(D->isFreeStanding()); Record.push_back(D->isCompleteDefinitionRequired()); - Record.AddSourceLocation(D->getRBraceLoc()); + Record.AddSourceRange(D->getBraceRange()); if (D->hasExtInfo()) { Record.push_back(1); @@ -1769,6 +1769,7 @@ void ASTWriter::WriteDeclAbbrevs() { Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind // EnumDecl Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // AddTypeRef @@ -1817,6 +1818,7 @@ void ASTWriter::WriteDeclAbbrevs() { Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind // RecordDecl Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // FlexibleArrayMember _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits