From: Craig Topper Date: Sun, 18 Aug 2013 10:09:15 +0000 (+0000) Subject: Make expression allocation methods use a 'const' reference to the ASTContext since... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=05ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1;p=clang Make expression allocation methods use a 'const' reference to the ASTContext since the underlying operator new only needs a const reference. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188636 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/ASTVector.h b/include/clang/AST/ASTVector.h index 0d4b3c4bb7..71a687869a 100644 --- a/include/clang/AST/ASTVector.h +++ b/include/clang/AST/ASTVector.h @@ -63,7 +63,7 @@ public: // Default ctor - Initialize to empty. ASTVector() : Begin(NULL), End(NULL), Capacity(NULL) { } - ASTVector(ASTContext &C, unsigned N) + ASTVector(const ASTContext &C, unsigned N) : Begin(NULL), End(NULL), Capacity(NULL) { reserve(C, N); } @@ -155,7 +155,7 @@ public: return const_pointer(Begin); } - void push_back(const_reference Elt, ASTContext &C) { + void push_back(const_reference Elt, const ASTContext &C) { if (End < Capacity) { Retry: new (End) T(Elt); @@ -166,7 +166,7 @@ public: goto Retry; } - void reserve(ASTContext &C, unsigned N) { + void reserve(const ASTContext &C, unsigned N) { if (unsigned(Capacity-Begin) < N) grow(C, N); } @@ -178,7 +178,7 @@ public: /// append - Add the specified range to the end of the SmallVector. /// template - void append(ASTContext &C, in_iter in_start, in_iter in_end) { + void append(const ASTContext &C, in_iter in_start, in_iter in_end) { size_type NumInputs = std::distance(in_start, in_end); if (NumInputs == 0) @@ -197,7 +197,7 @@ public: /// append - Add the specified range to the end of the SmallVector. /// - void append(ASTContext &C, size_type NumInputs, const T &Elt) { + void append(const ASTContext &C, size_type NumInputs, const T &Elt) { // Grow allocated space if needed. if (NumInputs > size_type(this->capacity_ptr()-this->end())) this->grow(C, this->size()+NumInputs); @@ -214,7 +214,7 @@ public: std::uninitialized_copy(I, E, Dest); } - iterator insert(ASTContext &C, iterator I, const T &Elt) { + iterator insert(const ASTContext &C, iterator I, const T &Elt) { if (I == this->end()) { // Important special case for empty vector. push_back(Elt, C); return this->end()-1; @@ -235,7 +235,7 @@ public: goto Retry; } - iterator insert(ASTContext &C, iterator I, size_type NumToInsert, + iterator insert(const ASTContext &C, iterator I, size_type NumToInsert, const T &Elt) { if (I == this->end()) { // Important special case for empty vector. append(C, NumToInsert, Elt); @@ -284,7 +284,7 @@ public: } template - iterator insert(ASTContext &C, iterator I, ItTy From, ItTy To) { + iterator insert(const ASTContext &C, iterator I, ItTy From, ItTy To) { if (I == this->end()) { // Important special case for empty vector. append(C, From, To); return this->end()-1; @@ -335,7 +335,7 @@ public: return I; } - void resize(ASTContext &C, unsigned N, const T &NV) { + void resize(const ASTContext &C, unsigned N, const T &NV) { if (N < this->size()) { this->destroy_range(this->begin()+N, this->end()); this->setEnd(this->begin()+N); @@ -350,7 +350,7 @@ public: private: /// grow - double the size of the allocated memory, guaranteeing space for at /// least one more element or MinSize if specified. - void grow(ASTContext &C, size_type MinSize = 1); + void grow(const ASTContext &C, size_type MinSize = 1); void construct_range(T *S, T *E, const T &Elt) { for (; S != E; ++S) @@ -370,7 +370,7 @@ protected: // Define this out-of-line to dissuade the C++ compiler from inlining it. template -void ASTVector::grow(ASTContext &C, size_t MinSize) { +void ASTVector::grow(const ASTContext &C, size_t MinSize) { size_t CurCapacity = Capacity-Begin; size_t CurSize = size(); size_t NewCapacity = 2*CurCapacity; diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index f641578bb3..1d957aa2be 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -1220,13 +1220,15 @@ protected: else return llvm::APInt(BitWidth, VAL); } - void setIntValue(ASTContext &C, const llvm::APInt &Val); + void setIntValue(const ASTContext &C, const llvm::APInt &Val); }; class APIntStorage : private APNumericStorage { public: llvm::APInt getValue() const { return getIntValue(); } - void setValue(ASTContext &C, const llvm::APInt &Val) { setIntValue(C, Val); } + void setValue(const ASTContext &C, const llvm::APInt &Val) { + setIntValue(C, Val); + } }; class APFloatStorage : private APNumericStorage { @@ -1234,7 +1236,7 @@ public: llvm::APFloat getValue(const llvm::fltSemantics &Semantics) const { return llvm::APFloat(Semantics, getIntValue()); } - void setValue(ASTContext &C, const llvm::APFloat &Val) { + void setValue(const ASTContext &C, const llvm::APFloat &Val) { setIntValue(C, Val.bitcastToAPInt()); } }; @@ -1249,17 +1251,17 @@ 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, + IntegerLiteral(const 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, /// UnsignedLongTy, or UnsignedLongLongTy which should match the size of V /// \param V - the value that the returned integer literal contains. - static IntegerLiteral *Create(ASTContext &C, const llvm::APInt &V, + static IntegerLiteral *Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l); /// \brief Returns a new empty integer literal. - static IntegerLiteral *Create(ASTContext &C, EmptyShell Empty); + static IntegerLiteral *Create(const ASTContext &C, EmptyShell Empty); SourceLocation getLocStart() const LLVM_READONLY { return Loc; } SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } @@ -1327,21 +1329,21 @@ public: class FloatingLiteral : public Expr, private APFloatStorage { SourceLocation Loc; - FloatingLiteral(ASTContext &C, const llvm::APFloat &V, bool isexact, + FloatingLiteral(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L); /// \brief Construct an empty floating-point literal. - explicit FloatingLiteral(ASTContext &C, EmptyShell Empty); + explicit FloatingLiteral(const ASTContext &C, EmptyShell Empty); public: - static FloatingLiteral *Create(ASTContext &C, const llvm::APFloat &V, + static FloatingLiteral *Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L); - static FloatingLiteral *Create(ASTContext &C, EmptyShell Empty); + static FloatingLiteral *Create(const ASTContext &C, EmptyShell Empty); llvm::APFloat getValue() const { return APFloatStorage::getValue(getSemantics()); } - void setValue(ASTContext &C, const llvm::APFloat &Val) { + void setValue(const ASTContext &C, const llvm::APFloat &Val) { assert(&getSemantics() == &Val.getSemantics() && "Inconsistent semantics"); APFloatStorage::setValue(C, Val); } @@ -1468,19 +1470,19 @@ private: public: /// This is the "fully general" constructor that allows representation of /// strings formed from multiple concatenated tokens. - static StringLiteral *Create(ASTContext &C, StringRef Str, StringKind Kind, - bool Pascal, QualType Ty, + static StringLiteral *Create(const ASTContext &C, StringRef Str, + StringKind Kind, bool Pascal, QualType Ty, const SourceLocation *Loc, unsigned NumStrs); /// Simple constructor for string literals made from one token. - static StringLiteral *Create(ASTContext &C, StringRef Str, StringKind Kind, - bool Pascal, QualType Ty, + static StringLiteral *Create(const ASTContext &C, StringRef Str, + StringKind Kind, bool Pascal, QualType Ty, SourceLocation Loc) { return Create(C, Str, Kind, Pascal, Ty, &Loc, 1); } /// \brief Construct an empty string literal. - static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs); + static StringLiteral *CreateEmpty(const ASTContext &C, unsigned NumStrs); StringRef getString() const { assert(CharByteWidth==1 @@ -1519,7 +1521,7 @@ public: unsigned getCharByteWidth() const { return CharByteWidth; } /// \brief Sets the string data to the given string data. - void setString(ASTContext &C, StringRef Str, + void setString(const ASTContext &C, StringRef Str, StringKind Kind, bool IsPascal); StringKind getKind() const { return static_cast(Kind); } @@ -1852,7 +1854,7 @@ private: // Number of sub-expressions (i.e. array subscript expressions). unsigned NumExprs; - OffsetOfExpr(ASTContext &C, QualType type, + OffsetOfExpr(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef comps, ArrayRef exprs, SourceLocation RParenLoc); @@ -1863,12 +1865,12 @@ private: public: - static OffsetOfExpr *Create(ASTContext &C, QualType type, + static OffsetOfExpr *Create(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef comps, ArrayRef exprs, SourceLocation RParenLoc); - static OffsetOfExpr *CreateEmpty(ASTContext &C, + static OffsetOfExpr *CreateEmpty(const ASTContext &C, unsigned NumComps, unsigned NumExprs); /// getOperatorLoc - Return the location of the operator. @@ -2132,10 +2134,11 @@ class CallExpr : public Expr { protected: // These versions of the constructor are for derived classes. - CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs, + CallExpr(const ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs, ArrayRef args, QualType t, ExprValueKind VK, SourceLocation rparenloc); - CallExpr(ASTContext &C, StmtClass SC, unsigned NumPreArgs, EmptyShell Empty); + CallExpr(const ASTContext &C, StmtClass SC, unsigned NumPreArgs, + EmptyShell Empty); Stmt *getPreArg(unsigned i) { assert(i < getNumPreArgs() && "Prearg access out of range!"); @@ -2153,11 +2156,11 @@ protected: unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; } public: - CallExpr(ASTContext& C, Expr *fn, ArrayRef args, QualType t, + CallExpr(const ASTContext& C, Expr *fn, ArrayRef args, QualType t, ExprValueKind VK, SourceLocation rparenloc); /// \brief Build an empty call expression. - CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty); + CallExpr(const ASTContext &C, StmtClass SC, EmptyShell Empty); const Expr *getCallee() const { return cast(SubExprs[FN]); } Expr *getCallee() { return cast(SubExprs[FN]); } @@ -2205,7 +2208,7 @@ public: /// setNumArgs - This changes the number of arguments present in this call. /// Any orphaned expressions are deleted by this, and any new operands are set /// to null. - void setNumArgs(ASTContext& C, unsigned NumArgs); + void setNumArgs(const ASTContext& C, unsigned NumArgs); typedef ExprIterator arg_iterator; typedef ConstExprIterator const_arg_iterator; @@ -2359,7 +2362,7 @@ public: HasQualifierOrFoundDecl(false), HasTemplateKWAndArgsInfo(false), HadMultipleCandidates(false) {} - static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow, + static MemberExpr *Create(const ASTContext &C, Expr *base, bool isarrow, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *memberdecl, DeclAccessPair founddecl, @@ -2746,12 +2749,13 @@ public: : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) { } - static ImplicitCastExpr *Create(ASTContext &Context, QualType T, + static ImplicitCastExpr *Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat); - static ImplicitCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); + static ImplicitCastExpr *CreateEmpty(const ASTContext &Context, + unsigned PathSize); SourceLocation getLocStart() const LLVM_READONLY { return getSubExpr()->getLocStart(); @@ -2837,13 +2841,14 @@ class CStyleCastExpr : public ExplicitCastExpr { : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { } public: - static CStyleCastExpr *Create(ASTContext &Context, QualType T, + static CStyleCastExpr *Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *BasePath, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation R); - static CStyleCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); + static CStyleCastExpr *CreateEmpty(const ASTContext &Context, + unsigned PathSize); SourceLocation getLParenLoc() const { return LPLoc; } void setLParenLoc(SourceLocation L) { LPLoc = L; } @@ -3411,7 +3416,7 @@ class ShuffleVectorExpr : public Expr { unsigned NumExprs; public: - ShuffleVectorExpr(ASTContext &C, ArrayRef args, QualType Type, + ShuffleVectorExpr(const ASTContext &C, ArrayRef args, QualType Type, SourceLocation BLoc, SourceLocation RP); /// \brief Build an empty vector-shuffle expression. @@ -3449,9 +3454,9 @@ public: return cast(SubExprs[Index]); } - void setExprs(ASTContext &C, ArrayRef Exprs); + void setExprs(const ASTContext &C, ArrayRef Exprs); - llvm::APSInt getShuffleMaskIdx(ASTContext &Ctx, unsigned N) const { + llvm::APSInt getShuffleMaskIdx(const ASTContext &Ctx, unsigned N) const { assert((N < NumExprs - 2) && "Shuffle idx out of range!"); return getExpr(N+2)->EvaluateKnownConstInt(Ctx); } @@ -3689,7 +3694,7 @@ class InitListExpr : public Expr { llvm::PointerUnion ArrayFillerOrUnionFieldInit; public: - InitListExpr(ASTContext &C, SourceLocation lbraceloc, + InitListExpr(const ASTContext &C, SourceLocation lbraceloc, ArrayRef initExprs, SourceLocation rbraceloc); /// \brief Build an empty initializer list. @@ -3717,7 +3722,7 @@ public: } /// \brief Reserve space for some number of initializers. - void reserveInits(ASTContext &C, unsigned NumInits); + void reserveInits(const ASTContext &C, unsigned NumInits); /// @brief Specify the number of initializers /// @@ -3725,7 +3730,7 @@ public: /// initializers will be destroyed. If there are fewer than @p /// NumInits initializers, NULL expressions will be added for the /// unknown initializers. - void resizeInits(ASTContext &Context, unsigned NumInits); + void resizeInits(const ASTContext &Context, unsigned NumInits); /// @brief Updates the initializer at index @p Init with the new /// expression @p expr, and returns the old expression at that @@ -3734,7 +3739,7 @@ public: /// When @p Init is out of range for this initializer list, the /// initializer list will be extended with NULL expressions to /// accommodate the new entry. - Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr); + Expr *updateInit(const ASTContext &C, unsigned Init, Expr *expr); /// \brief If this initializer list initializes an array with more elements /// than there are initializers in the list, specifies an expression to be @@ -3882,7 +3887,7 @@ private: Designator *Designators; - DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators, + DesignatedInitExpr(const ASTContext &C, QualType Ty, unsigned NumDesignators, const Designator *Designators, SourceLocation EqualOrColonLoc, bool GNUSyntax, ArrayRef IndexExprs, Expr *Init); @@ -4044,13 +4049,15 @@ public: } }; - static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators, + static DesignatedInitExpr *Create(const ASTContext &C, + Designator *Designators, unsigned NumDesignators, ArrayRef IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init); - static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs); + static DesignatedInitExpr *CreateEmpty(const ASTContext &C, + unsigned NumIndexExprs); /// @brief Returns the number of designators in this initializer. unsigned size() const { return NumDesignators; } @@ -4088,7 +4095,7 @@ public: Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; } - void setDesignators(ASTContext &C, const Designator *Desigs, + void setDesignators(const ASTContext &C, const Designator *Desigs, unsigned NumDesigs); Expr *getArrayIndex(const Designator &D) const; @@ -4136,8 +4143,8 @@ public: /// \brief Replaces the designator at index @p Idx with the series /// of designators in [First, Last). - void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First, - const Designator *Last); + void ExpandDesignator(const ASTContext &C, unsigned Idx, + const Designator *First, const Designator *Last); SourceRange getDesignatorsSourceRange() const; @@ -4191,8 +4198,8 @@ class ParenListExpr : public Expr { SourceLocation LParenLoc, RParenLoc; public: - ParenListExpr(ASTContext& C, SourceLocation lparenloc, ArrayRef exprs, - SourceLocation rparenloc); + ParenListExpr(const ASTContext& C, SourceLocation lparenloc, + ArrayRef exprs, SourceLocation rparenloc); /// \brief Build an empty paren list. explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { } @@ -4265,7 +4272,7 @@ class GenericSelectionExpr : public Expr { SourceLocation GenericLoc, DefaultLoc, RParenLoc; public: - GenericSelectionExpr(ASTContext &Context, + GenericSelectionExpr(const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr, ArrayRef AssocTypes, ArrayRef AssocExprs, @@ -4274,7 +4281,7 @@ public: unsigned ResultIndex); /// This constructor is used in the result-dependent case. - GenericSelectionExpr(ASTContext &Context, + GenericSelectionExpr(const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr, ArrayRef AssocTypes, ArrayRef AssocExprs, @@ -4557,11 +4564,11 @@ public: /// no semantic result. enum { NoResult = ~0U }; - static PseudoObjectExpr *Create(ASTContext &Context, Expr *syntactic, + static PseudoObjectExpr *Create(const ASTContext &Context, Expr *syntactic, ArrayRef semantic, unsigned resultIndex); - static PseudoObjectExpr *Create(ASTContext &Context, EmptyShell shell, + static PseudoObjectExpr *Create(const ASTContext &Context, EmptyShell shell, unsigned numSemanticExprs); /// Return the syntactic form of this expression, i.e. the diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index dff9a1df75..834a3dc1c0 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -312,19 +312,19 @@ protected: public: // Only allow allocation of Stmts using the allocator in ASTContext // or by doing a placement new. - void* operator new(size_t bytes, ASTContext& C, + void* operator new(size_t bytes, const ASTContext& C, unsigned alignment = 8) throw(); - void* operator new(size_t bytes, ASTContext* C, + void* operator new(size_t bytes, const ASTContext* C, unsigned alignment = 8) throw(); void* operator new(size_t bytes, void* mem) throw() { return mem; } - void operator delete(void*, ASTContext&, unsigned) throw() { } - void operator delete(void*, ASTContext*, unsigned) throw() { } - void operator delete(void*, std::size_t) throw() { } + void operator delete(void*, const ASTContext&, unsigned) throw() { } + void operator delete(void*, const ASTContext*, unsigned) throw() { } + void operator delete(void*, size_t) throw() { } void operator delete(void*, void*) throw() { } public: diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 3eeb53e620..6a1e500d33 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -622,7 +622,8 @@ std::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { return ""; } -void APNumericStorage::setIntValue(ASTContext &C, const llvm::APInt &Val) { +void APNumericStorage::setIntValue(const ASTContext &C, + const llvm::APInt &Val) { if (hasAllocation()) C.Deallocate(pVal); @@ -638,7 +639,7 @@ void APNumericStorage::setIntValue(ASTContext &C, const llvm::APInt &Val) { VAL = 0; } -IntegerLiteral::IntegerLiteral(ASTContext &C, const llvm::APInt &V, +IntegerLiteral::IntegerLiteral(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l) : Expr(IntegerLiteralClass, type, VK_RValue, OK_Ordinary, false, false, false, false), @@ -650,17 +651,17 @@ IntegerLiteral::IntegerLiteral(ASTContext &C, const llvm::APInt &V, } IntegerLiteral * -IntegerLiteral::Create(ASTContext &C, const llvm::APInt &V, +IntegerLiteral::Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l) { return new (C) IntegerLiteral(C, V, type, l); } IntegerLiteral * -IntegerLiteral::Create(ASTContext &C, EmptyShell Empty) { +IntegerLiteral::Create(const ASTContext &C, EmptyShell Empty) { return new (C) IntegerLiteral(Empty); } -FloatingLiteral::FloatingLiteral(ASTContext &C, const llvm::APFloat &V, +FloatingLiteral::FloatingLiteral(const 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) { @@ -669,20 +670,20 @@ FloatingLiteral::FloatingLiteral(ASTContext &C, const llvm::APFloat &V, setValue(C, V); } -FloatingLiteral::FloatingLiteral(ASTContext &C, EmptyShell Empty) +FloatingLiteral::FloatingLiteral(const ASTContext &C, EmptyShell Empty) : Expr(FloatingLiteralClass, Empty) { setRawSemantics(IEEEhalf); FloatingLiteralBits.IsExact = false; } FloatingLiteral * -FloatingLiteral::Create(ASTContext &C, const llvm::APFloat &V, +FloatingLiteral::Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L) { return new (C) FloatingLiteral(C, V, isexact, Type, L); } FloatingLiteral * -FloatingLiteral::Create(ASTContext &C, EmptyShell Empty) { +FloatingLiteral::Create(const ASTContext &C, EmptyShell Empty) { return new (C) FloatingLiteral(C, Empty); } @@ -756,7 +757,7 @@ int StringLiteral::mapCharByteWidth(TargetInfo const &target,StringKind k) { return CharByteWidth; } -StringLiteral *StringLiteral::Create(ASTContext &C, StringRef Str, +StringLiteral *StringLiteral::Create(const ASTContext &C, StringRef Str, StringKind Kind, bool Pascal, QualType Ty, const SourceLocation *Loc, unsigned NumStrs) { @@ -778,7 +779,8 @@ StringLiteral *StringLiteral::Create(ASTContext &C, StringRef Str, return SL; } -StringLiteral *StringLiteral::CreateEmpty(ASTContext &C, unsigned NumStrs) { +StringLiteral *StringLiteral::CreateEmpty(const ASTContext &C, + unsigned NumStrs) { void *Mem = C.Allocate(sizeof(StringLiteral)+ sizeof(SourceLocation)*(NumStrs-1), llvm::alignOf()); @@ -882,7 +884,7 @@ void StringLiteral::outputString(raw_ostream &OS) const { OS << '"'; } -void StringLiteral::setString(ASTContext &C, StringRef Str, +void StringLiteral::setString(const ASTContext &C, StringRef Str, StringKind Kind, bool IsPascal) { //FIXME: we assume that the string data comes from a target that uses the same // code unit size and endianess for the type of string. @@ -1035,9 +1037,9 @@ OverloadedOperatorKind UnaryOperator::getOverloadedOperator(Opcode Opc) { // Postfix Operators. //===----------------------------------------------------------------------===// -CallExpr::CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs, - ArrayRef args, QualType t, ExprValueKind VK, - SourceLocation rparenloc) +CallExpr::CallExpr(const ASTContext& C, StmtClass SC, Expr *fn, + unsigned NumPreArgs, ArrayRef args, QualType t, + ExprValueKind VK, SourceLocation rparenloc) : Expr(SC, t, VK, OK_Ordinary, fn->isTypeDependent(), fn->isValueDependent(), @@ -1064,7 +1066,7 @@ CallExpr::CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs, RParenLoc = rparenloc; } -CallExpr::CallExpr(ASTContext& C, Expr *fn, ArrayRef args, +CallExpr::CallExpr(const ASTContext& C, Expr *fn, ArrayRef args, QualType t, ExprValueKind VK, SourceLocation rparenloc) : Expr(CallExprClass, t, VK, OK_Ordinary, fn->isTypeDependent(), @@ -1092,14 +1094,14 @@ CallExpr::CallExpr(ASTContext& C, Expr *fn, ArrayRef args, RParenLoc = rparenloc; } -CallExpr::CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty) +CallExpr::CallExpr(const ASTContext &C, StmtClass SC, EmptyShell Empty) : Expr(SC, Empty), SubExprs(0), NumArgs(0) { // FIXME: Why do we allocate this? SubExprs = new (C) Stmt*[PREARGS_START]; CallExprBits.NumPreArgs = 0; } -CallExpr::CallExpr(ASTContext &C, StmtClass SC, unsigned NumPreArgs, +CallExpr::CallExpr(const ASTContext &C, StmtClass SC, unsigned NumPreArgs, EmptyShell Empty) : Expr(SC, Empty), SubExprs(0), NumArgs(0) { // FIXME: Why do we allocate this? @@ -1138,7 +1140,7 @@ FunctionDecl *CallExpr::getDirectCallee() { /// setNumArgs - This changes the number of arguments present in this call. /// Any orphaned expressions are deleted by this, and any new operands are set /// to null. -void CallExpr::setNumArgs(ASTContext& C, unsigned NumArgs) { +void CallExpr::setNumArgs(const ASTContext& C, unsigned NumArgs) { // No change, just return. if (NumArgs == getNumArgs()) return; @@ -1227,7 +1229,7 @@ SourceLocation CallExpr::getLocEnd() const { return end; } -OffsetOfExpr *OffsetOfExpr::Create(ASTContext &C, QualType type, +OffsetOfExpr *OffsetOfExpr::Create(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef comps, @@ -1241,7 +1243,7 @@ OffsetOfExpr *OffsetOfExpr::Create(ASTContext &C, QualType type, RParenLoc); } -OffsetOfExpr *OffsetOfExpr::CreateEmpty(ASTContext &C, +OffsetOfExpr *OffsetOfExpr::CreateEmpty(const ASTContext &C, unsigned numComps, unsigned numExprs) { void *Mem = C.Allocate(sizeof(OffsetOfExpr) + sizeof(OffsetOfNode) * numComps + @@ -1249,7 +1251,7 @@ OffsetOfExpr *OffsetOfExpr::CreateEmpty(ASTContext &C, return new (Mem) OffsetOfExpr(numComps, numExprs); } -OffsetOfExpr::OffsetOfExpr(ASTContext &C, QualType type, +OffsetOfExpr::OffsetOfExpr(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef comps, ArrayRef exprs, SourceLocation RParenLoc) @@ -1283,7 +1285,7 @@ IdentifierInfo *OffsetOfExpr::OffsetOfNode::getFieldName() const { return reinterpret_cast (Data & ~(uintptr_t)Mask); } -MemberExpr *MemberExpr::Create(ASTContext &C, Expr *base, bool isarrow, +MemberExpr *MemberExpr::Create(const ASTContext &C, Expr *base, bool isarrow, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *memberdecl, @@ -1637,7 +1639,7 @@ void CastExpr::setCastPath(const CXXCastPath &Path) { memcpy(path_buffer(), Path.data(), Path.size() * sizeof(CXXBaseSpecifier*)); } -ImplicitCastExpr *ImplicitCastExpr::Create(ASTContext &C, QualType T, +ImplicitCastExpr *ImplicitCastExpr::Create(const ASTContext &C, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind VK) { @@ -1650,7 +1652,7 @@ ImplicitCastExpr *ImplicitCastExpr::Create(ASTContext &C, QualType T, return E; } -ImplicitCastExpr *ImplicitCastExpr::CreateEmpty(ASTContext &C, +ImplicitCastExpr *ImplicitCastExpr::CreateEmpty(const ASTContext &C, unsigned PathSize) { void *Buffer = C.Allocate(sizeof(ImplicitCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); @@ -1658,7 +1660,7 @@ ImplicitCastExpr *ImplicitCastExpr::CreateEmpty(ASTContext &C, } -CStyleCastExpr *CStyleCastExpr::Create(ASTContext &C, QualType T, +CStyleCastExpr *CStyleCastExpr::Create(const ASTContext &C, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *BasePath, TypeSourceInfo *WrittenTy, @@ -1672,7 +1674,8 @@ CStyleCastExpr *CStyleCastExpr::Create(ASTContext &C, QualType T, return E; } -CStyleCastExpr *CStyleCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) { +CStyleCastExpr *CStyleCastExpr::CreateEmpty(const ASTContext &C, + unsigned PathSize) { void *Buffer = C.Allocate(sizeof(CStyleCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); return new (Buffer) CStyleCastExpr(EmptyShell(), PathSize); @@ -1781,7 +1784,7 @@ OverloadedOperatorKind BinaryOperator::getOverloadedOperator(Opcode Opc) { return OverOps[Opc]; } -InitListExpr::InitListExpr(ASTContext &C, SourceLocation lbraceloc, +InitListExpr::InitListExpr(const ASTContext &C, SourceLocation lbraceloc, ArrayRef initExprs, SourceLocation rbraceloc) : Expr(InitListExprClass, QualType(), VK_RValue, OK_Ordinary, false, false, false, false), @@ -1803,16 +1806,16 @@ InitListExpr::InitListExpr(ASTContext &C, SourceLocation lbraceloc, InitExprs.insert(C, InitExprs.end(), initExprs.begin(), initExprs.end()); } -void InitListExpr::reserveInits(ASTContext &C, unsigned NumInits) { +void InitListExpr::reserveInits(const ASTContext &C, unsigned NumInits) { if (NumInits > InitExprs.size()) InitExprs.reserve(C, NumInits); } -void InitListExpr::resizeInits(ASTContext &C, unsigned NumInits) { +void InitListExpr::resizeInits(const ASTContext &C, unsigned NumInits) { InitExprs.resize(C, NumInits, 0); } -Expr *InitListExpr::updateInit(ASTContext &C, unsigned Init, Expr *expr) { +Expr *InitListExpr::updateInit(const ASTContext &C, unsigned Init, Expr *expr) { if (Init >= InitExprs.size()) { InitExprs.insert(C, InitExprs.end(), Init - InitExprs.size() + 1, 0); InitExprs.back() = expr; @@ -3531,7 +3534,7 @@ StringRef ObjCBridgedCastExpr::getBridgeKindName() const { llvm_unreachable("Invalid BridgeKind!"); } -ShuffleVectorExpr::ShuffleVectorExpr(ASTContext &C, ArrayRef args, +ShuffleVectorExpr::ShuffleVectorExpr(const ASTContext &C, ArrayRef args, QualType Type, SourceLocation BLoc, SourceLocation RP) : Expr(ShuffleVectorExprClass, Type, VK_RValue, OK_Ordinary, @@ -3555,7 +3558,7 @@ ShuffleVectorExpr::ShuffleVectorExpr(ASTContext &C, ArrayRef args, } } -void ShuffleVectorExpr::setExprs(ASTContext &C, ArrayRef Exprs) { +void ShuffleVectorExpr::setExprs(const ASTContext &C, ArrayRef Exprs) { if (SubExprs) C.Deallocate(SubExprs); this->NumExprs = Exprs.size(); @@ -3563,7 +3566,7 @@ void ShuffleVectorExpr::setExprs(ASTContext &C, ArrayRef Exprs) { memcpy(SubExprs, Exprs.data(), sizeof(Expr *) * Exprs.size()); } -GenericSelectionExpr::GenericSelectionExpr(ASTContext &Context, +GenericSelectionExpr::GenericSelectionExpr(const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr, ArrayRef AssocTypes, ArrayRef AssocExprs, @@ -3589,7 +3592,7 @@ GenericSelectionExpr::GenericSelectionExpr(ASTContext &Context, std::copy(AssocExprs.begin(), AssocExprs.end(), SubExprs+END_EXPR); } -GenericSelectionExpr::GenericSelectionExpr(ASTContext &Context, +GenericSelectionExpr::GenericSelectionExpr(const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr, ArrayRef AssocTypes, ArrayRef AssocExprs, @@ -3626,7 +3629,7 @@ IdentifierInfo *DesignatedInitExpr::Designator::getFieldName() const { return getField()->getIdentifier(); } -DesignatedInitExpr::DesignatedInitExpr(ASTContext &C, QualType Ty, +DesignatedInitExpr::DesignatedInitExpr(const ASTContext &C, QualType Ty, unsigned NumDesignators, const Designator *Designators, SourceLocation EqualOrColonLoc, @@ -3693,7 +3696,7 @@ DesignatedInitExpr::DesignatedInitExpr(ASTContext &C, QualType Ty, } DesignatedInitExpr * -DesignatedInitExpr::Create(ASTContext &C, Designator *Designators, +DesignatedInitExpr::Create(const ASTContext &C, Designator *Designators, unsigned NumDesignators, ArrayRef IndexExprs, SourceLocation ColonOrEqualLoc, @@ -3705,14 +3708,14 @@ DesignatedInitExpr::Create(ASTContext &C, Designator *Designators, IndexExprs, Init); } -DesignatedInitExpr *DesignatedInitExpr::CreateEmpty(ASTContext &C, +DesignatedInitExpr *DesignatedInitExpr::CreateEmpty(const ASTContext &C, unsigned NumIndexExprs) { void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + sizeof(Stmt *) * (NumIndexExprs + 1), 8); return new (Mem) DesignatedInitExpr(NumIndexExprs + 1); } -void DesignatedInitExpr::setDesignators(ASTContext &C, +void DesignatedInitExpr::setDesignators(const ASTContext &C, const Designator *Desigs, unsigned NumDesigs) { Designators = new (C) Designator[NumDesigs]; @@ -3779,7 +3782,7 @@ Expr *DesignatedInitExpr::getArrayRangeEnd(const Designator &D) const { /// \brief Replaces the designator at index @p Idx with the series /// of designators in [First, Last). -void DesignatedInitExpr::ExpandDesignator(ASTContext &C, unsigned Idx, +void DesignatedInitExpr::ExpandDesignator(const ASTContext &C, unsigned Idx, const Designator *First, const Designator *Last) { unsigned NumNewDesignators = Last - First; @@ -3804,7 +3807,7 @@ void DesignatedInitExpr::ExpandDesignator(ASTContext &C, unsigned Idx, NumDesignators = NumDesignators - 1 + NumNewDesignators; } -ParenListExpr::ParenListExpr(ASTContext& C, SourceLocation lparenloc, +ParenListExpr::ParenListExpr(const ASTContext& C, SourceLocation lparenloc, ArrayRef exprs, SourceLocation rparenloc) : Expr(ParenListExprClass, QualType(), VK_RValue, OK_Ordinary, @@ -3836,7 +3839,8 @@ const OpaqueValueExpr *OpaqueValueExpr::findInCopyConstruct(const Expr *e) { return cast(e); } -PseudoObjectExpr *PseudoObjectExpr::Create(ASTContext &Context, EmptyShell sh, +PseudoObjectExpr *PseudoObjectExpr::Create(const ASTContext &Context, + EmptyShell sh, unsigned numSemanticExprs) { void *buffer = Context.Allocate(sizeof(PseudoObjectExpr) + (1 + numSemanticExprs) * sizeof(Expr*), @@ -3849,7 +3853,7 @@ PseudoObjectExpr::PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs) PseudoObjectExprBits.NumSubExprs = numSemanticExprs + 1; } -PseudoObjectExpr *PseudoObjectExpr::Create(ASTContext &C, Expr *syntax, +PseudoObjectExpr *PseudoObjectExpr::Create(const ASTContext &C, Expr *syntax, ArrayRef semantics, unsigned resultIndex) { assert(syntax && "no syntactic expression!"); diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index 6a39996cac..87e55a2fb9 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -49,12 +49,12 @@ static StmtClassNameTable &getStmtInfoTableEntry(Stmt::StmtClass E) { return StmtClassInfo[E]; } -void *Stmt::operator new(size_t bytes, ASTContext& C, +void *Stmt::operator new(size_t bytes, const ASTContext& C, unsigned alignment) throw() { return ::operator new(bytes, C, alignment); } -void *Stmt::operator new(size_t bytes, ASTContext* C, +void *Stmt::operator new(size_t bytes, const ASTContext* C, unsigned alignment) throw() { return ::operator new(bytes, *C, alignment); }