Author: eugenezelenko Date: Fri Nov 17 10:09:48 2017 New Revision: 318538 URL: http://llvm.org/viewvc/llvm-project?rev=318538&view=rev Log: [AST] Partially revert r318341 to fix two broken tests on llvm-clang-x86_64-expensive-checks-win (NFC).
Modified: cfe/trunk/include/clang/AST/Expr.h cfe/trunk/lib/AST/Expr.cpp Modified: cfe/trunk/include/clang/AST/Expr.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=318538&r1=318537&r2=318538&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/Expr.h (original) +++ cfe/trunk/include/clang/AST/Expr.h Fri Nov 17 10:09:48 2017 @@ -1,4 +1,4 @@ -//===- Expr.h - Classes for representing expressions ------------*- C++ -*-===// +//===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -18,56 +18,42 @@ #include "clang/AST/ASTVector.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclAccessPair.h" -#include "clang/AST/DeclarationName.h" -#include "clang/AST/NestedNameSpecifier.h" #include "clang/AST/OperationKinds.h" #include "clang/AST/Stmt.h" #include "clang/AST/TemplateBase.h" #include "clang/AST/Type.h" #include "clang/Basic/CharInfo.h" -#include "clang/Basic/LLVM.h" #include "clang/Basic/LangOptions.h" -#include "clang/Basic/OperatorKinds.h" -#include "clang/Basic/SourceLocation.h" -#include "clang/Basic/Specifiers.h" #include "clang/Basic/SyncScope.h" #include "clang/Basic/TypeTraits.h" #include "llvm/ADT/APFloat.h" -#include "llvm/ADT/APInt.h" #include "llvm/ADT/APSInt.h" -#include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/None.h" -#include "llvm/ADT/PointerIntPair.h" -#include "llvm/ADT/PointerUnion.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" -#include "llvm/ADT/iterator_range.h" -#include "llvm/Support/Casting.h" +#include "llvm/Support/AtomicOrdering.h" #include "llvm/Support/Compiler.h" -#include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/TrailingObjects.h" -#include <cassert> -#include <cstddef> -#include <cstdint> -#include <memory> -#include <string> namespace clang { - -class ASTContext; -class CastExpr; -class CXXBaseSpecifier; -class CXXRecordDecl; -class Decl; -class Expr; -class IdentifierInfo; -class ObjCPropertyRefExpr; -class SourceManager; -class StringLiteral; -class TargetInfo; + class APValue; + class ASTContext; + class BlockDecl; + class CXXBaseSpecifier; + class CXXMemberCallExpr; + class CXXOperatorCallExpr; + class CastExpr; + class Decl; + class IdentifierInfo; + class MaterializeTemporaryExpr; + class NamedDecl; + class ObjCPropertyRefExpr; + class OpaqueValueExpr; + class ParmVarDecl; + class StringLiteral; + class TargetInfo; + class ValueDecl; /// \brief A simple array of base specifiers. -using CXXCastPath = SmallVector<CXXBaseSpecifier *, 4>; +typedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; /// \brief An adjustment to be made to the temporary created when emitting a /// reference binding, which accesses a particular subobject of that temporary. @@ -96,17 +82,18 @@ struct SubobjectAdjustment { SubobjectAdjustment(const CastExpr *BasePath, const CXXRecordDecl *DerivedClass) - : Kind(DerivedToBaseAdjustment) { + : Kind(DerivedToBaseAdjustment) { DerivedToBase.BasePath = BasePath; DerivedToBase.DerivedClass = DerivedClass; } - SubobjectAdjustment(FieldDecl *Field) : Kind(FieldAdjustment) { + SubobjectAdjustment(FieldDecl *Field) + : Kind(FieldAdjustment) { this->Field = Field; } SubobjectAdjustment(const MemberPointerType *MPT, Expr *RHS) - : Kind(MemberPointerAdjustment) { + : Kind(MemberPointerAdjustment) { this->Ptr.MPT = MPT; this->Ptr.RHS = RHS; } @@ -122,7 +109,8 @@ class Expr : public Stmt { protected: Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK, bool TD, bool VD, bool ID, bool ContainsUnexpandedParameterPack) - : Stmt(SC) { + : Stmt(SC) + { ExprBits.TypeDependent = TD; ExprBits.ValueDependent = VD; ExprBits.InstantiationDependent = ID; @@ -134,11 +122,10 @@ protected: } /// \brief Construct an empty expression. - explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) {} + explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { } public: QualType getType() const { return TR; } - void setType(QualType t) { // In C++, the type of an expression is always adjusted so that it // will not have reference type (C++ [expr]p6). Use @@ -200,6 +187,7 @@ public: /// sizeof(sizeof(T() + T()); /// } /// \endcode + /// bool isInstantiationDependent() const { return ExprBits.InstantiationDependent; } @@ -275,7 +263,6 @@ public: LV_ClassTemporary, LV_ArrayTemporary }; - /// Reasons why an expression might not be an l-value. LValueClassification ClassifyLValue(ASTContext &Ctx) const; @@ -298,7 +285,6 @@ public: MLV_ClassTemporary, MLV_ArrayTemporary }; - /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, /// does not have an incomplete type, does not have a const-qualified type, /// and if it is a structure or union, does not have any member (including, @@ -330,7 +316,6 @@ public: CL_ObjCMessageRValue, // ObjC message is an rvalue CL_PRValue // A prvalue for any other reason, of any other type }; - /// \brief The results of modification testing. enum ModifiableType { CM_Untested, // testModifiable was false. @@ -353,18 +338,17 @@ public: unsigned short Modifiable; explicit Classification(Kinds k, ModifiableType m) - : Kind(k), Modifiable(m) {} + : Kind(k), Modifiable(m) + {} public: - Classification() = default; + Classification() {} Kinds getKind() const { return static_cast<Kinds>(Kind); } - ModifiableType getModifiable() const { assert(Modifiable != CM_Untested && "Did not test for modifiability."); return static_cast<ModifiableType>(Modifiable); } - bool isLValue() const { return Kind == CL_LValue; } bool isXValue() const { return Kind == CL_XValue; } bool isGLValue() const { return Kind <= CL_XValue; } @@ -378,7 +362,6 @@ public: } }; - /// \brief Classify - Classify this expression according to the C++11 /// expression taxonomy. /// @@ -445,6 +428,7 @@ private: Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const; public: + /// \brief Returns true if this expression is a gl-value that /// potentially refers to a bit-field. /// @@ -557,12 +541,12 @@ public: struct EvalStatus { /// \brief Whether the evaluated expression has side effects. /// For example, (f() && 0) can be folded, but it still has side effects. - bool HasSideEffects = false; + bool HasSideEffects; /// \brief Whether the evaluation hit undefined behavior. /// For example, 1.0 / 0.0 can be folded to Inf, but has undefined behavior. /// Likewise, INT_MAX + 1 can be folded to INT_MIN, but has UB. - bool HasUndefinedBehavior = false; + bool HasUndefinedBehavior; /// Diag - If this is non-null, it will be filled in with a stack of notes /// indicating why evaluation failed (or why it failed to produce a constant @@ -571,9 +555,10 @@ public: /// foldable. If the expression is foldable, but not a constant expression, /// the notes will describes why it isn't a constant expression. If the /// expression *is* a constant expression, no notes will be produced. - SmallVectorImpl<PartialDiagnosticAt> *Diag = nullptr; + SmallVectorImpl<PartialDiagnosticAt> *Diag; - EvalStatus() = default; + EvalStatus() + : HasSideEffects(false), HasUndefinedBehavior(false), Diag(nullptr) {} // hasSideEffects - Return true if the evaluated expression has // side effects. @@ -607,15 +592,10 @@ public: bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) const; enum SideEffectsKind { - /// Strictly evaluate the expression. - SE_NoSideEffects, - - /// Allow UB that we can give a value, but not arbitrary unmodeled side - /// effects. - SE_AllowUndefinedBehavior, - - /// Allow any unmodeled side effect. - SE_AllowSideEffects + SE_NoSideEffects, ///< Strictly evaluate the expression. + SE_AllowUndefinedBehavior, ///< Allow UB that we can give a value, but not + ///< arbitrary unmodeled side effects. + SE_AllowSideEffects ///< Allow any unmodeled side effect. }; /// EvaluateAsInt - Return true if this is a constant which we can fold and @@ -827,15 +807,12 @@ public: const Expr *IgnoreImpCasts() const LLVM_READONLY { return const_cast<Expr*>(this)->IgnoreImpCasts(); } - const Expr *IgnoreParens() const LLVM_READONLY { return const_cast<Expr*>(this)->IgnoreParens(); } - const Expr *IgnoreParenCasts() const LLVM_READONLY { return const_cast<Expr*>(this)->IgnoreParenCasts(); } - /// Strip off casts, but keep parentheses. const Expr *IgnoreCasts() const LLVM_READONLY { return const_cast<Expr*>(this)->IgnoreCasts(); @@ -890,7 +867,6 @@ public: /// context. class OpaqueValueExpr : public Expr { friend class ASTStmtReader; - Expr *SourceExpr; SourceLocation Loc; @@ -915,7 +891,7 @@ public: static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr); explicit OpaqueValueExpr(EmptyShell Empty) - : Expr(OpaqueValueExprClass, Empty) {} + : Expr(OpaqueValueExprClass, Empty) { } /// \brief Retrieve the location of this expression. SourceLocation getLocation() const { return Loc; } @@ -923,11 +899,9 @@ public: SourceLocation getLocStart() const LLVM_READONLY { return SourceExpr ? SourceExpr->getLocStart() : Loc; } - SourceLocation getLocEnd() const LLVM_READONLY { return SourceExpr ? SourceExpr->getLocEnd() : Loc; } - SourceLocation getExprLoc() const LLVM_READONLY { if (SourceExpr) return SourceExpr->getExprLoc(); return Loc; @@ -994,18 +968,6 @@ class DeclRefExpr final /// embedded in D. DeclarationNameLoc DNLoc; - DeclRefExpr(const ASTContext &Ctx, - NestedNameSpecifierLoc QualifierLoc, - SourceLocation TemplateKWLoc, - ValueDecl *D, bool RefersToEnlosingVariableOrCapture, - const DeclarationNameInfo &NameInfo, - NamedDecl *FoundD, - const TemplateArgumentListInfo *TemplateArgs, - QualType T, ExprValueKind VK); - - /// \brief Construct an empty declaration reference expression. - explicit DeclRefExpr(EmptyShell Empty) : Expr(DeclRefExprClass, Empty) {} - size_t numTrailingObjects(OverloadToken<NestedNameSpecifierLoc>) const { return hasQualifier() ? 1 : 0; } @@ -1022,15 +984,24 @@ class DeclRefExpr final /// this DRE. bool hasFoundDecl() const { return DeclRefExprBits.HasFoundDecl; } + DeclRefExpr(const ASTContext &Ctx, + NestedNameSpecifierLoc QualifierLoc, + SourceLocation TemplateKWLoc, + ValueDecl *D, bool RefersToEnlosingVariableOrCapture, + const DeclarationNameInfo &NameInfo, + NamedDecl *FoundD, + const TemplateArgumentListInfo *TemplateArgs, + QualType T, ExprValueKind VK); + + /// \brief Construct an empty declaration reference expression. + explicit DeclRefExpr(EmptyShell Empty) + : Expr(DeclRefExprClass, Empty) { } + /// \brief Computes the type- and value-dependence flags for this /// declaration reference expression. void computeDependence(const ASTContext &C); public: - friend class ASTStmtReader; - friend class ASTStmtWriter; - friend TrailingObjects; - DeclRefExpr(ValueDecl *D, bool RefersToEnclosingVariableOrCapture, QualType T, ExprValueKind VK, SourceLocation L, const DeclarationNameLoc &LocInfo = DeclarationNameLoc()) @@ -1103,6 +1074,7 @@ public: /// This Decl may be different from the ValueDecl actually referred to in the /// presence of using declarations, etc. It always returns non-NULL, and may /// simple return the ValueDecl when appropriate. + NamedDecl *getFoundDecl() { return hasFoundDecl() ? *getTrailingObjects<NamedDecl *>() : D; } @@ -1181,7 +1153,6 @@ public: bool hadMultipleCandidates() const { return DeclRefExprBits.HadMultipleCandidates; } - /// \brief Sets the flag telling whether this expression refers to /// a function that was resolved from an overloaded set having size /// greater than 1. @@ -1207,6 +1178,10 @@ public: const_child_range children() const { return const_child_range(const_child_iterator(), const_child_iterator()); } + + friend TrailingObjects; + friend class ASTStmtReader; + friend class ASTStmtWriter; }; /// \brief [C99 6.4.2.2] - A predefined identifier such as __func__. @@ -1215,13 +1190,10 @@ public: enum IdentType { Func, Function, - - // Same as Function, but as wide string. - LFunction, + LFunction, // Same as Function, but as wide string. FuncDName, FuncSig, PrettyFunction, - /// \brief The same as PrettyFunction, except that the /// 'virtual' keyword is omitted for virtual member functions. PrettyFunctionNoVirtual @@ -1230,17 +1202,15 @@ public: private: SourceLocation Loc; IdentType Type; - Stmt *FnName = nullptr; + Stmt *FnName; public: - friend class ASTStmtReader; - PredefinedExpr(SourceLocation L, QualType FNTy, IdentType IT, StringLiteral *SL); /// \brief Construct an empty predefined expression. explicit PredefinedExpr(EmptyShell Empty) - : Expr(PredefinedExprClass, Empty), Type(Func) {} + : Expr(PredefinedExprClass, Empty), Loc(), Type(Func), FnName(nullptr) {} IdentType getIdentType() const { return Type; } @@ -1264,10 +1234,11 @@ public: // Iterators child_range children() { return child_range(&FnName, &FnName + 1); } - const_child_range children() const { return const_child_range(&FnName, &FnName + 1); } + + friend class ASTStmtReader; }; /// \brief Used by IntegerLiteral/FloatingLiteral to store the numeric without @@ -1283,12 +1254,15 @@ class APNumericStorage { uint64_t VAL; ///< Used to store the <= 64 bits integer value. uint64_t *pVal; ///< Used to store the >64 bits integer value. }; - unsigned BitWidth = 0; + unsigned BitWidth; bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; } + APNumericStorage(const APNumericStorage &) = delete; + void operator=(const APNumericStorage &) = delete; + protected: - APNumericStorage() : VAL(0) {} + APNumericStorage() : VAL(0), BitWidth(0) { } llvm::APInt getIntValue() const { unsigned NumWords = llvm::APInt::getNumWords(BitWidth); @@ -1297,18 +1271,12 @@ protected: else return llvm::APInt(BitWidth, VAL); } - void setIntValue(const ASTContext &C, const llvm::APInt &Val); - -public: - APNumericStorage(const APNumericStorage &) = delete; - APNumericStorage &operator=(const APNumericStorage &) = delete; }; class APIntStorage : private APNumericStorage { public: llvm::APInt getValue() const { return getIntValue(); } - void setValue(const ASTContext &C, const llvm::APInt &Val) { setIntValue(C, Val); } @@ -1319,7 +1287,6 @@ public: llvm::APFloat getValue(const llvm::fltSemantics &Semantics) const { return llvm::APFloat(Semantics, getIntValue()); } - void setValue(const ASTContext &C, const llvm::APFloat &Val) { setIntValue(C, Val.bitcastToAPInt()); } @@ -1330,7 +1297,7 @@ class IntegerLiteral : public Expr, publ /// \brief Construct an empty integer literal. explicit IntegerLiteral(EmptyShell Empty) - : Expr(IntegerLiteralClass, Empty) {} + : Expr(IntegerLiteralClass, Empty) { } public: // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, @@ -1344,7 +1311,6 @@ public: /// \param V - the value that the returned integer literal contains. static IntegerLiteral *Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l); - /// \brief Returns a new empty integer literal. static IntegerLiteral *Create(const ASTContext &C, EmptyShell Empty); @@ -1364,7 +1330,6 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } - const_child_range children() const { return const_child_range(const_child_iterator(), const_child_iterator()); } @@ -1383,7 +1348,6 @@ public: private: unsigned Value; SourceLocation Loc; - public: // type should be IntTy CharacterLiteral(unsigned value, CharacterKind kind, QualType type, @@ -1395,10 +1359,9 @@ public: } /// \brief Construct an empty character literal. - CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) {} + CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { } SourceLocation getLocation() const { return Loc; } - CharacterKind getKind() const { return static_cast<CharacterKind>(CharacterLiteralBits.Kind); } @@ -1420,7 +1383,6 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } - const_child_range children() const { return const_child_range(const_child_iterator(), const_child_iterator()); } @@ -1443,7 +1405,6 @@ public: llvm::APFloat getValue() const { return APFloatStorage::getValue(getSemantics()); } - void setValue(const ASTContext &C, const llvm::APFloat &Val) { assert(&getSemantics() == &Val.getSemantics() && "Inconsistent semantics"); APFloatStorage::setValue(C, Val); @@ -1489,7 +1450,6 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } - const_child_range children() const { return const_child_range(const_child_iterator(), const_child_iterator()); } @@ -1499,9 +1459,9 @@ public: /// like "1.0i". We represent these as a wrapper around FloatingLiteral and /// IntegerLiteral classes. Instances of this class always have a Complex type /// whose element type matches the subexpression. +/// class ImaginaryLiteral : public Expr { Stmt *Val; - public: ImaginaryLiteral(Expr *val, QualType Ty) : Expr(ImaginaryLiteralClass, Ty, VK_RValue, OK_Ordinary, false, false, @@ -1510,7 +1470,7 @@ public: /// \brief Build an empty imaginary literal. explicit ImaginaryLiteral(EmptyShell Empty) - : Expr(ImaginaryLiteralClass, Empty) {} + : Expr(ImaginaryLiteralClass, Empty) { } const Expr *getSubExpr() const { return cast<Expr>(Val); } Expr *getSubExpr() { return cast<Expr>(Val); } @@ -1525,7 +1485,6 @@ public: // Iterators child_range children() { return child_range(&Val, &Val+1); } - const_child_range children() const { return const_child_range(&Val, &Val + 1); } @@ -1572,11 +1531,11 @@ private: unsigned NumConcatenated; SourceLocation TokLocs[1]; - StringLiteral(QualType Ty) - : Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary, false, false, - false, false) {} + StringLiteral(QualType Ty) : + Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary, false, false, false, + false) {} - static int mapCharByteWidth(TargetInfo const &target, StringKind k); + static int mapCharByteWidth(TargetInfo const &target,StringKind k); public: /// This is the "fully general" constructor that allows representation of @@ -1637,6 +1596,7 @@ public: StringKind getKind() const { return static_cast<StringKind>(Kind); } + bool isAscii() const { return Kind == Ascii; } bool isWide() const { return Kind == Wide; } bool isUTF8() const { return Kind == UTF8; } @@ -1678,13 +1638,11 @@ public: unsigned *StartToken = nullptr, unsigned *StartTokenByteOffset = nullptr) const; - using tokloc_iterator = const SourceLocation *; - + typedef const SourceLocation *tokloc_iterator; tokloc_iterator tokloc_begin() const { return TokLocs; } tokloc_iterator tokloc_end() const { return TokLocs + NumConcatenated; } SourceLocation getLocStart() const LLVM_READONLY { return TokLocs[0]; } - SourceLocation getLocEnd() const LLVM_READONLY { return TokLocs[NumConcatenated - 1]; } @@ -1697,7 +1655,6 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } - const_child_range children() const { return const_child_range(const_child_iterator(), const_child_iterator()); } @@ -1708,7 +1665,6 @@ public: class ParenExpr : public Expr { SourceLocation L, R; Stmt *Val; - public: ParenExpr(SourceLocation l, SourceLocation r, Expr *val) : Expr(ParenExprClass, val->getType(), @@ -1719,7 +1675,8 @@ public: L(l), R(r), Val(val) {} /// \brief Construct an empty parenthesized expression. - explicit ParenExpr(EmptyShell Empty) : Expr(ParenExprClass, Empty) {} + explicit ParenExpr(EmptyShell Empty) + : Expr(ParenExprClass, Empty) { } const Expr *getSubExpr() const { return cast<Expr>(Val); } Expr *getSubExpr() { return cast<Expr>(Val); } @@ -1742,7 +1699,6 @@ public: // Iterators child_range children() { return child_range(&Val, &Val+1); } - const_child_range children() const { return const_child_range(&Val, &Val + 1); } @@ -1757,16 +1713,17 @@ public: /// Real/Imag - These return the real/imag part of a complex operand. If /// applied to a non-complex value, the former returns its operand and the /// later returns zero in the type of the operand. +/// class UnaryOperator : public Expr { public: - using Opcode = UnaryOperatorKind; + typedef UnaryOperatorKind Opcode; private: unsigned Opc : 5; SourceLocation Loc; Stmt *Val; - public: + UnaryOperator(Expr *input, Opcode opc, QualType type, ExprValueKind VK, ExprObjectKind OK, SourceLocation l) : Expr(UnaryOperatorClass, type, VK, OK, @@ -1779,7 +1736,7 @@ public: /// \brief Build an empty unary operator. explicit UnaryOperator(EmptyShell Empty) - : Expr(UnaryOperatorClass, Empty), Opc(UO_AddrOf) {} + : Expr(UnaryOperatorClass, Empty), Opc(UO_AddrOf) { } Opcode getOpcode() const { return static_cast<Opcode>(Opc); } void setOpcode(Opcode O) { Opc = O; } @@ -1843,11 +1800,9 @@ public: SourceLocation getLocStart() const LLVM_READONLY { return isPostfix() ? Val->getLocStart() : Loc; } - SourceLocation getLocEnd() const LLVM_READONLY { return isPostfix() ? Loc : Val->getLocEnd(); } - SourceLocation getExprLoc() const LLVM_READONLY { return Loc; } static bool classof(const Stmt *T) { @@ -1856,7 +1811,6 @@ public: // Iterators child_range children() { return child_range(&Val, &Val+1); } - const_child_range children() const { return const_child_range(&Val, &Val + 1); } @@ -1871,13 +1825,10 @@ public: enum Kind { /// \brief An index into an array. Array = 0x00, - /// \brief A field. Field = 0x01, - /// \brief A field in a dependent type, known only by its name. Identifier = 0x02, - /// \brief An implicit indirection through a C++ base class, when the /// field found is in a base class. Base = 0x03 @@ -1919,7 +1870,7 @@ public: /// \brief Create an offsetof node that refers into a C++ base class. explicit OffsetOfNode(const CXXBaseSpecifier *Base) - : Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {} + : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {} /// \brief Determine what kind of offsetof node this is. Kind getKind() const { return static_cast<Kind>(Data & Mask); } @@ -1971,17 +1922,15 @@ public: /// }; /// @endcode /// we can represent and evaluate the expression @c offsetof(struct T, s[2].d). + class OffsetOfExpr final : public Expr, private llvm::TrailingObjects<OffsetOfExpr, OffsetOfNode, Expr *> { SourceLocation OperatorLoc, RParenLoc; - // Base type; - TypeSourceInfo *TSInfo = nullptr; - + TypeSourceInfo *TSInfo; // Number of sub-components (i.e. instances of OffsetOfNode). unsigned NumComps; - // Number of sub-expressions (i.e. array subscript expressions). unsigned NumExprs; @@ -1995,11 +1944,10 @@ class OffsetOfExpr final SourceLocation RParenLoc); explicit OffsetOfExpr(unsigned numComps, unsigned numExprs) - : Expr(OffsetOfExprClass, EmptyShell()), NumComps(numComps), - NumExprs(numExprs) {} + : Expr(OffsetOfExprClass, EmptyShell()), + TSInfo(nullptr), NumComps(numComps), NumExprs(numExprs) {} public: - friend TrailingObjects; static OffsetOfExpr *Create(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, @@ -2020,7 +1968,6 @@ public: TypeSourceInfo *getTypeSourceInfo() const { return TSInfo; } - void setTypeSourceInfo(TypeSourceInfo *tsi) { TSInfo = tsi; } @@ -2070,12 +2017,12 @@ public: Stmt **begin = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>()); return child_range(begin, begin + NumExprs); } - const_child_range children() const { Stmt *const *begin = reinterpret_cast<Stmt *const *>(getTrailingObjects<Expr *>()); return const_child_range(begin, begin + NumExprs); } + friend TrailingObjects; }; /// UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) @@ -2110,25 +2057,21 @@ public: /// \brief Construct an empty sizeof/alignof expression. explicit UnaryExprOrTypeTraitExpr(EmptyShell Empty) - : Expr(UnaryExprOrTypeTraitExprClass, Empty) {} + : Expr(UnaryExprOrTypeTraitExprClass, Empty) { } UnaryExprOrTypeTrait getKind() const { return static_cast<UnaryExprOrTypeTrait>(UnaryExprOrTypeTraitExprBits.Kind); } - void setKind(UnaryExprOrTypeTrait K) { UnaryExprOrTypeTraitExprBits.Kind = K;} bool isArgumentType() const { return UnaryExprOrTypeTraitExprBits.IsType; } - QualType getArgumentType() const { return getArgumentTypeInfo()->getType(); } - TypeSourceInfo *getArgumentTypeInfo() const { assert(isArgumentType() && "calling getArgumentType() when arg is expr"); return Argument.Ty; } - Expr *getArgumentExpr() { assert(!isArgumentType() && "calling getArgumentExpr() when arg is type"); return static_cast<Expr*>(Argument.Ex); @@ -2177,10 +2120,8 @@ public: /// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting. class ArraySubscriptExpr : public Expr { enum { LHS, RHS, END_EXPR=2 }; - Stmt* SubExprs[END_EXPR]; SourceLocation RBracketLoc; - public: ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, ExprValueKind VK, ExprObjectKind OK, @@ -2199,7 +2140,7 @@ public: /// \brief Create an empty array subscript expression. explicit ArraySubscriptExpr(EmptyShell Shell) - : Expr(ArraySubscriptExprClass, Shell) {} + : Expr(ArraySubscriptExprClass, Shell) { } /// An array access can be written A[4] or 4[A] (both are equivalent). /// - getBase() and getIdx() always present the normalized view: A[4]. @@ -2237,7 +2178,6 @@ public: SourceLocation getLocStart() const LLVM_READONLY { return getLHS()->getLocStart(); } - SourceLocation getLocEnd() const LLVM_READONLY { return RBracketLoc; } SourceLocation getRBracketLoc() const { return RBracketLoc; } @@ -2255,7 +2195,6 @@ public: child_range children() { return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); } - const_child_range children() const { return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR); } @@ -2269,9 +2208,8 @@ public: /// "str1 + str2" to resolve to a function call. class CallExpr : public Expr { enum { FN=0, PREARGS_START=1 }; - - Stmt **SubExprs = nullptr; - unsigned NumArgs = 0; + Stmt **SubExprs; + unsigned NumArgs; SourceLocation RParenLoc; void updateDependenciesFromArg(Expr *Arg); @@ -2324,6 +2262,7 @@ public: } /// getNumArgs - Return the number of actual arguments to this call. + /// unsigned getNumArgs() const { return NumArgs; } /// \brief Retrieve the call arguments. @@ -2356,10 +2295,10 @@ public: /// to null. void setNumArgs(const ASTContext& C, unsigned NumArgs); - using arg_iterator = ExprIterator; - using const_arg_iterator = ConstExprIterator; - using arg_range = llvm::iterator_range<arg_iterator>; - using arg_const_range = llvm::iterator_range<const_arg_iterator>; + typedef ExprIterator arg_iterator; + typedef ConstExprIterator const_arg_iterator; + typedef llvm::iterator_range<arg_iterator> arg_range; + typedef llvm::iterator_range<const_arg_iterator> arg_const_range; arg_range arguments() { return arg_range(arg_begin(), arg_end()); } arg_const_range arguments() const { @@ -2367,15 +2306,12 @@ public: } arg_iterator arg_begin() { return SubExprs+PREARGS_START+getNumPreArgs(); } - arg_iterator arg_end() { return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); } - const_arg_iterator arg_begin() const { return SubExprs+PREARGS_START+getNumPreArgs(); } - const_arg_iterator arg_end() const { return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); } @@ -2500,10 +2436,6 @@ class MemberExpr final } public: - friend class ASTReader; - friend class ASTStmtWriter; - friend TrailingObjects; - MemberExpr(Expr *base, bool isarrow, SourceLocation operatorloc, ValueDecl *memberdecl, const DeclarationNameInfo &NameInfo, QualType ty, ExprValueKind VK, ExprObjectKind OK) @@ -2527,7 +2459,7 @@ public: : Expr(MemberExprClass, ty, VK, OK, base->isTypeDependent(), base->isValueDependent(), base->isInstantiationDependent(), base->containsUnexpandedParameterPack()), - Base(base), MemberDecl(memberdecl), MemberLoc(l), + Base(base), MemberDecl(memberdecl), MemberDNLoc(), MemberLoc(l), OperatorLoc(operatorloc), IsArrow(isarrow), HasQualifierOrFoundDecl(false), HasTemplateKWAndArgsInfo(false), HadMultipleCandidates(false) {} @@ -2670,7 +2602,6 @@ public: bool hadMultipleCandidates() const { return HadMultipleCandidates; } - /// \brief Sets the flag telling whether this expression refers to /// a method that was resolved from an overloaded set having size /// greater than 1. @@ -2692,13 +2623,17 @@ public: // Iterators child_range children() { return child_range(&Base, &Base+1); } - const_child_range children() const { return const_child_range(&Base, &Base + 1); } + + friend TrailingObjects; + friend class ASTReader; + friend class ASTStmtWriter; }; /// CompoundLiteralExpr - [C99 6.5.2.5] +/// class CompoundLiteralExpr : public Expr { /// LParenLoc - If non-null, this is the location of the left paren in a /// compound literal like "(int){4}". This can be null if this is a @@ -2710,7 +2645,6 @@ class CompoundLiteralExpr : public Expr /// The int part of the pair stores whether this expr is file scope. llvm::PointerIntPair<TypeSourceInfo *, 1, bool> TInfoAndScope; Stmt *Init; - public: CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo, QualType T, ExprValueKind VK, Expr *init, bool fileScope) @@ -2724,7 +2658,7 @@ public: /// \brief Construct an empty compound literal. explicit CompoundLiteralExpr(EmptyShell Empty) - : Expr(CompoundLiteralExprClass, Empty) {} + : Expr(CompoundLiteralExprClass, Empty) { } const Expr *getInitializer() const { return cast<Expr>(Init); } Expr *getInitializer() { return cast<Expr>(Init); } @@ -2739,7 +2673,6 @@ public: TypeSourceInfo *getTypeSourceInfo() const { return TInfoAndScope.getPointer(); } - void setTypeSourceInfo(TypeSourceInfo *tinfo) { TInfoAndScope.setPointer(tinfo); } @@ -2752,7 +2685,6 @@ public: return Init->getLocStart(); return LParenLoc; } - SourceLocation getLocEnd() const LLVM_READONLY { // FIXME: Init should never be null. if (!Init) @@ -2766,7 +2698,6 @@ public: // Iterators child_range children() { return child_range(&Init, &Init+1); } - const_child_range children() const { return const_child_range(&Init, &Init + 1); } @@ -2785,7 +2716,6 @@ private: const CXXBaseSpecifier * const *path_buffer() const { return const_cast<CastExpr*>(this)->path_buffer(); } - CXXBaseSpecifier **path_buffer(); void setBasePathSize(unsigned basePathSize) { @@ -2820,7 +2750,7 @@ protected: /// \brief Construct an empty cast. CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize) - : Expr(SC, Empty) { + : Expr(SC, Empty) { setBasePathSize(BasePathSize); } @@ -2841,9 +2771,8 @@ public: return const_cast<CastExpr *>(this)->getSubExprAsWritten(); } - using path_iterator = CXXBaseSpecifier **; - using path_const_iterator = const CXXBaseSpecifier * const *; - + typedef CXXBaseSpecifier **path_iterator; + typedef const CXXBaseSpecifier * const *path_const_iterator; bool path_empty() const { return CastExprBits.BasePathSize == 0; } unsigned path_size() const { return CastExprBits.BasePathSize; } path_iterator path_begin() { return path_buffer(); } @@ -2897,21 +2826,19 @@ class ImplicitCastExpr final private: ImplicitCastExpr(QualType ty, CastKind kind, Expr *op, unsigned BasePathLength, ExprValueKind VK) - : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength) {} + : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength) { + } /// \brief Construct an empty implicit cast. explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize) - : CastExpr(ImplicitCastExprClass, Shell, PathSize) {} + : CastExpr(ImplicitCastExprClass, Shell, PathSize) { } public: - friend class CastExpr; - friend TrailingObjects; - enum OnStack_t { OnStack }; - ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op, ExprValueKind VK) - : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) {} + : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) { + } static ImplicitCastExpr *Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, @@ -2924,7 +2851,6 @@ public: SourceLocation getLocStart() const LLVM_READONLY { return getSubExpr()->getLocStart(); } - SourceLocation getLocEnd() const LLVM_READONLY { return getSubExpr()->getLocEnd(); } @@ -2932,6 +2858,9 @@ public: static bool classof(const Stmt *T) { return T->getStmtClass() == ImplicitCastExprClass; } + + friend TrailingObjects; + friend class CastExpr; }; inline Expr *Expr::IgnoreImpCasts() { @@ -2966,11 +2895,11 @@ protected: ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK, CastKind kind, Expr *op, unsigned PathSize, TypeSourceInfo *writtenTy) - : CastExpr(SC, exprTy, VK, kind, op, PathSize), TInfo(writtenTy) {} + : CastExpr(SC, exprTy, VK, kind, op, PathSize), TInfo(writtenTy) {} /// \brief Construct an empty explicit cast. ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize) - : CastExpr(SC, Shell, PathSize) {} + : CastExpr(SC, Shell, PathSize) { } public: /// getTypeInfoAsWritten - Returns the type source info for the type @@ -2994,11 +2923,8 @@ public: class CStyleCastExpr final : public ExplicitCastExpr, private llvm::TrailingObjects<CStyleCastExpr, CXXBaseSpecifier *> { - // the location of the left paren - SourceLocation LPLoc; - - // the location of the right paren - SourceLocation RPLoc; + SourceLocation LPLoc; // the location of the left paren + SourceLocation RPLoc; // the location of the right paren CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op, unsigned PathSize, TypeSourceInfo *writtenTy, @@ -3008,12 +2934,9 @@ class CStyleCastExpr final /// \brief Construct an empty C-style explicit cast. explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize) - : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) {} + : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { } public: - friend class CastExpr; - friend TrailingObjects; - static CStyleCastExpr *Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *BasePath, @@ -3030,7 +2953,6 @@ public: void setRParenLoc(SourceLocation L) { RPLoc = L; } SourceLocation getLocStart() const LLVM_READONLY { return LPLoc; } - SourceLocation getLocEnd() const LLVM_READONLY { return getSubExpr()->getLocEnd(); } @@ -3038,6 +2960,9 @@ public: static bool classof(const Stmt *T) { return T->getStmtClass() == CStyleCastExprClass; } + + friend TrailingObjects; + friend class CastExpr; }; /// \brief A builtin binary operation expression such as "x + y" or "x <= y". @@ -3060,7 +2985,7 @@ public: /// be used to express the computation. class BinaryOperator : public Expr { public: - using Opcode = BinaryOperatorKind; + typedef BinaryOperatorKind Opcode; private: unsigned Opc : 6; @@ -3068,13 +2993,12 @@ private: // This is only meaningful for operations on floating point types and 0 // otherwise. unsigned FPFeatures : 2; - SourceLocation OpLoc; enum { LHS, RHS, END_EXPR }; Stmt* SubExprs[END_EXPR]; - public: + BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptions FPFeatures) @@ -3094,7 +3018,7 @@ public: /// \brief Construct an empty binary operator. explicit BinaryOperator(EmptyShell Empty) - : Expr(BinaryOperatorClass, Empty), Opc(BO_Comma) {} + : Expr(BinaryOperatorClass, Empty), Opc(BO_Comma) { } SourceLocation getExprLoc() const LLVM_READONLY { return OpLoc; } SourceLocation getOperatorLoc() const { return OpLoc; } @@ -3111,7 +3035,6 @@ public: SourceLocation getLocStart() const LLVM_READONLY { return getLHS()->getLocStart(); } - SourceLocation getLocEnd() const LLVM_READONLY { return getRHS()->getLocEnd(); } @@ -3194,7 +3117,6 @@ public: bool isCompoundAssignmentOp() const { return isCompoundAssignmentOp(getOpcode()); } - static Opcode getOpForCompoundAssignment(Opcode Opc) { assert(isCompoundAssignmentOp(Opc)); if (Opc >= BO_AndAssign) @@ -3225,7 +3147,6 @@ public: child_range children() { return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); } - const_child_range children() const { return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR); } @@ -3259,7 +3180,7 @@ protected: } BinaryOperator(StmtClass SC, EmptyShell Empty) - : Expr(SC, Empty), Opc(BO_MulAssign) {} + : Expr(SC, Empty), Opc(BO_MulAssign) { } }; /// CompoundAssignOperator - For compound assignments (e.g. +=), we keep @@ -3271,7 +3192,6 @@ protected: class CompoundAssignOperator : public BinaryOperator { QualType ComputationLHSType; QualType ComputationResultType; - public: CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResType, ExprValueKind VK, ExprObjectKind OK, @@ -3287,7 +3207,7 @@ public: /// \brief Build an empty compound assignment operator expression. explicit CompoundAssignOperator(EmptyShell Empty) - : BinaryOperator(CompoundAssignOperatorClass, Empty) {} + : BinaryOperator(CompoundAssignOperatorClass, Empty) { } // The two computation types are the type the LHS is converted // to for the computation and the type of the result; the two are @@ -3306,9 +3226,8 @@ public: /// AbstractConditionalOperator - An abstract base class for /// ConditionalOperator and BinaryConditionalOperator. class AbstractConditionalOperator : public Expr { - friend class ASTStmtReader; - SourceLocation QuestionLoc, ColonLoc; + friend class ASTStmtReader; protected: AbstractConditionalOperator(StmtClass SC, QualType T, @@ -3321,7 +3240,7 @@ protected: QuestionLoc(qloc), ColonLoc(cloc) {} AbstractConditionalOperator(StmtClass SC, EmptyShell Empty) - : Expr(SC, Empty) {} + : Expr(SC, Empty) { } public: // getCond - Return the expression representing the condition for @@ -3349,13 +3268,10 @@ public: /// ConditionalOperator - The ?: ternary operator. The GNU "missing /// middle" extension is a BinaryConditionalOperator. class ConditionalOperator : public AbstractConditionalOperator { - friend class ASTStmtReader; - enum { COND, LHS, RHS, END_EXPR }; + Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. - // Left/Middle/Right hand sides. - Stmt* SubExprs[END_EXPR]; - + friend class ASTStmtReader; public: ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs, SourceLocation CLoc, Expr *rhs, @@ -3381,7 +3297,7 @@ public: /// \brief Build an empty conditional operator. explicit ConditionalOperator(EmptyShell Empty) - : AbstractConditionalOperator(ConditionalOperatorClass, Empty) {} + : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { } // getCond - Return the expression representing the condition for // the ?: operator. @@ -3402,7 +3318,6 @@ public: SourceLocation getLocStart() const LLVM_READONLY { return getCond()->getLocStart(); } - SourceLocation getLocEnd() const LLVM_READONLY { return getRHS()->getLocEnd(); } @@ -3415,7 +3330,6 @@ public: child_range children() { return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); } - const_child_range children() const { return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR); } @@ -3427,8 +3341,6 @@ public: /// This is a different expression kind on the assumption that almost /// every client ends up needing to know that these are different. class BinaryConditionalOperator : public AbstractConditionalOperator { - friend class ASTStmtReader; - enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS }; /// - the common condition/left-hand-side expression, which will be @@ -3439,6 +3351,7 @@ class BinaryConditionalOperator : public Stmt *SubExprs[NUM_SUBEXPRS]; OpaqueValueExpr *OpaqueValue; + friend class ASTStmtReader; public: BinaryConditionalOperator(Expr *common, OpaqueValueExpr *opaqueValue, Expr *cond, Expr *lhs, Expr *rhs, @@ -3462,7 +3375,7 @@ public: /// \brief Build an empty conditional operator. explicit BinaryConditionalOperator(EmptyShell Empty) - : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) {} + : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { } /// \brief getCommon - Return the common expression, written to the /// left of the condition. The opaque value will be bound to the @@ -3493,7 +3406,6 @@ public: SourceLocation getLocStart() const LLVM_READONLY { return getCommon()->getLocStart(); } - SourceLocation getLocEnd() const LLVM_READONLY { return getFalseExpr()->getLocEnd(); } @@ -3506,7 +3418,6 @@ public: child_range children() { return child_range(SubExprs, SubExprs + NUM_SUBEXPRS); } - const_child_range children() const { return const_child_range(SubExprs, SubExprs + NUM_SUBEXPRS); } @@ -3534,7 +3445,6 @@ inline Expr *AbstractConditionalOperator class AddrLabelExpr : public Expr { SourceLocation AmpAmpLoc, LabelLoc; LabelDecl *Label; - public: AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelDecl *L, QualType t) @@ -3543,7 +3453,8 @@ public: AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {} /// \brief Build an empty address of a label expression. - explicit AddrLabelExpr(EmptyShell Empty) : Expr(AddrLabelExprClass, Empty) {} + explicit AddrLabelExpr(EmptyShell Empty) + : Expr(AddrLabelExprClass, Empty) { } SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; } void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; } @@ -3564,7 +3475,6 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } - const_child_range children() const { return const_child_range(const_child_iterator(), const_child_iterator()); } @@ -3579,19 +3489,18 @@ public: class StmtExpr : public Expr { Stmt *SubStmt; SourceLocation LParenLoc, RParenLoc; - public: // FIXME: Does type-dependence need to be computed differently? // FIXME: Do we need to compute instantiation instantiation-dependence for // statements? (ugh!) StmtExpr(CompoundStmt *substmt, QualType T, - SourceLocation lp, SourceLocation rp) - : Expr(StmtExprClass, T, VK_RValue, OK_Ordinary, - T->isDependentType(), false, false, false), - SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) {} + SourceLocation lp, SourceLocation rp) : + Expr(StmtExprClass, T, VK_RValue, OK_Ordinary, + T->isDependentType(), false, false, false), + SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { } /// \brief Build an empty statement expression. - explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) {} + explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { } CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); } const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); } @@ -3611,7 +3520,6 @@ public: // Iterators child_range children() { return child_range(&SubStmt, &SubStmt+1); } - const_child_range children() const { return const_child_range(&SubStmt, &SubStmt + 1); } @@ -3630,7 +3538,7 @@ class ShuffleVectorExpr : public Expr { // function. The first two are vectors, and the rest are constant // indices. The number of values in this list is always // 2+the number of indices in the vector type. - Stmt **SubExprs = nullptr; + Stmt **SubExprs; unsigned NumExprs; public: @@ -3639,7 +3547,7 @@ public: /// \brief Build an empty vector-shuffle expression. explicit ShuffleVectorExpr(EmptyShell Empty) - : Expr(ShuffleVectorExprClass, Empty) {} + : Expr(ShuffleVectorExprClass, Empty), SubExprs(nullptr) { } SourceLocation getBuiltinLoc() const { return BuiltinLoc; } void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } @@ -3683,7 +3591,6 @@ public: child_range children() { return child_range(&SubExprs[0], &SubExprs[0]+NumExprs); } - const_child_range children() const { return const_child_range(&SubExprs[0], &SubExprs[0] + NumExprs); } @@ -3694,13 +3601,12 @@ public: /// vector type of the same arity. class ConvertVectorExpr : public Expr { private: - friend class ASTReader; - friend class ASTStmtReader; - Stmt *SrcExpr; TypeSourceInfo *TInfo; SourceLocation BuiltinLoc, RParenLoc; + friend class ASTReader; + friend class ASTStmtReader; explicit ConvertVectorExpr(EmptyShell Empty) : Expr(ConvertVectorExprClass, Empty) {} public: @@ -3742,7 +3648,6 @@ public: // Iterators child_range children() { return child_range(&SrcExpr, &SrcExpr+1); } - const_child_range children() const { return const_child_range(&SrcExpr, &SrcExpr + 1); } @@ -3759,11 +3664,9 @@ public: /// sub-expression. class ChooseExpr : public Expr { enum { COND, LHS, RHS, END_EXPR }; - Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. SourceLocation BuiltinLoc, RParenLoc; bool CondIsTrue; - public: ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t, ExprValueKind VK, ExprObjectKind OK, @@ -3783,7 +3686,7 @@ public: } /// \brief Build an empty __builtin_choose_expr. - explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) {} + explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { } /// isConditionTrue - Return whether the condition is true (i.e. not /// equal to zero). @@ -3828,7 +3731,6 @@ public: child_range children() { return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); } - const_child_range children() const { return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR); } @@ -3846,12 +3748,12 @@ class GNUNullExpr : public Expr { public: GNUNullExpr(QualType Ty, SourceLocation Loc) - : Expr(GNUNullExprClass, Ty, VK_RValue, OK_Ordinary, false, false, false, - false), - TokenLoc(Loc) {} + : Expr(GNUNullExprClass, Ty, VK_RValue, OK_Ordinary, false, false, false, + false), + TokenLoc(Loc) { } /// \brief Build an empty GNU __null expression. - explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) {} + explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { } /// getTokenLocation - The location of the __null token. SourceLocation getTokenLocation() const { return TokenLoc; } @@ -3868,7 +3770,6 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } - const_child_range children() const { return const_child_range(const_child_iterator(), const_child_iterator()); } @@ -3876,10 +3777,9 @@ public: /// Represents a call to the builtin function \c __builtin_va_arg. class VAArgExpr : public Expr { - Stmt *Val = nullptr; + Stmt *Val; llvm::PointerIntPair<TypeSourceInfo *, 1, bool> TInfo; SourceLocation BuiltinLoc, RParenLoc; - public: VAArgExpr(SourceLocation BLoc, Expr *e, TypeSourceInfo *TInfo, SourceLocation RPLoc, QualType t, bool IsMS) @@ -3892,7 +3792,7 @@ public: /// Create an empty __builtin_va_arg expression. explicit VAArgExpr(EmptyShell Empty) - : Expr(VAArgExprClass, Empty), TInfo(nullptr, false) {} + : Expr(VAArgExprClass, Empty), Val(nullptr), TInfo(nullptr, false) {} const Expr *getSubExpr() const { return cast<Expr>(Val); } Expr *getSubExpr() { return cast<Expr>(Val); } @@ -3920,7 +3820,6 @@ public: // Iterators child_range children() { return child_range(&Val, &Val+1); } - const_child_range children() const { return const_child_range(&Val, &Val + 1); } @@ -3973,8 +3872,7 @@ public: /// semantic initializer list also serves as its syntactic form. class InitListExpr : public Expr { // FIXME: Eliminate this vector in favor of ASTContext allocation - using InitExprsTy = ASTVector<Stmt *>; - + typedef ASTVector<Stmt *> InitExprsTy; InitExprsTy InitExprs; SourceLocation LBraceLoc, RBraceLoc; @@ -3995,15 +3893,12 @@ class InitListExpr : public Expr { llvm::PointerUnion<Expr *, FieldDecl *> ArrayFillerOrUnionFieldInit; public: - friend class ASTStmtReader; - friend class ASTStmtWriter; - InitListExpr(const ASTContext &C, SourceLocation lbraceloc, ArrayRef<Expr*> initExprs, SourceLocation rbraceloc); /// \brief Build an empty initializer list. explicit InitListExpr(EmptyShell Empty) - : Expr(InitListExprClass, Empty), AltForm(nullptr, true) {} + : Expr(InitListExprClass, Empty), AltForm(nullptr, true) { } unsigned getNumInits() const { return InitExprs.size(); } @@ -4126,15 +4021,12 @@ public: void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; } bool isSemanticForm() const { return AltForm.getInt(); } - InitListExpr *getSemanticForm() const { return isSemanticForm() ? nullptr : AltForm.getPointer(); } - bool isSyntacticForm() const { return !AltForm.getInt() || !AltForm.getPointer(); } - InitListExpr *getSyntacticForm() const { return isSemanticForm() ? AltForm.getPointer() : nullptr; } @@ -4149,7 +4041,6 @@ public: bool hadArrayRangeDesignator() const { return InitListExprBits.HadArrayRangeDesignator != 0; } - void sawArrayRangeDesignator(bool ARD = true) { InitListExprBits.HadArrayRangeDesignator = ARD; } @@ -4175,10 +4066,10 @@ public: return const_child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size()); } - using iterator = InitExprsTy::iterator; - using const_iterator = InitExprsTy::const_iterator; - using reverse_iterator = InitExprsTy::reverse_iterator; - using const_reverse_iterator = InitExprsTy::const_reverse_iterator; + typedef InitExprsTy::iterator iterator; + typedef InitExprsTy::const_iterator const_iterator; + typedef InitExprsTy::reverse_iterator reverse_iterator; + typedef InitExprsTy::const_reverse_iterator const_reverse_iterator; iterator begin() { return InitExprs.begin(); } const_iterator begin() const { return InitExprs.begin(); } @@ -4188,6 +4079,9 @@ public: const_reverse_iterator rbegin() const { return InitExprs.rbegin(); } reverse_iterator rend() { return InitExprs.rend(); } const_reverse_iterator rend() const { return InitExprs.rend(); } + + friend class ASTStmtReader; + friend class ASTStmtWriter; }; /// @brief Represents a C99 designated initializer expression. @@ -4236,7 +4130,7 @@ private: /// \brief The designators in this designated initialization /// expression. - Designator *Designators = nullptr; + Designator *Designators; DesignatedInitExpr(const ASTContext &C, QualType Ty, llvm::ArrayRef<Designator> Designators, @@ -4244,12 +4138,10 @@ private: ArrayRef<Expr *> IndexExprs, Expr *Init); explicit DesignatedInitExpr(unsigned NumSubExprs) - : Expr(DesignatedInitExprClass, EmptyShell()), - NumDesignators(0), NumSubExprs(NumSubExprs) {} + : Expr(DesignatedInitExprClass, EmptyShell()), + NumDesignators(0), NumSubExprs(NumSubExprs), Designators(nullptr) { } public: - friend TrailingObjects; - /// A field designator, e.g., ".x". struct FieldDesignator { /// Refers to the field that is being initialized. The low bit @@ -4272,14 +4164,11 @@ public: /// Location of the first index expression within the designated /// initializer expression's list of subexpressions. unsigned Index; - /// The location of the '[' starting the array range designator. unsigned LBracketLoc; - /// The location of the ellipsis separating the start and end /// indices. Only valid for GNU array-range designators. unsigned EllipsisLoc; - /// The location of the ']' terminating the array range designator. unsigned RBracketLoc; }; @@ -4291,8 +4180,6 @@ public: /// keep us from reusing it. Try harder, later, to rectify these /// differences. class Designator { - friend class DesignatedInitExpr; - /// @brief The kind of designator this describes. enum { FieldDesignator, @@ -4303,13 +4190,13 @@ public: union { /// A field designator, e.g., ".x". struct FieldDesignator Field; - /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". struct ArrayOrRangeDesignator ArrayOrRange; }; + friend class DesignatedInitExpr; public: - Designator() = default; + Designator() {} /// @brief Initializes a field designator. Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc, @@ -4399,11 +4286,9 @@ public: else return getLBracketLoc(); } - SourceLocation getLocEnd() const LLVM_READONLY { return Kind == FieldDesignator ? getFieldLoc() : getRBracketLoc(); } - SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(getLocStart(), getLocEnd()); } @@ -4496,11 +4381,12 @@ public: Stmt **begin = getTrailingObjects<Stmt *>(); return child_range(begin, begin + NumSubExprs); } - const_child_range children() const { Stmt * const *begin = getTrailingObjects<Stmt *>(); return const_child_range(begin, begin + NumSubExprs); } + + friend TrailingObjects; }; /// \brief Represents a place-holder for an object not to be initialized by @@ -4515,10 +4401,11 @@ public: class NoInitExpr : public Expr { public: explicit NoInitExpr(QualType ty) - : Expr(NoInitExprClass, ty, VK_RValue, OK_Ordinary, - false, false, ty->isInstantiationDependentType(), false) {} + : Expr(NoInitExprClass, ty, VK_RValue, OK_Ordinary, + false, false, ty->isInstantiationDependentType(), false) { } - explicit NoInitExpr(EmptyShell Empty) : Expr(NoInitExprClass, Empty) {} + explicit NoInitExpr(EmptyShell Empty) + : Expr(NoInitExprClass, Empty) { } static bool classof(const Stmt *T) { return T->getStmtClass() == NoInitExprClass; @@ -4531,7 +4418,6 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } - const_child_range children() const { return const_child_range(const_child_iterator(), const_child_iterator()); } @@ -4558,7 +4444,7 @@ public: Expr *baseExprs, SourceLocation rBraceLoc); explicit DesignatedInitUpdateExpr(EmptyShell Empty) - : Expr(DesignatedInitUpdateExprClass, Empty) {} + : Expr(DesignatedInitUpdateExprClass, Empty) { } SourceLocation getLocStart() const LLVM_READONLY; SourceLocation getLocEnd() const LLVM_READONLY; @@ -4573,7 +4459,6 @@ public: InitListExpr *getUpdater() const { return cast<InitListExpr>(BaseAndUpdaterExprs[1]); } - void setUpdater(Expr *Updater) { BaseAndUpdaterExprs[1] = Updater; } // Iterators @@ -4581,7 +4466,6 @@ public: child_range children() { return child_range(&BaseAndUpdaterExprs[0], &BaseAndUpdaterExprs[0] + 2); } - const_child_range children() const { return const_child_range(&BaseAndUpdaterExprs[0], &BaseAndUpdaterExprs[0] + 2); @@ -4611,10 +4495,6 @@ class ArrayInitLoopExpr : public Expr { : Expr(ArrayInitLoopExprClass, Empty), SubExprs{} {} public: - friend class ASTReader; - friend class ASTStmtReader; - friend class ASTStmtWriter; - explicit ArrayInitLoopExpr(QualType T, Expr *CommonInit, Expr *ElementInit) : Expr(ArrayInitLoopExprClass, T, VK_RValue, OK_Ordinary, false, CommonInit->isValueDependent() || ElementInit->isValueDependent(), @@ -4644,7 +4524,6 @@ public: SourceLocation getLocStart() const LLVM_READONLY { return getCommonExpr()->getLocStart(); } - SourceLocation getLocEnd() const LLVM_READONLY { return getCommonExpr()->getLocEnd(); } @@ -4652,10 +4531,13 @@ public: child_range children() { return child_range(SubExprs, SubExprs + 2); } - const_child_range children() const { return const_child_range(SubExprs, SubExprs + 2); } + + friend class ASTReader; + friend class ASTStmtReader; + friend class ASTStmtWriter; }; /// \brief Represents the index of the current element of an array being @@ -4666,9 +4548,6 @@ class ArrayInitIndexExpr : public Expr { : Expr(ArrayInitIndexExprClass, Empty) {} public: - friend class ASTReader; - friend class ASTStmtReader; - explicit ArrayInitIndexExpr(QualType T) : Expr(ArrayInitIndexExprClass, T, VK_RValue, OK_Ordinary, false, false, false, false) {} @@ -4683,10 +4562,12 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } - const_child_range children() const { return const_child_range(const_child_iterator(), const_child_iterator()); } + + friend class ASTReader; + friend class ASTStmtReader; }; /// \brief Represents an implicitly-generated value initialization of @@ -4700,12 +4581,12 @@ public: class ImplicitValueInitExpr : public Expr { public: explicit ImplicitValueInitExpr(QualType ty) - : Expr(ImplicitValueInitExprClass, ty, VK_RValue, OK_Ordinary, - false, false, ty->isInstantiationDependentType(), false) {} + : Expr(ImplicitValueInitExprClass, ty, VK_RValue, OK_Ordinary, + false, false, ty->isInstantiationDependentType(), false) { } /// \brief Construct an empty implicit value initialization. explicit ImplicitValueInitExpr(EmptyShell Empty) - : Expr(ImplicitValueInitExprClass, Empty) {} + : Expr(ImplicitValueInitExprClass, Empty) { } static bool classof(const Stmt *T) { return T->getStmtClass() == ImplicitValueInitExprClass; @@ -4718,7 +4599,6 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } - const_child_range children() const { return const_child_range(const_child_iterator(), const_child_iterator()); } @@ -4730,14 +4610,11 @@ class ParenListExpr : public Expr { SourceLocation LParenLoc, RParenLoc; public: - friend class ASTStmtReader; - friend class ASTStmtWriter; - ParenListExpr(const ASTContext& C, SourceLocation lparenloc, ArrayRef<Expr*> exprs, SourceLocation rparenloc); /// \brief Build an empty paren list. - explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) {} + explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { } unsigned getNumExprs() const { return NumExprs; } @@ -4771,10 +4648,12 @@ public: child_range children() { return child_range(&Exprs[0], &Exprs[0]+NumExprs); } - const_child_range children() const { return const_child_range(&Exprs[0], &Exprs[0] + NumExprs); } + + friend class ASTStmtReader; + friend class ASTStmtWriter; }; /// \brief Represents a C11 generic selection. @@ -4805,15 +4684,12 @@ public: /// Result-dependent generic associations are both type- and value-dependent. class GenericSelectionExpr : public Expr { enum { CONTROLLING, END_EXPR }; - TypeSourceInfo **AssocTypes; Stmt **SubExprs; unsigned NumAssocs, ResultIndex; SourceLocation GenericLoc, DefaultLoc, RParenLoc; public: - friend class ASTStmtReader; - GenericSelectionExpr(const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr, ArrayRef<TypeSourceInfo*> AssocTypes, @@ -4831,7 +4707,7 @@ public: bool ContainsUnexpandedParameterPack); explicit GenericSelectionExpr(EmptyShell Empty) - : Expr(GenericSelectionExprClass, Empty) {} + : Expr(GenericSelectionExprClass, Empty) { } unsigned getNumAssocs() const { return NumAssocs; } @@ -4842,22 +4718,17 @@ public: const Expr *getAssocExpr(unsigned i) const { return cast<Expr>(SubExprs[END_EXPR+i]); } - Expr *getAssocExpr(unsigned i) { return cast<Expr>(SubExprs[END_EXPR+i]); } - ArrayRef<Expr *> getAssocExprs() const { return NumAssocs ? llvm::makeArrayRef( &reinterpret_cast<Expr **>(SubExprs)[END_EXPR], NumAssocs) : None; } - const TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) const { return AssocTypes[i]; } - TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) { return AssocTypes[i]; } - ArrayRef<TypeSourceInfo *> getAssocTypeSourceInfos() const { return NumAssocs ? llvm::makeArrayRef(&AssocTypes[0], NumAssocs) : None; } @@ -4872,7 +4743,6 @@ public: const Expr *getControllingExpr() const { return cast<Expr>(SubExprs[CONTROLLING]); } - Expr *getControllingExpr() { return cast<Expr>(SubExprs[CONTROLLING]); } /// Whether this generic selection is result-dependent. @@ -4901,10 +4771,10 @@ public: child_range children() { return child_range(SubExprs, SubExprs+END_EXPR+NumAssocs); } - const_child_range children() const { return const_child_range(SubExprs, SubExprs + END_EXPR + NumAssocs); } + friend class ASTStmtReader; }; //===----------------------------------------------------------------------===// @@ -4917,11 +4787,11 @@ public: /// /// Note that the base may have either vector or pointer to vector type, just /// like a struct field reference. +/// class ExtVectorElementExpr : public Expr { Stmt *Base; IdentifierInfo *Accessor; SourceLocation AccessorLoc; - public: ExtVectorElementExpr(QualType ty, ExprValueKind VK, Expr *base, IdentifierInfo &accessor, SourceLocation loc) @@ -4934,7 +4804,7 @@ public: /// \brief Build an empty vector element expression. explicit ExtVectorElementExpr(EmptyShell Empty) - : Expr(ExtVectorElementExprClass, Empty) {} + : Expr(ExtVectorElementExprClass, Empty) { } const Expr *getBase() const { return cast<Expr>(Base); } Expr *getBase() { return cast<Expr>(Base); } @@ -4960,7 +4830,6 @@ public: SourceLocation getLocStart() const LLVM_READONLY { return getBase()->getLocStart(); } - SourceLocation getLocEnd() const LLVM_READONLY { return AccessorLoc; } /// isArrow - Return true if the base expression is a pointer to vector, @@ -4973,7 +4842,6 @@ public: // Iterators child_range children() { return child_range(&Base, &Base+1); } - const_child_range children() const { return const_child_range(&Base, &Base + 1); } @@ -4984,7 +4852,6 @@ public: class BlockExpr : public Expr { protected: BlockDecl *TheBlock; - public: BlockExpr(BlockDecl *BD, QualType ty) : Expr(BlockExprClass, ty, VK_RValue, OK_Ordinary, @@ -4994,7 +4861,7 @@ public: TheBlock(BD) {} /// \brief Build an empty block expression. - explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) {} + explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { } const BlockDecl *getBlockDecl() const { return TheBlock; } BlockDecl *getBlockDecl() { return TheBlock; } @@ -5019,7 +4886,6 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } - const_child_range children() const { return const_child_range(const_child_iterator(), const_child_iterator()); } @@ -5030,12 +4896,11 @@ public: /// type of the same size. class AsTypeExpr : public Expr { private: - friend class ASTReader; - friend class ASTStmtReader; - Stmt *SrcExpr; SourceLocation BuiltinLoc, RParenLoc; + friend class ASTReader; + friend class ASTStmtReader; explicit AsTypeExpr(EmptyShell Empty) : Expr(AsTypeExprClass, Empty) {} public: @@ -5069,7 +4934,6 @@ public: // Iterators child_range children() { return child_range(&SrcExpr, &SrcExpr+1); } - const_child_range children() const { return const_child_range(&SrcExpr, &SrcExpr + 1); } @@ -5117,26 +4981,22 @@ class PseudoObjectExpr final // in to Create, which is an index within the semantic forms. // Note also that ASTStmtWriter assumes this encoding. + Expr **getSubExprsBuffer() { return getTrailingObjects<Expr *>(); } + const Expr * const *getSubExprsBuffer() const { + return getTrailingObjects<Expr *>(); + } + PseudoObjectExpr(QualType type, ExprValueKind VK, Expr *syntactic, ArrayRef<Expr*> semantic, unsigned resultIndex); PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs); - Expr **getSubExprsBuffer() { return getTrailingObjects<Expr *>(); } - - const Expr * const *getSubExprsBuffer() const { - return getTrailingObjects<Expr *>(); - } - unsigned getNumSubExprs() const { return PseudoObjectExprBits.NumSubExprs; } public: - friend class ASTStmtReader; - friend TrailingObjects; - /// NoResult - A value for the result index indicating that there is /// no semantic result. enum : unsigned { NoResult = ~0U }; @@ -5173,21 +5033,17 @@ public: unsigned getNumSemanticExprs() const { return getNumSubExprs() - 1; } - using semantics_iterator = Expr * const *; - using const_semantics_iterator = const Expr * const *; - + typedef Expr * const *semantics_iterator; + typedef const Expr * const *const_semantics_iterator; semantics_iterator semantics_begin() { return getSubExprsBuffer() + 1; } - const_semantics_iterator semantics_begin() const { return getSubExprsBuffer() + 1; } - semantics_iterator semantics_end() { return getSubExprsBuffer() + getNumSubExprs(); } - const_semantics_iterator semantics_end() const { return getSubExprsBuffer() + getNumSubExprs(); } @@ -5195,7 +5051,6 @@ public: llvm::iterator_range<semantics_iterator> semantics() { return llvm::make_range(semantics_begin(), semantics_end()); } - llvm::iterator_range<const_semantics_iterator> semantics() const { return llvm::make_range(semantics_begin(), semantics_end()); } @@ -5204,7 +5059,6 @@ public: assert(index + 1 < getNumSubExprs()); return getSubExprsBuffer()[index + 1]; } - const Expr *getSemanticExpr(unsigned index) const { return const_cast<PseudoObjectExpr*>(this)->getSemanticExpr(index); } @@ -5216,7 +5070,6 @@ public: SourceLocation getLocStart() const LLVM_READONLY { return getSyntacticForm()->getLocStart(); } - SourceLocation getLocEnd() const LLVM_READONLY { return getSyntacticForm()->getLocEnd(); } @@ -5227,7 +5080,6 @@ public: return child_range(cast_away_const(CCR.begin()), cast_away_const(CCR.end())); } - const_child_range children() const { Stmt *const *cs = const_cast<Stmt *const *>( reinterpret_cast<const Stmt *const *>(getSubExprsBuffer())); @@ -5237,6 +5089,9 @@ public: static bool classof(const Stmt *T) { return T->getStmtClass() == PseudoObjectExprClass; } + + friend TrailingObjects; + friend class ASTStmtReader; }; /// AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, @@ -5257,18 +5112,16 @@ public: }; private: - friend class ASTStmtReader; - /// \brief Location of sub-expressions. /// The location of Scope sub-expression is NumSubExprs - 1, which is /// not fixed, therefore is not defined in enum. enum { PTR, ORDER, VAL1, ORDER_FAIL, VAL2, WEAK, END_EXPR }; - Stmt *SubExprs[END_EXPR + 1]; unsigned NumSubExprs; SourceLocation BuiltinLoc, RParenLoc; AtomicOp Op; + friend class ASTStmtReader; public: AtomicExpr(SourceLocation BLoc, ArrayRef<Expr*> args, QualType t, AtomicOp op, SourceLocation RP); @@ -5278,52 +5131,44 @@ public: static unsigned getNumSubExprs(AtomicOp Op); /// \brief Build an empty AtomicExpr. - explicit AtomicExpr(EmptyShell Empty) : Expr(AtomicExprClass, Empty) {} + explicit AtomicExpr(EmptyShell Empty) : Expr(AtomicExprClass, Empty) { } Expr *getPtr() const { return cast<Expr>(SubExprs[PTR]); } - Expr *getOrder() const { return cast<Expr>(SubExprs[ORDER]); } - Expr *getScope() const { assert(getScopeModel() && "No scope"); return cast<Expr>(SubExprs[NumSubExprs - 1]); } - Expr *getVal1() const { if (Op == AO__c11_atomic_init || Op == AO__opencl_atomic_init) return cast<Expr>(SubExprs[ORDER]); assert(NumSubExprs > VAL1); return cast<Expr>(SubExprs[VAL1]); } - Expr *getOrderFail() const { assert(NumSubExprs > ORDER_FAIL); return cast<Expr>(SubExprs[ORDER_FAIL]); } - Expr *getVal2() const { if (Op == AO__atomic_exchange) return cast<Expr>(SubExprs[ORDER_FAIL]); assert(NumSubExprs > VAL2); return cast<Expr>(SubExprs[VAL2]); } - Expr *getWeak() const { assert(NumSubExprs > WEAK); return cast<Expr>(SubExprs[WEAK]); } - QualType getValueType() const; AtomicOp getOp() const { return Op; } unsigned getNumSubExprs() const { return NumSubExprs; } Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); } - const Expr * const *getSubExprs() const { return reinterpret_cast<Expr * const *>(SubExprs); } @@ -5360,7 +5205,6 @@ public: child_range children() { return child_range(SubExprs, SubExprs+NumSubExprs); } - const_child_range children() const { return const_child_range(SubExprs, SubExprs + NumSubExprs); } @@ -5400,7 +5244,6 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } - const_child_range children() const { return const_child_range(const_child_iterator(), const_child_iterator()); } @@ -5411,8 +5254,8 @@ public: static bool classof(const Stmt *T) { return T->getStmtClass() == TypoExprClass; } -}; -} // namespace clang +}; +} // end namespace clang #endif // LLVM_CLANG_AST_EXPR_H Modified: cfe/trunk/lib/AST/Expr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=318538&r1=318537&r2=318538&view=diff ============================================================================== --- cfe/trunk/lib/AST/Expr.cpp (original) +++ cfe/trunk/lib/AST/Expr.cpp Fri Nov 17 10:09:48 2017 @@ -1,4 +1,4 @@ -//===- Expr.cpp - Expression AST Node Implementation ----------------------===// +//===--- Expr.cpp - Expression AST Node Implementation --------------------===// // // The LLVM Compiler Infrastructure // @@ -11,62 +11,28 @@ // //===----------------------------------------------------------------------===// -#include "clang/AST/Expr.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Attr.h" -#include "clang/AST/Decl.h" -#include "clang/AST/DeclBase.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/DeclTemplate.h" -#include "clang/AST/DeclarationName.h" #include "clang/AST/EvaluatedExprVisitor.h" +#include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" -#include "clang/AST/ExprObjC.h" -#include "clang/AST/ExprOpenMP.h" #include "clang/AST/Mangle.h" -#include "clang/AST/NestedNameSpecifier.h" -#include "clang/AST/OperationKinds.h" -#include "clang/AST/PrettyPrinter.h" -#include "clang/AST/Stmt.h" -#include "clang/AST/TemplateBase.h" -#include "clang/AST/Type.h" -#include "clang/Basic/AddressSpaces.h" +#include "clang/AST/RecordLayout.h" +#include "clang/AST/StmtVisitor.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/CharInfo.h" -#include "clang/Basic/LLVM.h" -#include "clang/Basic/Lambda.h" -#include "clang/Basic/LangOptions.h" -#include "clang/Basic/OperatorKinds.h" -#include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" -#include "clang/Basic/Specifiers.h" #include "clang/Basic/TargetInfo.h" -#include "clang/Basic/TypeTraits.h" #include "clang/Lex/Lexer.h" #include "clang/Lex/LiteralSupport.h" -#include "clang/Lex/Token.h" -#include "llvm/ADT/APFloat.h" -#include "llvm/ADT/APInt.h" -#include "llvm/ADT/APSInt.h" -#include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/None.h" -#include "llvm/ADT/SmallString.h" -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/StringRef.h" -#include "llvm/Support/Casting.h" -#include "llvm/Support/Compiler.h" +#include "clang/Sema/SemaDiagnostic.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> -#include <cassert> -#include <cstddef> -#include <cstdint> #include <cstring> -#include <memory> -#include <string> -#include <utility> - using namespace clang; const Expr *Expr::getBestDynamicClassTypeExpr() const { @@ -227,23 +193,24 @@ bool Expr::isKnownToHaveBooleanValue() c // a more specific implementation of getExprLoc(). // // See also Stmt.cpp:{getLocStart(),getLocEnd()}. - -/// This implementation is used when a class provides a custom -/// implementation of getExprLoc. -template <class E, class T> -static SourceLocation getExprLocImpl(const Expr *expr, - SourceLocation (T::*v)() const) { - return static_cast<const E*>(expr)->getExprLoc(); -} - -/// This implementation is used when a class doesn't provide -/// a custom implementation of getExprLoc. Overload resolution -/// should pick it over the implementation above because it's -/// more specialized according to function template partial ordering. -template <class E> -static SourceLocation getExprLocImpl(const Expr *expr, - SourceLocation (Expr::*v)() const) { - return static_cast<const E*>(expr)->getLocStart(); +namespace { + /// This implementation is used when a class provides a custom + /// implementation of getExprLoc. + template <class E, class T> + SourceLocation getExprLocImpl(const Expr *expr, + SourceLocation (T::*v)() const) { + return static_cast<const E*>(expr)->getExprLoc(); + } + + /// This implementation is used when a class doesn't provide + /// a custom implementation of getExprLoc. Overload resolution + /// should pick it over the implementation above because it's + /// more specialized according to function template partial ordering. + template <class E> + SourceLocation getExprLocImpl(const Expr *expr, + SourceLocation (Expr::*v)() const) { + return static_cast<const E*>(expr)->getLocStart(); + } } SourceLocation Expr::getExprLoc() const { @@ -485,7 +452,6 @@ SourceLocation DeclRefExpr::getLocStart( return getQualifierLoc().getBeginLoc(); return getNameInfo().getLocStart(); } - SourceLocation DeclRefExpr::getLocEnd() const { if (hasExplicitTemplateArgs()) return getRAngleLoc(); @@ -640,9 +606,8 @@ std::string PredefinedExpr::ComputeName( POut << " &&"; } - using SpecsTy = SmallVector<const ClassTemplateSpecializationDecl *, 8>; + typedef SmallVector<const ClassTemplateSpecializationDecl *, 8> SpecsTy; SpecsTy Specs; - const DeclContext *Ctx = FD->getDeclContext(); while (Ctx && isa<NamedDecl>(Ctx)) { const ClassTemplateSpecializationDecl *Spec @@ -800,7 +765,7 @@ FloatingLiteral::FloatingLiteral(const A } FloatingLiteral::FloatingLiteral(const ASTContext &C, EmptyShell Empty) - : Expr(FloatingLiteralClass, Empty) { + : Expr(FloatingLiteralClass, Empty) { setRawSemantics(IEEEhalf); FloatingLiteralBits.IsExact = false; } @@ -1070,6 +1035,7 @@ void StringLiteral::setString(const ASTC /// Using these two parameters can reduce the time complexity from O(n^2) to /// O(n) if one wants to get the location of byte for all the tokens in a /// string. +/// SourceLocation StringLiteral::getLocationOfByte(unsigned ByteNo, const SourceManager &SM, const LangOptions &Features, @@ -1088,7 +1054,7 @@ StringLiteral::getLocationOfByte(unsigne StringOffset = *StartTokenByteOffset; ByteNo -= StringOffset; } - while (true) { + while (1) { assert(TokNo < getNumConcatenated() && "Invalid byte number!"); SourceLocation StrTokLoc = getStrTokenLoc(TokNo); @@ -1143,6 +1109,8 @@ StringLiteral::getLocationOfByte(unsigne } } + + /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it /// corresponds to, e.g. "sizeof" or "[pre]++". StringRef UnaryOperator::getOpcodeStr(Opcode Op) { @@ -1184,6 +1152,7 @@ OverloadedOperatorKind UnaryOperator::ge } } + //===----------------------------------------------------------------------===// // Postfix Operators. //===----------------------------------------------------------------------===// @@ -1195,6 +1164,7 @@ CallExpr::CallExpr(const ASTContext &C, fn->isValueDependent(), fn->isInstantiationDependent(), fn->containsUnexpandedParameterPack()), NumArgs(args.size()) { + unsigned NumPreArgs = preargs.size(); SubExprs = new (C) Stmt *[args.size()+PREARGS_START+NumPreArgs]; SubExprs[FN] = fn; @@ -1218,15 +1188,15 @@ CallExpr::CallExpr(const ASTContext &C, CallExpr::CallExpr(const ASTContext &C, Expr *fn, ArrayRef<Expr *> args, QualType t, ExprValueKind VK, SourceLocation rparenloc) - : CallExpr(C, CallExprClass, fn, ArrayRef<Expr *>(), args, t, VK, - rparenloc) {} + : CallExpr(C, CallExprClass, fn, ArrayRef<Expr *>(), args, t, VK, rparenloc) { +} CallExpr::CallExpr(const ASTContext &C, StmtClass SC, EmptyShell Empty) : CallExpr(C, SC, /*NumPreArgs=*/0, Empty) {} CallExpr::CallExpr(const ASTContext &C, StmtClass SC, unsigned NumPreArgs, EmptyShell Empty) - : Expr(SC, Empty) { + : Expr(SC, Empty), SubExprs(nullptr), NumArgs(0) { // FIXME: Why do we allocate this? SubExprs = new (C) Stmt*[PREARGS_START+NumPreArgs](); CallExprBits.NumPreArgs = NumPreArgs; @@ -1362,7 +1332,6 @@ SourceLocation CallExpr::getLocStart() c begin = getArg(0)->getLocStart(); return begin; } - SourceLocation CallExpr::getLocEnd() const { if (isa<CXXOperatorCallExpr>(this)) return cast<CXXOperatorCallExpr>(this)->getLocEnd(); @@ -1424,7 +1393,7 @@ IdentifierInfo *OffsetOfNode::getFieldNa if (getKind() == Field) return getField()->getIdentifier(); - return reinterpret_cast<IdentifierInfo *>(Data & ~(uintptr_t)Mask); + return reinterpret_cast<IdentifierInfo *> (Data & ~(uintptr_t)Mask); } UnaryExprOrTypeTraitExpr::UnaryExprOrTypeTraitExpr( @@ -1471,6 +1440,7 @@ MemberExpr *MemberExpr::Create( ValueDecl *memberdecl, DeclAccessPair founddecl, DeclarationNameInfo nameinfo, const TemplateArgumentListInfo *targs, QualType ty, ExprValueKind vk, ExprObjectKind ok) { + bool hasQualOrFound = (QualifierLoc || founddecl.getDecl() != memberdecl || founddecl.getAccess() != memberdecl->getAccess()); @@ -1538,7 +1508,6 @@ SourceLocation MemberExpr::getLocStart() return BaseStartLoc; return MemberLoc; } - SourceLocation MemberExpr::getLocEnd() const { SourceLocation EndLoc = getMemberNameInfo().getEndLoc(); if (hasExplicitTemplateArgs()) @@ -1672,17 +1641,19 @@ const char *CastExpr::getCastKindName() llvm_unreachable("Unhandled cast kind!"); } -static Expr *skipImplicitTemporary(Expr *expr) { - // Skip through reference binding to temporary. - if (MaterializeTemporaryExpr *Materialize - = dyn_cast<MaterializeTemporaryExpr>(expr)) - expr = Materialize->GetTemporaryExpr(); - - // Skip any temporary bindings; they're implicit. - if (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(expr)) - expr = Binder->getSubExpr(); +namespace { + Expr *skipImplicitTemporary(Expr *expr) { + // Skip through reference binding to temporary. + if (MaterializeTemporaryExpr *Materialize + = dyn_cast<MaterializeTemporaryExpr>(expr)) + expr = Materialize->GetTemporaryExpr(); - return expr; + // Skip any temporary bindings; they're implicit. + if (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(expr)) + expr = Binder->getSubExpr(); + + return expr; + } } Expr *CastExpr::getSubExprAsWritten() { @@ -1890,13 +1861,13 @@ bool BinaryOperator::isNullPointerArithm return true; } - InitListExpr::InitListExpr(const ASTContext &C, SourceLocation lbraceloc, ArrayRef<Expr*> initExprs, SourceLocation rbraceloc) - : Expr(InitListExprClass, QualType(), VK_RValue, OK_Ordinary, false, false, - false, false), - InitExprs(C, initExprs.size()), - LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), AltForm(nullptr, true) { + : Expr(InitListExprClass, QualType(), VK_RValue, OK_Ordinary, false, false, + false, false), + InitExprs(C, initExprs.size()), + LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), AltForm(nullptr, true) +{ sawArrayRangeDesignator(false); for (unsigned I = 0; I != initExprs.size(); ++I) { if (initExprs[I]->isTypeDependent()) @@ -2028,6 +1999,7 @@ SourceLocation InitListExpr::getLocEnd() } /// getFunctionType - Return the underlying function type for this block. +/// const FunctionProtoType *BlockExpr::getFunctionType() const { // The block pointer is never sugared, but the function type might be. return cast<BlockPointerType>(getType()) @@ -2037,15 +2009,14 @@ const FunctionProtoType *BlockExpr::getF SourceLocation BlockExpr::getCaretLocation() const { return TheBlock->getCaretLocation(); } - const Stmt *BlockExpr::getBody() const { return TheBlock->getBody(); } - Stmt *BlockExpr::getBody() { return TheBlock->getBody(); } + //===----------------------------------------------------------------------===// // Generic Expression Routines //===----------------------------------------------------------------------===// @@ -2240,7 +2211,7 @@ bool Expr::isUnusedResultAWarning(const return false; case CXXTemporaryObjectExprClass: - case CXXConstructExprClass: + case CXXConstructExprClass: { if (const CXXRecordDecl *Type = getType()->getAsCXXRecordDecl()) { if (Type->hasAttr<WarnUnusedAttr>()) { WarnE = this; @@ -2250,6 +2221,7 @@ bool Expr::isUnusedResultAWarning(const } } return false; + } case ObjCMessageExprClass: { const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(this); @@ -2922,6 +2894,7 @@ bool Expr::isConstantInitializer(ASTCont case MaterializeTemporaryExprClass: return cast<MaterializeTemporaryExpr>(this)->GetTemporaryExpr() ->isConstantInitializer(Ctx, false, Culprit); + case SubstNonTypeTemplateParmExprClass: return cast<SubstNonTypeTemplateParmExpr>(this)->getReplacement() ->isConstantInitializer(Ctx, false, Culprit); @@ -2943,17 +2916,16 @@ bool Expr::isConstantInitializer(ASTCont } namespace { - /// \brief Look for any side effects within a Stmt. class SideEffectFinder : public ConstEvaluatedExprVisitor<SideEffectFinder> { - using Inherited = ConstEvaluatedExprVisitor<SideEffectFinder>; - + typedef ConstEvaluatedExprVisitor<SideEffectFinder> Inherited; const bool IncludePossibleEffects; - bool HasSideEffects = false; + bool HasSideEffects; public: explicit SideEffectFinder(const ASTContext &Context, bool IncludePossible) - : Inherited(Context), IncludePossibleEffects(IncludePossible) {} + : Inherited(Context), + IncludePossibleEffects(IncludePossible), HasSideEffects(false) { } bool hasSideEffects() const { return HasSideEffects; } @@ -2963,8 +2935,7 @@ namespace { HasSideEffects = true; } }; - -} // namespace +} bool Expr::HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects) const { @@ -3240,17 +3211,16 @@ bool Expr::HasSideEffects(const ASTConte } namespace { - /// \brief Look for a call to a non-trivial function within an expression. - class NonTrivialCallFinder - : public ConstEvaluatedExprVisitor<NonTrivialCallFinder> { - using Inherited = ConstEvaluatedExprVisitor<NonTrivialCallFinder>; + class NonTrivialCallFinder : public ConstEvaluatedExprVisitor<NonTrivialCallFinder> + { + typedef ConstEvaluatedExprVisitor<NonTrivialCallFinder> Inherited; - bool NonTrivial = false; + bool NonTrivial; public: explicit NonTrivialCallFinder(const ASTContext &Context) - : Inherited(Context) {} + : Inherited(Context), NonTrivial(false) { } bool hasNonTrivialCall() const { return NonTrivial; } @@ -3286,8 +3256,7 @@ namespace { NonTrivial = true; } }; - -} // namespace +} bool Expr::hasNonTrivialCall(const ASTContext &Ctx) const { NonTrivialCallFinder Finder(Ctx); @@ -3313,6 +3282,7 @@ Expr::isNullPointerConstant(ASTContext & return NPCK_ZeroExpression; else return NPCK_NotNull; + case NPC_ValueDependentIsNotNull: return NPCK_NotNull; } @@ -3610,11 +3580,12 @@ void ExtVectorElementExpr::getEncodedEle ShuffleVectorExpr::ShuffleVectorExpr(const ASTContext &C, ArrayRef<Expr*> args, QualType Type, SourceLocation BLoc, SourceLocation RP) - : Expr(ShuffleVectorExprClass, Type, VK_RValue, OK_Ordinary, - Type->isDependentType(), Type->isDependentType(), - Type->isInstantiationDependentType(), - Type->containsUnexpandedParameterPack()), - BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(args.size()) { + : Expr(ShuffleVectorExprClass, Type, VK_RValue, OK_Ordinary, + Type->isDependentType(), Type->isDependentType(), + Type->isInstantiationDependentType(), + Type->containsUnexpandedParameterPack()), + BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(args.size()) +{ SubExprs = new (C) Stmt*[args.size()]; for (unsigned i = 0; i != args.size(); i++) { if (args[i]->isTypeDependent()) @@ -3935,7 +3906,7 @@ PseudoObjectExpr *PseudoObjectExpr::Crea ArrayRef<Expr*> semantics, unsigned resultIndex) { assert(syntax && "no syntactic expression!"); - assert(!semantics.empty() && "no semantic expressions!"); + assert(semantics.size() && "no semantic expressions!"); QualType type; ExprValueKind VK; @@ -4009,9 +3980,10 @@ Stmt::const_child_range UnaryExprOrTypeT AtomicExpr::AtomicExpr(SourceLocation BLoc, ArrayRef<Expr*> args, QualType t, AtomicOp op, SourceLocation RP) - : Expr(AtomicExprClass, t, VK_RValue, OK_Ordinary, - false, false, false, false), - NumSubExprs(args.size()), BuiltinLoc(BLoc), RParenLoc(RP), Op(op) { + : Expr(AtomicExprClass, t, VK_RValue, OK_Ordinary, + false, false, false, false), + NumSubExprs(args.size()), BuiltinLoc(BLoc), RParenLoc(RP), Op(op) +{ assert(args.size() == getNumSubExprs(op) && "wrong number of subexpressions"); for (unsigned i = 0; i != args.size(); i++) { if (args[i]->isTypeDependent()) @@ -4114,7 +4086,7 @@ QualType OMPArraySectionExpr::getBaseOri if (OriginalTy->isAnyPointerType()) OriginalTy = OriginalTy->getPointeeType(); else { - assert(OriginalTy->isArrayType()); + assert (OriginalTy->isArrayType()); OriginalTy = OriginalTy->castAsArrayTypeUnsafe()->getElementType(); } } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits