From 478851c3ed6bd784e7377dffd8e57b200c1b9ba9 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Wed, 4 Jul 2012 17:04:04 +0000 Subject: [PATCH] Drop the ASTContext.h include from Stmt.h and fix up transitive users. This required moving the ctors for IntegerLiteral and FloatingLiteral out of line which shouldn't change anything as they are usually called through Create methods that are already out of line. ASTContext::Deallocate has been a nop for a long time, drop it from ASTVector and make it independent from ASTContext.h Pass the StorageAllocator directly to AccessedEntity so it doesn't need to have a definition of ASTContext around. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159718 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/ASTVector.h | 4 +-- include/clang/AST/DeclCXX.h | 1 + include/clang/AST/DeclFriend.h | 1 + include/clang/AST/DeclTemplate.h | 1 + include/clang/AST/Expr.h | 29 ++++--------------- include/clang/AST/ExprCXX.h | 1 + include/clang/AST/RecordLayout.h | 4 +-- include/clang/AST/Stmt.h | 3 +- include/clang/Frontend/ASTUnit.h | 1 + include/clang/Sema/DelayedDiagnostic.h | 8 ++--- include/clang/Sema/Sema.h | 3 +- .../Core/PathSensitive/MemRegion.h | 1 + .../Core/PathSensitive/SValBuilder.h | 1 + lib/ARCMigrate/TransformActions.cpp | 1 + lib/AST/Expr.cpp | 28 ++++++++++++++++++ lib/AST/LambdaMangleContext.cpp | 2 ++ lib/AST/StmtDumper.cpp | 1 + lib/AST/TypeLoc.cpp | 1 + lib/Analysis/CFG.cpp | 1 + lib/Analysis/PseudoConstantAnalysis.cpp | 1 + lib/CodeGen/CGDebugInfo.h | 1 + lib/Edit/RewriteObjCFoundationAPI.cpp | 1 + lib/Parse/ParseAST.cpp | 1 + lib/Sema/AttributeList.cpp | 1 + lib/Sema/SemaAccess.cpp | 6 ++-- lib/Sema/SemaFixItUtils.cpp | 1 + lib/StaticAnalyzer/Core/BasicValueFactory.cpp | 1 + 27 files changed, 69 insertions(+), 36 deletions(-) diff --git a/include/clang/AST/ASTVector.h b/include/clang/AST/ASTVector.h index 217dfade52..4ff5ea37b8 100644 --- a/include/clang/AST/ASTVector.h +++ b/include/clang/AST/ASTVector.h @@ -374,7 +374,7 @@ void ASTVector::grow(ASTContext &C, size_t MinSize) { NewCapacity = MinSize; // Allocate the memory from the ASTContext. - T *NewElts = new (C) T[NewCapacity]; + T *NewElts = new (C, llvm::alignOf()) T[NewCapacity]; // Copy the elements over. if (llvm::is_class::value) { @@ -387,7 +387,7 @@ void ASTVector::grow(ASTContext &C, size_t MinSize) { memcpy(NewElts, Begin, CurSize * sizeof(T)); } - C.Deallocate(Begin); + // ASTContext never frees any memory. Begin = NewElts; End = NewElts+CurSize; Capacity = Begin+NewCapacity; diff --git a/include/clang/AST/DeclCXX.h b/include/clang/AST/DeclCXX.h index b7854feae1..9130e28a47 100644 --- a/include/clang/AST/DeclCXX.h +++ b/include/clang/AST/DeclCXX.h @@ -41,6 +41,7 @@ class CXXFinalOverriderMap; class CXXIndirectPrimaryBaseSet; class FriendDecl; class LambdaExpr; +class UsingDecl; /// \brief Represents any kind of function declaration, whether it is a /// concrete function or a function template. diff --git a/include/clang/AST/DeclFriend.h b/include/clang/AST/DeclFriend.h index ba1eb8d729..57a54e6507 100644 --- a/include/clang/AST/DeclFriend.h +++ b/include/clang/AST/DeclFriend.h @@ -15,6 +15,7 @@ #ifndef LLVM_CLANG_AST_DECLFRIEND_H #define LLVM_CLANG_AST_DECLFRIEND_H +#include "clang/AST/ASTContext.h" #include "clang/AST/DeclCXX.h" #include "llvm/Support/Compiler.h" diff --git a/include/clang/AST/DeclTemplate.h b/include/clang/AST/DeclTemplate.h index 7affc7e15f..2727312d74 100644 --- a/include/clang/AST/DeclTemplate.h +++ b/include/clang/AST/DeclTemplate.h @@ -15,6 +15,7 @@ #ifndef LLVM_CLANG_AST_DECLTEMPLATE_H #define LLVM_CLANG_AST_DECLTEMPLATE_H +#include "clang/AST/ASTContext.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/Redeclarable.h" #include "clang/AST/TemplateBase.h" diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index aedbefc5e1..d9cf0ad162 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -15,6 +15,7 @@ #define LLVM_CLANG_AST_EXPR_H #include "clang/AST/APValue.h" +#include "clang/AST/Decl.h" #include "clang/AST/Stmt.h" #include "clang/AST/Type.h" #include "clang/AST/DeclAccessPair.h" @@ -1163,16 +1164,8 @@ class IntegerLiteral : public Expr, public APIntStorage { public: // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, // or UnsignedLongLongTy - IntegerLiteral(ASTContext &C, const llvm::APInt &V, - QualType type, SourceLocation l) - : Expr(IntegerLiteralClass, type, VK_RValue, OK_Ordinary, false, false, - false, false), - Loc(l) { - assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); - assert(V.getBitWidth() == C.getIntWidth(type) && - "Integer type is not the correct size for constant."); - setValue(C, V); - } + IntegerLiteral(ASTContext &C, const llvm::APInt &V, QualType type, + SourceLocation l); /// \brief Returns a new integer literal with value 'V' and type 'type'. /// \param type - either IntTy, LongTy, LongLongTy, UnsignedIntTy, @@ -1250,22 +1243,10 @@ class FloatingLiteral : public Expr, private APFloatStorage { SourceLocation Loc; FloatingLiteral(ASTContext &C, const llvm::APFloat &V, bool isexact, - QualType Type, SourceLocation L) - : Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary, false, false, - false, false), Loc(L) { - FloatingLiteralBits.IsIEEE = - &C.getTargetInfo().getLongDoubleFormat() == &llvm::APFloat::IEEEquad; - FloatingLiteralBits.IsExact = isexact; - setValue(C, V); - } + QualType Type, SourceLocation L); /// \brief Construct an empty floating-point literal. - explicit FloatingLiteral(ASTContext &C, EmptyShell Empty) - : Expr(FloatingLiteralClass, Empty) { - FloatingLiteralBits.IsIEEE = - &C.getTargetInfo().getLongDoubleFormat() == &llvm::APFloat::IEEEquad; - FloatingLiteralBits.IsExact = false; - } + explicit FloatingLiteral(ASTContext &C, EmptyShell Empty); public: static FloatingLiteral *Create(ASTContext &C, const llvm::APFloat &V, diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index d77722888e..5710cba6ea 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -14,6 +14,7 @@ #ifndef LLVM_CLANG_AST_EXPRCXX_H #define LLVM_CLANG_AST_EXPRCXX_H +#include "clang/AST/Decl.h" #include "clang/AST/Expr.h" #include "clang/AST/UnresolvedSet.h" #include "clang/AST/TemplateBase.h" diff --git a/include/clang/AST/RecordLayout.h b/include/clang/AST/RecordLayout.h index 6f5c032a78..ba093636ba 100644 --- a/include/clang/AST/RecordLayout.h +++ b/include/clang/AST/RecordLayout.h @@ -14,10 +14,10 @@ #ifndef LLVM_CLANG_AST_LAYOUTINFO_H #define LLVM_CLANG_AST_LAYOUTINFO_H -#include "llvm/Support/DataTypes.h" -#include "llvm/ADT/DenseMap.h" +#include "clang/AST/ASTContext.h" #include "clang/AST/CharUnits.h" #include "clang/AST/DeclCXX.h" +#include "llvm/ADT/DenseMap.h" namespace clang { class ASTContext; diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index 3539c71634..1662ba87b4 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -19,7 +19,6 @@ #include "clang/AST/PrettyPrinter.h" #include "clang/AST/StmtIterator.h" #include "clang/AST/DeclGroup.h" -#include "clang/AST/ASTContext.h" #include "clang/AST/Attr.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/Compiler.h" @@ -37,9 +36,11 @@ namespace clang { class ParmVarDecl; class QualType; class IdentifierInfo; + class LabelDecl; class SourceManager; class StringLiteral; class SwitchStmt; + class VarDecl; //===--------------------------------------------------------------------===// // ExprIterator - Iterators for iterating over Stmt* arrays that contain diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h index cc503bc4eb..afaf60e89a 100644 --- a/include/clang/Frontend/ASTUnit.h +++ b/include/clang/Frontend/ASTUnit.h @@ -19,6 +19,7 @@ #include "clang/Sema/CodeCompleteConsumer.h" #include "clang/Lex/ModuleLoader.h" #include "clang/Lex/PreprocessingRecord.h" +#include "clang/AST/ASTContext.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/FileManager.h" diff --git a/include/clang/Sema/DelayedDiagnostic.h b/include/clang/Sema/DelayedDiagnostic.h index 4f5bc20d4d..c241266c9b 100644 --- a/include/clang/Sema/DelayedDiagnostic.h +++ b/include/clang/Sema/DelayedDiagnostic.h @@ -40,17 +40,17 @@ public: bool isMemberAccess() const { return IsMember; } - AccessedEntity(ASTContext &Context, + AccessedEntity(PartialDiagnostic::StorageAllocator &Allocator, MemberNonce _, CXXRecordDecl *NamingClass, DeclAccessPair FoundDecl, QualType BaseObjectType) : Access(FoundDecl.getAccess()), IsMember(true), Target(FoundDecl.getDecl()), NamingClass(NamingClass), - BaseObjectType(BaseObjectType), Diag(0, Context.getDiagAllocator()) { + BaseObjectType(BaseObjectType), Diag(0, Allocator) { } - AccessedEntity(ASTContext &Context, + AccessedEntity(PartialDiagnostic::StorageAllocator &Allocator, BaseNonce _, CXXRecordDecl *BaseClass, CXXRecordDecl *DerivedClass, @@ -58,7 +58,7 @@ public: : Access(Access), IsMember(false), Target(BaseClass), NamingClass(DerivedClass), - Diag(0, Context.getDiagAllocator()) { + Diag(0, Allocator) { } bool isQuiet() const { return Diag.getDiagID() == 0; } diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index d186c6f1dc..5379821782 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -28,6 +28,7 @@ #include "clang/AST/ExprObjC.h" #include "clang/AST/DeclarationName.h" #include "clang/AST/ExternalASTSource.h" +#include "clang/AST/LambdaMangleContext.h" #include "clang/AST/TypeLoc.h" #include "clang/AST/NSAPI.h" #include "clang/Lex/ModuleLoader.h" @@ -3302,7 +3303,7 @@ public: public: explicit ImplicitExceptionSpecification(Sema &Self) : Self(&Self), ComputedEST(EST_BasicNoexcept) { - if (!Self.Context.getLangOpts().CPlusPlus0x) + if (!Self.getLangOpts().CPlusPlus0x) ComputedEST = EST_DynamicNone; } diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h b/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h index e76c20e60e..2e922c0cc3 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h @@ -16,6 +16,7 @@ #ifndef LLVM_CLANG_GR_MEMREGION_H #define LLVM_CLANG_GR_MEMREGION_H +#include "clang/AST/ASTContext.h" #include "clang/AST/CharUnits.h" #include "clang/AST/Decl.h" #include "clang/AST/ExprObjC.h" diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h b/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h index c0fc380eec..83c3a56345 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h @@ -15,6 +15,7 @@ #ifndef LLVM_CLANG_GR_SVALBUILDER #define LLVM_CLANG_GR_SVALBUILDER +#include "clang/AST/ASTContext.h" #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" #include "clang/AST/ExprObjC.h" diff --git a/lib/ARCMigrate/TransformActions.cpp b/lib/ARCMigrate/TransformActions.cpp index 0ecfeb54f8..783db1c8f3 100644 --- a/lib/ARCMigrate/TransformActions.cpp +++ b/lib/ARCMigrate/TransformActions.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "Internals.h" +#include "clang/AST/ASTContext.h" #include "clang/AST/Expr.h" #include "clang/Lex/Preprocessor.h" #include "clang/Basic/SourceManager.h" diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index b68f864711..f2f77367d8 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -555,6 +555,17 @@ void APNumericStorage::setIntValue(ASTContext &C, const llvm::APInt &Val) { VAL = 0; } +IntegerLiteral::IntegerLiteral(ASTContext &C, const llvm::APInt &V, + QualType type, SourceLocation l) + : Expr(IntegerLiteralClass, type, VK_RValue, OK_Ordinary, false, false, + false, false), + Loc(l) { + assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); + assert(V.getBitWidth() == C.getIntWidth(type) && + "Integer type is not the correct size for constant."); + setValue(C, V); +} + IntegerLiteral * IntegerLiteral::Create(ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l) { @@ -566,6 +577,23 @@ IntegerLiteral::Create(ASTContext &C, EmptyShell Empty) { return new (C) IntegerLiteral(Empty); } +FloatingLiteral::FloatingLiteral(ASTContext &C, const llvm::APFloat &V, + bool isexact, QualType Type, SourceLocation L) + : Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary, false, false, + false, false), Loc(L) { + FloatingLiteralBits.IsIEEE = + &C.getTargetInfo().getLongDoubleFormat() == &llvm::APFloat::IEEEquad; + FloatingLiteralBits.IsExact = isexact; + setValue(C, V); +} + +FloatingLiteral::FloatingLiteral(ASTContext &C, EmptyShell Empty) + : Expr(FloatingLiteralClass, Empty) { + FloatingLiteralBits.IsIEEE = + &C.getTargetInfo().getLongDoubleFormat() == &llvm::APFloat::IEEEquad; + FloatingLiteralBits.IsExact = false; +} + FloatingLiteral * FloatingLiteral::Create(ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L) { diff --git a/lib/AST/LambdaMangleContext.cpp b/lib/AST/LambdaMangleContext.cpp index f5272a7fdb..6f4fe2d4b4 100644 --- a/lib/AST/LambdaMangleContext.cpp +++ b/lib/AST/LambdaMangleContext.cpp @@ -11,7 +11,9 @@ // the Itanium C++ ABI mangling numbers for lambda expressions. // //===----------------------------------------------------------------------===// + #include "clang/AST/LambdaMangleContext.h" +#include "clang/AST/ASTContext.h" #include "clang/AST/DeclCXX.h" using namespace clang; diff --git a/lib/AST/StmtDumper.cpp b/lib/AST/StmtDumper.cpp index d5e12c873d..962e35269c 100644 --- a/lib/AST/StmtDumper.cpp +++ b/lib/AST/StmtDumper.cpp @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// #include "clang/AST/StmtVisitor.h" +#include "clang/AST/ASTContext.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/PrettyPrinter.h" diff --git a/lib/AST/TypeLoc.cpp b/lib/AST/TypeLoc.cpp index caa19b19df..c7bb7da4d1 100644 --- a/lib/AST/TypeLoc.cpp +++ b/lib/AST/TypeLoc.cpp @@ -13,6 +13,7 @@ #include "llvm/Support/raw_ostream.h" #include "clang/AST/TypeLocVisitor.h" +#include "clang/AST/ASTContext.h" #include "clang/AST/Expr.h" #include "llvm/Support/ErrorHandling.h" using namespace clang; diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp index 9ac92dce37..b69fbd6afb 100644 --- a/lib/Analysis/CFG.cpp +++ b/lib/Analysis/CFG.cpp @@ -14,6 +14,7 @@ #include "llvm/Support/SaveAndRestore.h" #include "clang/Analysis/CFG.h" +#include "clang/AST/ASTContext.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/StmtVisitor.h" #include "clang/AST/PrettyPrinter.h" diff --git a/lib/Analysis/PseudoConstantAnalysis.cpp b/lib/Analysis/PseudoConstantAnalysis.cpp index c8b491a216..5d659ce585 100644 --- a/lib/Analysis/PseudoConstantAnalysis.cpp +++ b/lib/Analysis/PseudoConstantAnalysis.cpp @@ -17,6 +17,7 @@ #include "clang/AST/Decl.h" #include "clang/AST/Expr.h" #include "clang/AST/Stmt.h" +#include "llvm/ADT/SmallPtrSet.h" #include using namespace clang; diff --git a/lib/CodeGen/CGDebugInfo.h b/lib/CodeGen/CGDebugInfo.h index 616b703822..44cc49ade1 100644 --- a/lib/CodeGen/CGDebugInfo.h +++ b/lib/CodeGen/CGDebugInfo.h @@ -30,6 +30,7 @@ namespace llvm { } namespace clang { + class CXXMethodDecl; class VarDecl; class ObjCInterfaceDecl; class ClassTemplateSpecializationDecl; diff --git a/lib/Edit/RewriteObjCFoundationAPI.cpp b/lib/Edit/RewriteObjCFoundationAPI.cpp index 6ef2e642fb..0e7b877994 100644 --- a/lib/Edit/RewriteObjCFoundationAPI.cpp +++ b/lib/Edit/RewriteObjCFoundationAPI.cpp @@ -14,6 +14,7 @@ #include "clang/Edit/Rewriters.h" #include "clang/Edit/Commit.h" #include "clang/Lex/Lexer.h" +#include "clang/AST/ASTContext.h" #include "clang/AST/ExprObjC.h" #include "clang/AST/ExprCXX.h" #include "clang/AST/NSAPI.h" diff --git a/lib/Parse/ParseAST.cpp b/lib/Parse/ParseAST.cpp index c50c1c980e..bd4f859521 100644 --- a/lib/Parse/ParseAST.cpp +++ b/lib/Parse/ParseAST.cpp @@ -18,6 +18,7 @@ #include "clang/Sema/SemaConsumer.h" #include "clang/Sema/ExternalSemaSource.h" #include "clang/AST/ASTConsumer.h" +#include "clang/AST/ASTContext.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/ExternalASTSource.h" #include "clang/AST/Stmt.h" diff --git a/lib/Sema/AttributeList.cpp b/lib/Sema/AttributeList.cpp index 93f8c5d359..0f209fd7d6 100644 --- a/lib/Sema/AttributeList.cpp +++ b/lib/Sema/AttributeList.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "clang/Sema/AttributeList.h" +#include "clang/AST/ASTContext.h" #include "clang/AST/Expr.h" #include "clang/Basic/IdentifierTable.h" #include "llvm/ADT/StringSwitch.h" diff --git a/lib/Sema/SemaAccess.cpp b/lib/Sema/SemaAccess.cpp index 7a7185f33d..f71a38816f 100644 --- a/lib/Sema/SemaAccess.cpp +++ b/lib/Sema/SemaAccess.cpp @@ -152,7 +152,8 @@ struct AccessTarget : public AccessedEntity { CXXRecordDecl *NamingClass, DeclAccessPair FoundDecl, QualType BaseObjectType) - : AccessedEntity(Context, Member, NamingClass, FoundDecl, BaseObjectType) { + : AccessedEntity(Context.getDiagAllocator(), Member, NamingClass, + FoundDecl, BaseObjectType) { initialize(); } @@ -161,7 +162,8 @@ struct AccessTarget : public AccessedEntity { CXXRecordDecl *BaseClass, CXXRecordDecl *DerivedClass, AccessSpecifier Access) - : AccessedEntity(Context, Base, BaseClass, DerivedClass, Access) { + : AccessedEntity(Context.getDiagAllocator(), Base, BaseClass, DerivedClass, + Access) { initialize(); } diff --git a/lib/Sema/SemaFixItUtils.cpp b/lib/Sema/SemaFixItUtils.cpp index fa99ef160a..b61b9307dd 100644 --- a/lib/Sema/SemaFixItUtils.cpp +++ b/lib/Sema/SemaFixItUtils.cpp @@ -11,6 +11,7 @@ // //===----------------------------------------------------------------------===// +#include "clang/AST/ASTContext.h" #include "clang/AST/ExprCXX.h" #include "clang/AST/ExprObjC.h" #include "clang/Lex/Preprocessor.h" diff --git a/lib/StaticAnalyzer/Core/BasicValueFactory.cpp b/lib/StaticAnalyzer/Core/BasicValueFactory.cpp index fe96700772..20c73612c4 100644 --- a/lib/StaticAnalyzer/Core/BasicValueFactory.cpp +++ b/lib/StaticAnalyzer/Core/BasicValueFactory.cpp @@ -13,6 +13,7 @@ // //===----------------------------------------------------------------------===// +#include "clang/AST/ASTContext.h" #include "clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h" #include "clang/StaticAnalyzer/Core/PathSensitive/Store.h" -- 2.50.1