Author: eugenezelenko Date: Mon Nov 13 15:01:27 2017 New Revision: 318101 URL: http://llvm.org/viewvc/llvm-project?rev=318101&view=rev Log: [AST] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
Modified: cfe/trunk/include/clang/AST/Decl.h cfe/trunk/lib/AST/Decl.cpp Modified: cfe/trunk/include/clang/AST/Decl.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=318101&r1=318100&r2=318101&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/Decl.h (original) +++ cfe/trunk/include/clang/AST/Decl.h Mon Nov 13 15:01:27 2017 @@ -1,4 +1,4 @@ -//===--- Decl.h - Classes for representing declarations ---------*- C++ -*-===// +//===- Decl.h - Classes for representing declarations -----------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -18,33 +18,58 @@ #include "clang/AST/DeclBase.h" #include "clang/AST/DeclarationName.h" #include "clang/AST/ExternalASTSource.h" +#include "clang/AST/NestedNameSpecifier.h" #include "clang/AST/Redeclarable.h" #include "clang/AST/Type.h" +#include "clang/Basic/AddressSpaces.h" +#include "clang/Basic/Diagnostic.h" +#include "clang/Basic/IdentifierTable.h" +#include "clang/Basic/LLVM.h" #include "clang/Basic/Linkage.h" -#include "clang/Basic/Module.h" #include "clang/Basic/OperatorKinds.h" +#include "clang/Basic/PartialDiagnostic.h" #include "clang/Basic/PragmaKinds.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Basic/Specifiers.h" +#include "clang/Basic/Visibility.h" +#include "llvm/ADT/APSInt.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/Optional.h" +#include "llvm/ADT/PointerIntPair.h" +#include "llvm/ADT/PointerUnion.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/iterator_range.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/Compiler.h" -#include "llvm/Support/raw_ostream.h" #include "llvm/Support/TrailingObjects.h" +#include <cassert> +#include <cstddef> +#include <cstdint> +#include <string> +#include <utility> namespace clang { + +class ASTContext; struct ASTTemplateArgumentListInfo; -class CXXTemporary; +class Attr; class CompoundStmt; class DependentFunctionTemplateSpecializationInfo; +class EnumDecl; class Expr; class FunctionTemplateDecl; class FunctionTemplateSpecializationInfo; class LabelStmt; class MemberSpecializationInfo; -class NestedNameSpecifier; +class Module; +class NamespaceDecl; class ParmVarDecl; +class RecordDecl; class Stmt; class StringLiteral; +class TagDecl; class TemplateArgumentList; +class TemplateArgumentListInfo; class TemplateParameterList; class TypeAliasTemplateDecl; class TypeLoc; @@ -58,13 +83,15 @@ class VarTemplateDecl; /// TypeLoc TL = TypeSourceInfo->getTypeLoc(); /// TL.getStartLoc().print(OS, SrcMgr); /// @endcode -/// class TypeSourceInfo { - QualType Ty; // Contains a memory block after the class, used for type source information, // allocated by ASTContext. friend class ASTContext; - TypeSourceInfo(QualType ty) : Ty(ty) { } + + QualType Ty; + + TypeSourceInfo(QualType ty) : Ty(ty) {} + public: /// \brief Return the type wrapped by this type source info. QualType getType() const { return Ty; } @@ -78,14 +105,16 @@ public: /// TranslationUnitDecl - The top declaration context. class TranslationUnitDecl : public Decl, public DeclContext { - virtual void anchor(); ASTContext &Ctx; /// The (most recently entered) anonymous namespace for this /// translation unit, if one has been created. - NamespaceDecl *AnonymousNamespace; + NamespaceDecl *AnonymousNamespace = nullptr; explicit TranslationUnitDecl(ASTContext &ctx); + + virtual void anchor(); + public: ASTContext &getASTContext() const { return Ctx; } @@ -93,6 +122,7 @@ public: void setAnonymousNamespace(NamespaceDecl *D) { AnonymousNamespace = D; } static TranslationUnitDecl *Create(ASTContext &C); + // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classofKind(Kind K) { return K == TranslationUnit; } @@ -109,18 +139,18 @@ public: class PragmaCommentDecl final : public Decl, private llvm::TrailingObjects<PragmaCommentDecl, char> { - virtual void anchor(); - - PragmaMSCommentKind CommentKind; - - friend TrailingObjects; friend class ASTDeclReader; friend class ASTDeclWriter; + friend TrailingObjects; + + PragmaMSCommentKind CommentKind; PragmaCommentDecl(TranslationUnitDecl *TU, SourceLocation CommentLoc, PragmaMSCommentKind CommentKind) : Decl(PragmaComment, TU, CommentLoc), CommentKind(CommentKind) {} + virtual void anchor(); + public: static PragmaCommentDecl *Create(const ASTContext &C, TranslationUnitDecl *DC, SourceLocation CommentLoc, @@ -143,18 +173,18 @@ public: class PragmaDetectMismatchDecl final : public Decl, private llvm::TrailingObjects<PragmaDetectMismatchDecl, char> { - virtual void anchor(); - - size_t ValueStart; - - friend TrailingObjects; friend class ASTDeclReader; friend class ASTDeclWriter; + friend TrailingObjects; + + size_t ValueStart; PragmaDetectMismatchDecl(TranslationUnitDecl *TU, SourceLocation Loc, size_t ValueStart) : Decl(PragmaDetectMismatch, TU, Loc), ValueStart(ValueStart) {} + virtual void anchor(); + public: static PragmaDetectMismatchDecl *Create(const ASTContext &C, TranslationUnitDecl *DC, @@ -189,14 +219,16 @@ public: /// The declaration at #3 finds it is a redeclaration of \c N::f through /// lookup in the extern "C" context. class ExternCContextDecl : public Decl, public DeclContext { - virtual void anchor(); - explicit ExternCContextDecl(TranslationUnitDecl *TU) : Decl(ExternCContext, TU, SourceLocation()), DeclContext(ExternCContext) {} + + virtual void anchor(); + public: static ExternCContextDecl *Create(const ASTContext &C, TranslationUnitDecl *TU); + // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classofKind(Kind K) { return K == ExternCContext; } @@ -211,18 +243,19 @@ public: /// NamedDecl - This represents a decl with a name. Many decls have names such /// as ObjCMethodDecl, but not \@class, etc. class NamedDecl : public Decl { - virtual void anchor(); /// Name - The name of this declaration, which is typically a normal /// identifier but may also be a special kind of name (C++ /// constructor, Objective-C selector, etc.) DeclarationName Name; + virtual void anchor(); + private: NamedDecl *getUnderlyingDeclImpl() LLVM_READONLY; protected: NamedDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N) - : Decl(DK, DC, L), Name(N) { } + : Decl(DK, DC, L), Name(N) {} public: /// getIdentifier - Get the identifier that names this declaration, @@ -425,10 +458,10 @@ inline raw_ostream &operator<<(raw_ostre /// location of the statement. For GNU local labels (__label__), the decl /// location is where the __label__ is. class LabelDecl : public NamedDecl { - void anchor() override; LabelStmt *TheStmt; StringRef MSAsmName; - bool MSAsmNameResolved; + bool MSAsmNameResolved = false; + /// LocStart - For normal labels, this is the same as the main declaration /// label, i.e., the location of the identifier; for GNU local labels, /// this is the location of the __label__ keyword. @@ -436,10 +469,9 @@ class LabelDecl : public NamedDecl { LabelDecl(DeclContext *DC, SourceLocation IdentL, IdentifierInfo *II, LabelStmt *S, SourceLocation StartL) - : NamedDecl(Label, DC, IdentL, II), - TheStmt(S), - MSAsmNameResolved(false), - LocStart(StartL) {} + : NamedDecl(Label, DC, IdentL, II), TheStmt(S), LocStart(StartL) {} + + void anchor() override; public: static LabelDecl *Create(ASTContext &C, DeclContext *DC, @@ -459,7 +491,7 @@ public: return SourceRange(LocStart, getLocation()); } - bool isMSAsmLabel() const { return MSAsmName.size() != 0; } + bool isMSAsmLabel() const { return !MSAsmName.empty(); } bool isResolvedMSAsmLabel() const { return isMSAsmLabel() && MSAsmNameResolved; } void setMSAsmLabel(StringRef Name); StringRef getMSAsmLabel() const { return MSAsmName; } @@ -477,6 +509,7 @@ class NamespaceDecl : public NamedDecl, /// LocStart - The starting location of the source range, pointing /// to either the namespace or the inline keyword. SourceLocation LocStart; + /// RBraceLoc - The ending location of the source range. SourceLocation RBraceLoc; @@ -490,12 +523,16 @@ class NamespaceDecl : public NamedDecl, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, NamespaceDecl *PrevDecl); - typedef Redeclarable<NamespaceDecl> redeclarable_base; + using redeclarable_base = Redeclarable<NamespaceDecl>; + NamespaceDecl *getNextRedeclarationImpl() override; NamespaceDecl *getPreviousDeclImpl() override; NamespaceDecl *getMostRecentDeclImpl() override; public: + friend class ASTDeclReader; + friend class ASTDeclWriter; + static NamespaceDecl *Create(ASTContext &C, DeclContext *DC, bool Inline, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, @@ -503,8 +540,9 @@ public: static NamespaceDecl *CreateDeserialized(ASTContext &C, unsigned ID); - typedef redeclarable_base::redecl_range redecl_range; - typedef redeclarable_base::redecl_iterator redecl_iterator; + using redecl_range = redeclarable_base::redecl_range; + using redecl_iterator = redeclarable_base::redecl_iterator; + using redeclarable_base::redecls_begin; using redeclarable_base::redecls_end; using redeclarable_base::redecls; @@ -582,22 +620,21 @@ public: static NamespaceDecl *castFromDeclContext(const DeclContext *DC) { return static_cast<NamespaceDecl *>(const_cast<DeclContext*>(DC)); } - - friend class ASTDeclReader; - friend class ASTDeclWriter; }; /// ValueDecl - Represent the declaration of a variable (in which case it is /// an lvalue) a function (in which case it is a function designator) or /// an enum constant. class ValueDecl : public NamedDecl { - void anchor() override; QualType DeclType; + void anchor() override; + protected: ValueDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N, QualType T) : NamedDecl(DK, DC, L, N), DeclType(T) {} + public: QualType getType() const { return DeclType; } void setType(QualType newType) { DeclType = newType; } @@ -620,28 +657,23 @@ struct QualifierInfo { /// The count includes all of the template parameter lists that were matched /// against the template-ids occurring into the NNS and possibly (in the /// case of an explicit specialization) a final "template <>". - unsigned NumTemplParamLists; + unsigned NumTemplParamLists = 0; /// TemplParamLists - A new-allocated array of size NumTemplParamLists, /// containing pointers to the "outer" template parameter lists. /// It includes all of the template parameter lists that were matched /// against the template-ids occurring into the NNS and possibly (in the /// case of an explicit specialization) a final "template <>". - TemplateParameterList** TemplParamLists; + TemplateParameterList** TemplParamLists = nullptr; - /// Default constructor. - QualifierInfo() - : QualifierLoc(), NumTemplParamLists(0), TemplParamLists(nullptr) {} + QualifierInfo() = default; + QualifierInfo(const QualifierInfo &) = delete; + QualifierInfo& operator=(const QualifierInfo &) = delete; /// setTemplateParameterListsInfo - Sets info about "outer" template /// parameter lists. void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef<TemplateParameterList *> TPLists); - -private: - // Copy constructor and copy assignment are disabled. - QualifierInfo(const QualifierInfo&) = delete; - QualifierInfo& operator=(const QualifierInfo&) = delete; }; /// \brief Represents a ValueDecl that came out of a declarator. @@ -653,7 +685,7 @@ class DeclaratorDecl : public ValueDecl TypeSourceInfo *TInfo; }; - llvm::PointerUnion<TypeSourceInfo*, ExtInfo*> DeclInfo; + llvm::PointerUnion<TypeSourceInfo *, ExtInfo *> DeclInfo; /// InnerLocStart - The start of the source range for this declaration, /// ignoring outer template declarations. @@ -667,15 +699,18 @@ protected: DeclaratorDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N, QualType T, TypeSourceInfo *TInfo, SourceLocation StartL) - : ValueDecl(DK, DC, L, N, T), DeclInfo(TInfo), InnerLocStart(StartL) { - } + : ValueDecl(DK, DC, L, N, T), DeclInfo(TInfo), InnerLocStart(StartL) {} public: + friend class ASTDeclReader; + friend class ASTDeclWriter; + TypeSourceInfo *getTypeSourceInfo() const { return hasExtInfo() ? getExtInfo()->TInfo : DeclInfo.get<TypeSourceInfo*>(); } + void setTypeSourceInfo(TypeSourceInfo *TI) { if (hasExtInfo()) getExtInfo()->TInfo = TI; @@ -693,6 +728,7 @@ public: SourceLocation getOuterLocStart() const; SourceRange getSourceRange() const override LLVM_READONLY; + SourceLocation getLocStart() const LLVM_READONLY { return getOuterLocStart(); } @@ -717,10 +753,12 @@ public: unsigned getNumTemplateParameterLists() const { return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0; } + TemplateParameterList *getTemplateParameterList(unsigned index) const { assert(index < getNumTemplateParameterLists()); return getExtInfo()->TemplParamLists[index]; } + void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef<TemplateParameterList *> TPLists); @@ -731,18 +769,12 @@ public: static bool classofKind(Kind K) { return K >= firstDeclarator && K <= lastDeclarator; } - - friend class ASTDeclReader; - friend class ASTDeclWriter; }; /// \brief Structure used to store a statement, the constant value to /// which it was evaluated (if any), and whether or not the statement /// is an integral constant expression (if known). struct EvaluatedStmt { - EvaluatedStmt() : WasEvaluated(false), IsEvaluating(false), CheckedICE(false), - CheckingICE(false), IsICE(false) { } - /// \brief Whether this statement was already evaluated. bool WasEvaluated : 1; @@ -764,32 +796,46 @@ struct EvaluatedStmt { Stmt *Value; APValue Evaluated; + + EvaluatedStmt() : WasEvaluated(false), IsEvaluating(false), CheckedICE(false), + CheckingICE(false), IsICE(false) {} + }; /// VarDecl - An instance of this class is created to represent a variable /// declaration or definition. class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> { public: - /// getStorageClassSpecifierString - Return the string used to - /// specify the storage class \p SC. - /// - /// It is illegal to call this function with SC == None. - static const char *getStorageClassSpecifierString(StorageClass SC); - /// \brief Initialization styles. enum InitializationStyle { - CInit, ///< C-style initialization with assignment - CallInit, ///< Call-style initialization (C++98) - ListInit ///< Direct list-initialization (C++11) + /// C-style initialization with assignment + CInit, + + /// Call-style initialization (C++98) + CallInit, + + /// Direct list-initialization (C++11) + ListInit }; /// \brief Kinds of thread-local storage. enum TLSKind { - TLS_None, ///< Not a TLS variable. - TLS_Static, ///< TLS with a known-constant initializer. - TLS_Dynamic ///< TLS with a dynamic initializer. + /// Not a TLS variable. + TLS_None, + + /// TLS with a known-constant initializer. + TLS_Static, + + /// TLS with a dynamic initializer. + TLS_Dynamic }; + /// getStorageClassSpecifierString - Return the string used to + /// specify the storage class \p SC. + /// + /// It is illegal to call this function with SC == None. + static const char *getStorageClassSpecifierString(StorageClass SC); + protected: // A pointer union of Stmt * and EvaluatedStmt *. When an EvaluatedStmt, we // have allocated the auxiliary struct of information there. @@ -798,16 +844,20 @@ protected: // this as *many* VarDecls are ParmVarDecls that don't have default // arguments. We could save some space by moving this pointer union to be // allocated in trailing space when necessary. - typedef llvm::PointerUnion<Stmt *, EvaluatedStmt *> InitType; + using InitType = llvm::PointerUnion<Stmt *, EvaluatedStmt *>; /// \brief The initializer for this variable or, for a ParmVarDecl, the /// C++ default argument. mutable InitType Init; private: + friend class ASTDeclReader; + friend class ASTNodeImporter; + friend class StmtIteratorBase; + class VarDeclBitfields { - friend class VarDecl; friend class ASTDeclReader; + friend class VarDecl; unsigned SClass : 3; unsigned TSCSpec : 2; @@ -815,10 +865,6 @@ private: }; enum { NumVarDeclBits = 7 }; - friend class ASTDeclReader; - friend class StmtIteratorBase; - friend class ASTNodeImporter; - protected: enum { NumParameterIndexBits = 8 }; @@ -830,8 +876,8 @@ protected: }; class ParmVarDeclBitfields { - friend class ParmVarDecl; friend class ASTDeclReader; + friend class ParmVarDecl; unsigned : NumVarDeclBits; @@ -863,9 +909,9 @@ protected: }; class NonParmVarDeclBitfields { - friend class VarDecl; - friend class ImplicitParamDecl; friend class ASTDeclReader; + friend class ImplicitParamDecl; + friend class VarDecl; unsigned : NumVarDeclBits; @@ -925,20 +971,24 @@ protected: SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass SC); - typedef Redeclarable<VarDecl> redeclarable_base; + using redeclarable_base = Redeclarable<VarDecl>; + VarDecl *getNextRedeclarationImpl() override { return getNextRedeclaration(); } + VarDecl *getPreviousDeclImpl() override { return getPreviousDecl(); } + VarDecl *getMostRecentDeclImpl() override { return getMostRecentDecl(); } public: - typedef redeclarable_base::redecl_range redecl_range; - typedef redeclarable_base::redecl_iterator redecl_iterator; + using redecl_range = redeclarable_base::redecl_range; + using redecl_iterator = redeclarable_base::redecl_iterator; + using redeclarable_base::redecls_begin; using redeclarable_base::redecls_end; using redeclarable_base::redecls; @@ -1043,7 +1093,6 @@ public: /// inside of functions. It also includes variables inside blocks. /// /// void foo() { int x; static int y; extern int z; } - /// bool isLocalVarDecl() const { if (getKind() != Decl::Var && getKind() != Decl::Decomposition) return false; @@ -1086,9 +1135,14 @@ public: } enum DefinitionKind { - DeclarationOnly, ///< This declaration is only a declaration. - TentativeDefinition, ///< This declaration is a tentative definition. - Definition ///< This declaration is definitely a definition. + /// This declaration is only a declaration. + DeclarationOnly, + + /// This declaration is a tentative definition. + TentativeDefinition, + + /// This declaration is definitely a definition. + Definition }; /// \brief Check whether this declaration is a definition. If this could be @@ -1218,6 +1272,7 @@ public: InitializationStyle getInitStyle() const { return static_cast<InitializationStyle>(VarDeclBits.InitStyle); } + /// \brief Whether the initializer is a direct-initializer (list or call). bool isDirectInit() const { return getInitStyle() != CInit; @@ -1235,8 +1290,8 @@ public: /// definitions one of which needs to be demoted to a declaration to keep /// the AST invariants. void demoteThisDefinitionToDeclaration() { - assert (isThisDeclarationADefinition() && "Not a definition!"); - assert (!isa<ParmVarDecl>(this) && "Cannot demote ParmVarDecls!"); + assert(isThisDeclarationADefinition() && "Not a definition!"); + assert(!isa<ParmVarDecl>(this) && "Cannot demote ParmVarDecls!"); NonParmVarDeclBits.IsThisDeclarationADemotedDefinition = 1; } @@ -1400,12 +1455,23 @@ public: /// with pointer to 'this', 'self', '_cmd', virtual table pointers, captured /// context or something else. enum ImplicitParamKind : unsigned { - ObjCSelf, /// Parameter for Objective-C 'self' argument - ObjCCmd, /// Parameter for Objective-C '_cmd' argument - CXXThis, /// Parameter for C++ 'this' argument - CXXVTT, /// Parameter for C++ virtual table pointers - CapturedContext, /// Parameter for captured context - Other, /// Other implicit parameter + /// Parameter for Objective-C 'self' argument + ObjCSelf, + + /// Parameter for Objective-C '_cmd' argument + ObjCCmd, + + /// Parameter for C++ 'this' argument + CXXThis, + + /// Parameter for C++ virtual table pointers + CXXVTT, + + /// Parameter for captured context + CapturedContext, + + /// Other implicit parameter + Other, }; /// Create implicit parameter. @@ -1438,6 +1504,7 @@ public: ImplicitParamKind getParameterKind() const { return static_cast<ImplicitParamKind>(NonParmVarDeclBits.ImplicitParamKind); } + // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classofKind(Kind K) { return K == ImplicitParam; } @@ -1644,7 +1711,7 @@ private: /// ParamInfo - new[]'d array of pointers to VarDecls for the formal /// parameters of this function. This is null if a prototype or if there are /// no formals. - ParmVarDecl **ParamInfo; + ParmVarDecl **ParamInfo = nullptr; LazyDeclStmtPtr Body; @@ -1653,10 +1720,12 @@ private: unsigned SClass : 3; unsigned IsInline : 1; unsigned IsInlineSpecified : 1; + protected: // This is shared by CXXConstructorDecl, CXXConversionDecl, and // CXXDeductionGuideDecl. unsigned IsExplicitSpecified : 1; + private: unsigned IsVirtualAsWritten : 1; unsigned IsPure : 1; @@ -1669,7 +1738,7 @@ private: unsigned HasImplicitReturnZero : 1; unsigned IsLateTemplateParsed : 1; unsigned IsConstexpr : 1; - unsigned InstantiationIsPending:1; + unsigned InstantiationIsPending : 1; /// \brief Indicates if the function uses __try. unsigned UsesSEHTry : 1; @@ -1689,6 +1758,7 @@ protected: /// Indicates that the Deduction Guide is the implicitly generated 'copy /// deduction candidate' (is used during overload resolution). unsigned IsCopyDeductionCandidate : 1; + private: /// \brief End part of this FunctionDecl's source range. /// @@ -1764,32 +1834,38 @@ protected: bool isConstexprSpecified) : DeclaratorDecl(DK, DC, NameInfo.getLoc(), NameInfo.getName(), T, TInfo, StartLoc), - DeclContext(DK), redeclarable_base(C), ParamInfo(nullptr), Body(), - SClass(S), IsInline(isInlineSpecified), - IsInlineSpecified(isInlineSpecified), IsExplicitSpecified(false), - IsVirtualAsWritten(false), IsPure(false), HasInheritedPrototype(false), - HasWrittenPrototype(true), IsDeleted(false), IsTrivial(false), - IsDefaulted(false), IsExplicitlyDefaulted(false), - HasImplicitReturnZero(false), IsLateTemplateParsed(false), - IsConstexpr(isConstexprSpecified), InstantiationIsPending(false), - UsesSEHTry(false), HasSkippedBody(false), WillHaveBody(false), - IsCopyDeductionCandidate(false), EndRangeLoc(NameInfo.getEndLoc()), - TemplateOrSpecialization(), DNLoc(NameInfo.getInfo()) {} + DeclContext(DK), redeclarable_base(C), SClass(S), + IsInline(isInlineSpecified), IsInlineSpecified(isInlineSpecified), + IsExplicitSpecified(false), IsVirtualAsWritten(false), IsPure(false), + HasInheritedPrototype(false), HasWrittenPrototype(true), + IsDeleted(false), IsTrivial(false), IsDefaulted(false), + IsExplicitlyDefaulted(false), HasImplicitReturnZero(false), + IsLateTemplateParsed(false), IsConstexpr(isConstexprSpecified), + InstantiationIsPending(false), UsesSEHTry(false), HasSkippedBody(false), + WillHaveBody(false), IsCopyDeductionCandidate(false), + EndRangeLoc(NameInfo.getEndLoc()), DNLoc(NameInfo.getInfo()) {} + + using redeclarable_base = Redeclarable<FunctionDecl>; - typedef Redeclarable<FunctionDecl> redeclarable_base; FunctionDecl *getNextRedeclarationImpl() override { return getNextRedeclaration(); } + FunctionDecl *getPreviousDeclImpl() override { return getPreviousDecl(); } + FunctionDecl *getMostRecentDeclImpl() override { return getMostRecentDecl(); } public: - typedef redeclarable_base::redecl_range redecl_range; - typedef redeclarable_base::redecl_iterator redecl_iterator; + friend class ASTDeclReader; + friend class ASTDeclWriter; + + using redecl_range = redeclarable_base::redecl_range; + using redecl_iterator = redeclarable_base::redecl_iterator; + using redeclarable_base::redecls_begin; using redeclarable_base::redecls_end; using redeclarable_base::redecls; @@ -1890,7 +1966,6 @@ public: /// /// This does not determine whether the function has been defined (e.g., in a /// previous definition); for that information, use isDefined. - /// bool isThisDeclarationADefinition() const { return IsDeleted || IsDefaulted || Body || IsLateTemplateParsed || WillHaveBody || hasDefiningAttr(); @@ -2094,8 +2169,9 @@ public: } // Iterator access to formal parameters. - typedef MutableArrayRef<ParmVarDecl *>::iterator param_iterator; - typedef ArrayRef<ParmVarDecl *>::const_iterator param_const_iterator; + using param_iterator = MutableArrayRef<ParmVarDecl *>::iterator; + using param_const_iterator = ArrayRef<ParmVarDecl *>::const_iterator; + bool param_empty() const { return parameters().empty(); } param_iterator param_begin() { return parameters().begin(); } param_iterator param_end() { return parameters().end(); } @@ -2378,12 +2454,8 @@ public: static FunctionDecl *castFromDeclContext(const DeclContext *DC) { return static_cast<FunctionDecl *>(const_cast<DeclContext*>(DC)); } - - friend class ASTDeclReader; - friend class ASTDeclWriter; }; - /// FieldDecl - An instance of this class is created by Sema::ActOnField to /// represent a member of a struct/union/class. class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> { @@ -2445,6 +2517,9 @@ protected: } public: + friend class ASTDeclReader; + friend class ASTDeclWriter; + static FieldDecl *Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, @@ -2480,6 +2555,7 @@ public: return static_cast<InitAndBitWidth*>(Ptr)->BitWidth; return static_cast<Expr*>(Ptr); } + unsigned getBitWidthValue(const ASTContext &Ctx) const; /// setBitWidth - Set the bit-field width for this member. @@ -2557,6 +2633,7 @@ public: InitStorage.getPointer()) : nullptr; } + /// \brief Set the captured variable length array type for this field. void setCapturedVLAType(const VariableArrayType *VLAType); @@ -2579,9 +2656,6 @@ public: // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classofKind(Kind K) { return K >= firstField && K <= lastField; } - - friend class ASTDeclReader; - friend class ASTDeclWriter; }; /// EnumConstantDecl - An instance of this object exists for each enum constant @@ -2591,6 +2665,7 @@ public: class EnumConstantDecl : public ValueDecl, public Mergeable<EnumConstantDecl> { Stmt *Init; // an integer constant expression llvm::APSInt Val; // The value. + protected: EnumConstantDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T, Expr *E, @@ -2598,6 +2673,7 @@ protected: : ValueDecl(EnumConstant, DC, L, Id, T), Init((Stmt*)E), Val(V) {} public: + friend class StmtIteratorBase; static EnumConstantDecl *Create(ASTContext &C, EnumDecl *DC, SourceLocation L, IdentifierInfo *Id, @@ -2621,8 +2697,6 @@ public: // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classofKind(Kind K) { return K == EnumConstant; } - - friend class StmtIteratorBase; }; /// IndirectFieldDecl - An instance of this class is created to represent a @@ -2630,7 +2704,6 @@ public: /// IndirectFieldDecl are always implicit. class IndirectFieldDecl : public ValueDecl, public Mergeable<IndirectFieldDecl> { - void anchor() override; NamedDecl **Chaining; unsigned ChainingSize; @@ -2638,14 +2711,18 @@ class IndirectFieldDecl : public ValueDe DeclarationName N, QualType T, MutableArrayRef<NamedDecl *> CH); + void anchor() override; + public: + friend class ASTDeclReader; + static IndirectFieldDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T, llvm::MutableArrayRef<NamedDecl *> CH); static IndirectFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID); - typedef ArrayRef<NamedDecl *>::const_iterator chain_iterator; + using chain_iterator = ArrayRef<NamedDecl *>::const_iterator; ArrayRef<NamedDecl *> chain() const { return llvm::makeArrayRef(Chaining, ChainingSize); @@ -2671,26 +2748,27 @@ public: // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classofKind(Kind K) { return K == IndirectField; } - friend class ASTDeclReader; }; /// TypeDecl - Represents a declaration of a type. -/// class TypeDecl : public NamedDecl { - void anchor() override; + friend class ASTContext; + /// TypeForDecl - This indicates the Type object that represents /// this TypeDecl. It is a cache maintained by /// ASTContext::getTypedefType, ASTContext::getTagDeclType, and /// ASTContext::getTemplateTypeParmType, and TemplateTypeParmDecl. - mutable const Type *TypeForDecl; + mutable const Type *TypeForDecl = nullptr; + /// LocStart - The start of the source range for this declaration. SourceLocation LocStart; - friend class ASTContext; + + void anchor() override; protected: TypeDecl(Kind DK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, SourceLocation StartL = SourceLocation()) - : NamedDecl(DK, DC, L, Id), TypeForDecl(nullptr), LocStart(StartL) {} + : NamedDecl(DK, DC, L, Id), LocStart(StartL) {} public: // Low-level accessor. If you just want the type defined by this node, @@ -2714,18 +2792,18 @@ public: static bool classofKind(Kind K) { return K >= firstType && K <= lastType; } }; - /// Base class for declarations which introduce a typedef-name. class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> { - void anchor() override; - typedef std::pair<TypeSourceInfo*, QualType> ModedTInfo; - llvm::PointerUnion<TypeSourceInfo*, ModedTInfo*> MaybeModedTInfo; + using ModedTInfo = std::pair<TypeSourceInfo *, QualType>; + llvm::PointerUnion<TypeSourceInfo *, ModedTInfo *> MaybeModedTInfo; // FIXME: This can be packed into the bitfields in Decl. /// If 0, we have not computed IsTransparentTag. /// Otherwise, IsTransparentTag is (CacheIsTransparentTag >> 1). mutable unsigned CacheIsTransparentTag : 2; + void anchor() override; + protected: TypedefNameDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, @@ -2733,20 +2811,24 @@ protected: : TypeDecl(DK, DC, IdLoc, Id, StartLoc), redeclarable_base(C), MaybeModedTInfo(TInfo), CacheIsTransparentTag(0) {} - typedef Redeclarable<TypedefNameDecl> redeclarable_base; + using redeclarable_base = Redeclarable<TypedefNameDecl>; + TypedefNameDecl *getNextRedeclarationImpl() override { return getNextRedeclaration(); } + TypedefNameDecl *getPreviousDeclImpl() override { return getPreviousDecl(); } + TypedefNameDecl *getMostRecentDeclImpl() override { return getMostRecentDecl(); } public: - typedef redeclarable_base::redecl_range redecl_range; - typedef redeclarable_base::redecl_iterator redecl_iterator; + using redecl_range = redeclarable_base::redecl_range; + using redecl_iterator = redeclarable_base::redecl_iterator; + using redeclarable_base::redecls_begin; using redeclarable_base::redecls_end; using redeclarable_base::redecls; @@ -2761,14 +2843,17 @@ public: ? MaybeModedTInfo.get<ModedTInfo*>()->first : MaybeModedTInfo.get<TypeSourceInfo*>(); } + QualType getUnderlyingType() const { return isModed() ? MaybeModedTInfo.get<ModedTInfo*>()->second : MaybeModedTInfo.get<TypeSourceInfo*>()->getType(); } + void setTypeSourceInfo(TypeSourceInfo *newType) { MaybeModedTInfo = newType; } + void setModedTypeSourceInfo(TypeSourceInfo *unmodedTSI, QualType modedTy) { MaybeModedTInfo = new (getASTContext()) ModedTInfo(unmodedTSI, modedTy); } @@ -2854,7 +2939,7 @@ class TagDecl : public TypeDecl, public DeclContext, public Redeclarable<TagDecl> { public: // This is really ugly. - typedef TagTypeKind TagKind; + using TagKind = TagTypeKind; private: // FIXME: This can be packed into the bitfields in Decl. @@ -2887,6 +2972,7 @@ protected: /// IsScoped - True if this tag declaration is a scoped enumeration. Only /// possible in C++11 mode. unsigned IsScoped : 1; + /// IsScopedUsingClassTag - If this tag declaration is a scoped enum, /// then this is true if the scoped enum was declared using the class /// tag, false if it was declared with the struct tag. No meaning is @@ -2906,12 +2992,13 @@ protected: /// Has the full definition of this type been required by a use somewhere in /// the TU. unsigned IsCompleteDefinitionRequired : 1; + private: SourceRange BraceRange; // A struct representing syntactic qualifier info, // to be used for the (uncommon) case of out-of-line declarations. - typedef QualifierInfo ExtInfo; + using ExtInfo = QualifierInfo; /// \brief If the (out-of-line) tag declaration name /// is qualified, it points to the qualifier info (nns and range); @@ -2943,13 +3030,16 @@ protected: setPreviousDecl(PrevDecl); } - typedef Redeclarable<TagDecl> redeclarable_base; + using redeclarable_base = Redeclarable<TagDecl>; + TagDecl *getNextRedeclarationImpl() override { return getNextRedeclaration(); } + TagDecl *getPreviousDeclImpl() override { return getPreviousDecl(); } + TagDecl *getMostRecentDeclImpl() override { return getMostRecentDecl(); } @@ -2960,8 +3050,12 @@ protected: void completeDefinition(); public: - typedef redeclarable_base::redecl_range redecl_range; - typedef redeclarable_base::redecl_iterator redecl_iterator; + friend class ASTDeclReader; + friend class ASTDeclWriter; + + using redecl_range = redeclarable_base::redecl_range; + using redecl_iterator = redeclarable_base::redecl_iterator; + using redeclarable_base::redecls_begin; using redeclarable_base::redecls_end; using redeclarable_base::redecls; @@ -3111,10 +3205,12 @@ public: unsigned getNumTemplateParameterLists() const { return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0; } + TemplateParameterList *getTemplateParameterList(unsigned i) const { assert(i < getNumTemplateParameterLists()); return getExtInfo()->TemplParamLists[i]; } + void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef<TemplateParameterList *> TPLists); @@ -3125,19 +3221,16 @@ public: static DeclContext *castToDeclContext(const TagDecl *D) { return static_cast<DeclContext *>(const_cast<TagDecl*>(D)); } + static TagDecl *castFromDeclContext(const DeclContext *DC) { return static_cast<TagDecl *>(const_cast<DeclContext*>(DC)); } - - friend class ASTDeclReader; - friend class ASTDeclWriter; }; /// EnumDecl - Represents an enum. In C++11, enums can be forward-declared /// with a fixed underlying type, and in C we allow them to be forward-declared /// with no underlying type as an extension. class EnumDecl : public TagDecl { - void anchor() override; /// IntegerType - This represent the integer type that the enum corresponds /// to for code generation purposes. Note that the enumerator constants may /// have a different type than this does. @@ -3152,8 +3245,7 @@ class EnumDecl : public TagDecl { /// The underlying type of an enumeration never has any qualifiers, so /// we can get away with just storing a raw Type*, and thus save an /// extra pointer when TypeSourceInfo is needed. - - llvm::PointerUnion<const Type*, TypeSourceInfo*> IntegerType; + llvm::PointerUnion<const Type *, TypeSourceInfo *> IntegerType; /// PromotionType - The integer type that values of this type should /// promote to. In C, enumerators are generally of an integer type @@ -3164,13 +3256,12 @@ class EnumDecl : public TagDecl { /// \brief If this enumeration is an instantiation of a member enumeration /// of a class template specialization, this is the member specialization /// information. - MemberSpecializationInfo *SpecializationInfo; + MemberSpecializationInfo *SpecializationInfo = nullptr; EnumDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl, bool Scoped, bool ScopedUsingClassTag, bool Fixed) - : TagDecl(Enum, TTK_Enum, C, DC, IdLoc, Id, PrevDecl, StartLoc), - SpecializationInfo(nullptr) { + : TagDecl(Enum, TTK_Enum, C, DC, IdLoc, Id, PrevDecl, StartLoc) { assert(Scoped || !ScopedUsingClassTag); IntegerType = (const Type *)nullptr; NumNegativeBits = 0; @@ -3180,9 +3271,13 @@ class EnumDecl : public TagDecl { IsFixed = Fixed; } + void anchor() override; + void setInstantiationOfMemberEnum(ASTContext &C, EnumDecl *ED, TemplateSpecializationKind TSK); public: + friend class ASTDeclReader; + EnumDecl *getCanonicalDecl() override { return cast<EnumDecl>(TagDecl::getCanonicalDecl()); } @@ -3228,9 +3323,9 @@ public: // enumerator_iterator - Iterates through the enumerators of this // enumeration. - typedef specific_decl_iterator<EnumConstantDecl> enumerator_iterator; - typedef llvm::iterator_range<specific_decl_iterator<EnumConstantDecl>> - enumerator_range; + using enumerator_iterator = specific_decl_iterator<EnumConstantDecl>; + using enumerator_range = + llvm::iterator_range<specific_decl_iterator<EnumConstantDecl>>; enumerator_range enumerators() const { return enumerator_range(enumerator_begin(), enumerator_end()); @@ -3378,17 +3473,15 @@ public: static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classofKind(Kind K) { return K == Enum; } - - friend class ASTDeclReader; }; - /// RecordDecl - Represents a struct/union/class. For example: /// struct X; // Forward declaration, no "body". /// union Y { int A, B; }; // Has body with members A and B (FieldDecls). /// This decl will be marked invalid if *any* members are invalid. -/// class RecordDecl : public TagDecl { + friend class DeclContext; + // FIXME: This can be packed into the bitfields in Decl. /// HasFlexibleArrayMember - This is true if this struct ends with a flexible /// array member (e.g. int X[]) or if this union contains a struct that does. @@ -3412,7 +3505,6 @@ class RecordDecl : public TagDecl { /// methods/nested types we allow deserialization of just the fields /// when needed. mutable bool LoadedFieldsFromExternalStorage : 1; - friend class DeclContext; protected: RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC, @@ -3495,6 +3587,7 @@ public: /// \brief Determine whether this record is a record for captured variables in /// CapturedStmt construct. bool isCapturedRecord() const; + /// \brief Mark the record as a record for captured variables in CapturedStmt /// construct. void setCapturedRecord(); @@ -3514,8 +3607,8 @@ public: // Iterator access to field members. The field iterator only visits // the non-static data members of this class, ignoring any static // data members, functions, constructors, destructors, etc. - typedef specific_decl_iterator<FieldDecl> field_iterator; - typedef llvm::iterator_range<specific_decl_iterator<FieldDecl>> field_range; + using field_iterator = specific_decl_iterator<FieldDecl>; + using field_range = llvm::iterator_range<specific_decl_iterator<FieldDecl>>; field_range fields() const { return field_range(field_begin(), field_end()); } field_iterator field_begin() const; @@ -3559,12 +3652,15 @@ private: }; class FileScopeAsmDecl : public Decl { - virtual void anchor(); StringLiteral *AsmString; SourceLocation RParenLoc; + FileScopeAsmDecl(DeclContext *DC, StringLiteral *asmstring, SourceLocation StartL, SourceLocation EndL) : Decl(FileScopeAsm, DC, StartL), AsmString(asmstring), RParenLoc(EndL) {} + + virtual void anchor(); + public: static FileScopeAsmDecl *Create(ASTContext &C, DeclContext *DC, StringLiteral *Str, SourceLocation AsmLoc, @@ -3590,7 +3686,6 @@ public: /// BlockDecl - This represents a block literal declaration, which is like an /// unnamed FunctionDecl. For example: /// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } -/// class BlockDecl : public Decl, public DeclContext { public: /// A class which contains all the information about a particular @@ -3637,29 +3732,27 @@ private: bool CapturesCXXThis : 1; bool BlockMissingReturnType : 1; bool IsConversionFromLambda : 1; + /// ParamInfo - new[]'d array of pointers to ParmVarDecls for the formal /// parameters of this function. This is null if a prototype or if there are /// no formals. - ParmVarDecl **ParamInfo; - unsigned NumParams; + ParmVarDecl **ParamInfo = nullptr; + unsigned NumParams = 0; - Stmt *Body; - TypeSourceInfo *SignatureAsWritten; + Stmt *Body = nullptr; + TypeSourceInfo *SignatureAsWritten = nullptr; - const Capture *Captures; - unsigned NumCaptures; + const Capture *Captures = nullptr; + unsigned NumCaptures = 0; - unsigned ManglingNumber; - Decl *ManglingContextDecl; + unsigned ManglingNumber = 0; + Decl *ManglingContextDecl = nullptr; protected: BlockDecl(DeclContext *DC, SourceLocation CaretLoc) - : Decl(Block, DC, CaretLoc), DeclContext(Block), - IsVariadic(false), CapturesCXXThis(false), - BlockMissingReturnType(true), IsConversionFromLambda(false), - ParamInfo(nullptr), NumParams(0), Body(nullptr), - SignatureAsWritten(nullptr), Captures(nullptr), NumCaptures(0), - ManglingNumber(0), ManglingContextDecl(nullptr) {} + : Decl(Block, DC, CaretLoc), DeclContext(Block), IsVariadic(false), + CapturesCXXThis(false), BlockMissingReturnType(true), + IsConversionFromLambda(false) {} public: static BlockDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L); @@ -3686,8 +3779,9 @@ public: } // Iterator access to formal parameters. - typedef MutableArrayRef<ParmVarDecl *>::iterator param_iterator; - typedef ArrayRef<ParmVarDecl *>::const_iterator param_const_iterator; + using param_iterator = MutableArrayRef<ParmVarDecl *>::iterator; + using param_const_iterator = ArrayRef<ParmVarDecl *>::const_iterator; + bool param_empty() const { return parameters().empty(); } param_iterator param_begin() { return parameters().begin(); } param_iterator param_end() { return parameters().end(); } @@ -3696,6 +3790,7 @@ public: size_t param_size() const { return parameters().size(); } unsigned getNumParams() const { return NumParams; } + const ParmVarDecl *getParamDecl(unsigned i) const { assert(i < getNumParams() && "Illegal param #"); return ParamInfo[i]; @@ -3704,6 +3799,7 @@ public: assert(i < getNumParams() && "Illegal param #"); return ParamInfo[i]; } + void setParams(ArrayRef<ParmVarDecl *> NewParamInfo); /// hasCaptures - True if this block (or its nested blocks) captures @@ -3714,7 +3810,7 @@ public: /// Does not include an entry for 'this'. unsigned getNumCaptures() const { return NumCaptures; } - typedef ArrayRef<Capture>::const_iterator capture_const_iterator; + using capture_const_iterator = ArrayRef<Capture>::const_iterator; ArrayRef<Capture> captures() const { return {Captures, NumCaptures}; } @@ -3736,6 +3832,7 @@ public: unsigned getBlockManglingNumber() const { return ManglingNumber; } + Decl *getBlockManglingContextDecl() const { return ManglingContextDecl; } @@ -3772,8 +3869,10 @@ protected: private: /// \brief The number of parameters to the outlined function. unsigned NumParams; + /// \brief The position of context parameter in list of parameters. unsigned ContextParam; + /// \brief The body of the outlined function. llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow; @@ -3788,6 +3887,10 @@ private: } public: + friend class ASTDeclReader; + friend class ASTDeclWriter; + friend TrailingObjects; + static CapturedDecl *Create(ASTContext &C, DeclContext *DC, unsigned NumParams); static CapturedDecl *CreateDeserialized(ASTContext &C, unsigned ID, @@ -3830,8 +3933,8 @@ public: } unsigned getContextParamPosition() const { return ContextParam; } - typedef ImplicitParamDecl *const *param_iterator; - typedef llvm::iterator_range<param_iterator> param_range; + using param_iterator = ImplicitParamDecl *const *; + using param_range = llvm::iterator_range<param_iterator>; /// \brief Retrieve an iterator pointing to the first parameter decl. param_iterator param_begin() const { return getParams(); } @@ -3847,10 +3950,6 @@ public: static CapturedDecl *castFromDeclContext(const DeclContext *DC) { return static_cast<CapturedDecl *>(const_cast<DeclContext *>(DC)); } - - friend class ASTDeclReader; - friend class ASTDeclWriter; - friend TrailingObjects; }; /// \brief Describes a module import declaration, which makes the contents @@ -3865,6 +3964,11 @@ public: /// \#include/\#import directives. class ImportDecl final : public Decl, llvm::TrailingObjects<ImportDecl, SourceLocation> { + friend class ASTContext; + friend class ASTDeclReader; + friend class ASTReader; + friend TrailingObjects; + /// \brief The imported module, along with a bit that indicates whether /// we have source-location information for each identifier in the module /// name. @@ -3875,20 +3979,15 @@ class ImportDecl final : public Decl, /// \brief The next import in the list of imports local to the translation /// unit being parsed (not loaded from an AST file). - ImportDecl *NextLocalImport; + ImportDecl *NextLocalImport = nullptr; - friend class ASTReader; - friend class ASTDeclReader; - friend class ASTContext; - friend TrailingObjects; - ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported, ArrayRef<SourceLocation> IdentifierLocs); ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported, SourceLocation EndLoc); - ImportDecl(EmptyShell Empty) : Decl(Import, Empty), NextLocalImport() { } + ImportDecl(EmptyShell Empty) : Decl(Import, Empty) {} public: /// \brief Create a new module import declaration. @@ -3930,15 +4029,16 @@ public: /// \endcode class ExportDecl final : public Decl, public DeclContext { virtual void anchor(); + private: + friend class ASTDeclReader; + /// \brief The source location for the right brace (if valid). SourceLocation RBraceLoc; ExportDecl(DeclContext *DC, SourceLocation ExportLoc) - : Decl(Export, DC, ExportLoc), DeclContext(Export), - RBraceLoc(SourceLocation()) { } - - friend class ASTDeclReader; + : Decl(Export, DC, ExportLoc), DeclContext(Export), + RBraceLoc(SourceLocation()) {} public: static ExportDecl *Create(ASTContext &C, DeclContext *DC, @@ -3973,9 +4073,9 @@ public: /// \brief Represents an empty-declaration. class EmptyDecl : public Decl { + EmptyDecl(DeclContext *DC, SourceLocation L) : Decl(Empty, DC, L) {} + virtual void anchor(); - EmptyDecl(DeclContext *DC, SourceLocation L) - : Decl(Empty, DC, L) { } public: static EmptyDecl *Create(ASTContext &C, DeclContext *DC, @@ -4052,6 +4152,6 @@ inline bool IsEnumDeclScoped(EnumDecl *E return ED->isScoped(); } -} // end namespace clang +} // namespace clang -#endif +#endif // LLVM_CLANG_AST_DECL_H Modified: cfe/trunk/lib/AST/Decl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=318101&r1=318100&r2=318101&view=diff ============================================================================== --- cfe/trunk/lib/AST/Decl.cpp (original) +++ cfe/trunk/lib/AST/Decl.cpp Mon Nov 13 15:01:27 2017 @@ -1,4 +1,4 @@ -//===--- Decl.cpp - Declaration AST Node Implementation -------------------===// +//===- Decl.cpp - Declaration AST Node Implementation ---------------------===// // // The LLVM Compiler Infrastructure // @@ -16,24 +16,58 @@ #include "clang/AST/ASTContext.h" #include "clang/AST/ASTLambda.h" #include "clang/AST/ASTMutationListener.h" -#include "clang/AST/Attr.h" +#include "clang/AST/CanonicalType.h" +#include "clang/AST/DeclBase.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/DeclOpenMP.h" #include "clang/AST/DeclTemplate.h" +#include "clang/AST/DeclarationName.h" #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" +#include "clang/AST/ExternalASTSource.h" #include "clang/AST/PrettyPrinter.h" +#include "clang/AST/Redeclarable.h" #include "clang/AST/Stmt.h" +#include "clang/AST/TemplateBase.h" +#include "clang/AST/Type.h" #include "clang/AST/TypeLoc.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/IdentifierTable.h" +#include "clang/Basic/LLVM.h" +#include "clang/Basic/LangOptions.h" +#include "clang/Basic/Linkage.h" #include "clang/Basic/Module.h" +#include "clang/Basic/PartialDiagnostic.h" +#include "clang/Basic/SanitizerBlacklist.h" +#include "clang/Basic/Sanitizers.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Basic/SourceManager.h" #include "clang/Basic/Specifiers.h" +#include "clang/Basic/TargetCXXABI.h" #include "clang/Basic/TargetInfo.h" +#include "clang/Basic/Visibility.h" #include "clang/Frontend/FrontendDiagnostic.h" +#include "llvm/ADT/APSInt.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/None.h" +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringSwitch.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Triple.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/raw_ostream.h" #include <algorithm> +#include <cassert> +#include <cstddef> +#include <cstring> +#include <memory> +#include <string> +#include <tuple> +#include <type_traits> using namespace clang; @@ -48,7 +82,7 @@ bool Decl::isOutOfLine() const { TranslationUnitDecl::TranslationUnitDecl(ASTContext &ctx) : Decl(TranslationUnit, nullptr, SourceLocation()), - DeclContext(TranslationUnit), Ctx(ctx), AnonymousNamespace(nullptr) {} + DeclContext(TranslationUnit), Ctx(ctx) {} //===----------------------------------------------------------------------===// // NamedDecl Implementation @@ -980,7 +1014,7 @@ LinkageComputer::getLVForClassMember(con return LV; } -void NamedDecl::anchor() { } +void NamedDecl::anchor() {} bool NamedDecl::isLinkageValid() const { if (!hasCachedLinkage()) @@ -1408,7 +1442,7 @@ Module *Decl::getOwningModuleForLinkage( case Module::ModuleInterfaceUnit: return M; - case Module::GlobalModuleFragment: + case Module::GlobalModuleFragment: { // External linkage declarations in the global module have no owning module // for linkage purposes. But internal linkage declarations in the global // module fragment of a particular module are owned by that module for @@ -1425,6 +1459,7 @@ Module *Decl::getOwningModuleForLinkage( } return InternalLinkage ? M->Parent : nullptr; } + } llvm_unreachable("unknown module kind"); } @@ -1458,7 +1493,7 @@ void NamedDecl::printQualifiedName(raw_o return; } - typedef SmallVector<const DeclContext *, 8> ContextsTy; + using ContextsTy = SmallVector<const DeclContext *, 8>; ContextsTy Contexts; // Collect contexts. @@ -1467,7 +1502,7 @@ void NamedDecl::printQualifiedName(raw_o Ctx = Ctx->getParent(); } - for (const DeclContext *DC : reverse(Contexts)) { + for (const DeclContext *DC : llvm::reverse(Contexts)) { if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(DC)) { OS << Spec->getName(); const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); @@ -1731,11 +1766,9 @@ SourceLocation DeclaratorDecl::getOuterL return getTemplateOrInnerLocStart(this); } -namespace { - // Helper function: returns true if QT is or contains a type // having a postfix component. -bool typeIsPostfix(clang::QualType QT) { +static bool typeIsPostfix(QualType QT) { while (true) { const Type* T = QT.getTypePtr(); switch (T->getTypeClass()) { @@ -1769,8 +1802,6 @@ bool typeIsPostfix(clang::QualType QT) { } } -} // namespace - SourceRange DeclaratorDecl::getSourceRange() const { SourceLocation RangeEnd = getLocation(); if (TypeSourceInfo *TInfo = getTypeSourceInfo()) { @@ -1820,7 +1851,7 @@ VarDecl::VarDecl(Kind DK, ASTContext &C, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass SC) : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc), - redeclarable_base(C), Init() { + redeclarable_base(C) { static_assert(sizeof(VarDeclBitfields) <= sizeof(unsigned), "VarDeclBitfields too large!"); static_assert(sizeof(ParmVarDeclBitfields) <= sizeof(unsigned), @@ -2862,7 +2893,6 @@ unsigned FunctionDecl::getBuiltinID() co return BuiltinID; } - /// getNumParams - Return the number of parameters this function must have /// based on its FunctionType. This is the length of the ParamInfo array /// after it has been created. @@ -3374,7 +3404,6 @@ DependentFunctionTemplateSpecializationI DependentFunctionTemplateSpecializationInfo(const UnresolvedSetImpl &Ts, const TemplateArgumentListInfo &TArgs) : AngleLocs(TArgs.getLAngleLoc(), TArgs.getRAngleLoc()) { - NumTemplates = Ts.size(); NumArgs = TArgs.size(); @@ -3737,7 +3766,7 @@ void TagDecl::setTemplateParameterListsI // EnumDecl Implementation //===----------------------------------------------------------------------===// -void EnumDecl::anchor() { } +void EnumDecl::anchor() {} EnumDecl *EnumDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, @@ -3846,12 +3875,10 @@ RecordDecl::RecordDecl(Kind DK, TagKind DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, RecordDecl *PrevDecl) - : TagDecl(DK, TK, C, DC, IdLoc, Id, PrevDecl, StartLoc) { - HasFlexibleArrayMember = false; - AnonymousStructOrUnion = false; - HasObjectMember = false; - HasVolatileMember = false; - LoadedFieldsFromExternalStorage = false; + : TagDecl(DK, TK, C, DC, IdLoc, Id, PrevDecl, StartLoc), + HasFlexibleArrayMember(false), AnonymousStructOrUnion(false), + HasObjectMember(false), HasVolatileMember(false), + LoadedFieldsFromExternalStorage(false) { assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!"); } @@ -4000,7 +4027,6 @@ const FieldDecl *RecordDecl::findFirstNa return nullptr; } - //===----------------------------------------------------------------------===// // BlockDecl Implementation //===----------------------------------------------------------------------===// @@ -4046,13 +4072,13 @@ SourceRange BlockDecl::getSourceRange() // Other Decl Allocation/Deallocation Method Implementations //===----------------------------------------------------------------------===// -void TranslationUnitDecl::anchor() { } +void TranslationUnitDecl::anchor() {} TranslationUnitDecl *TranslationUnitDecl::Create(ASTContext &C) { return new (C, (DeclContext *)nullptr) TranslationUnitDecl(C); } -void PragmaCommentDecl::anchor() { } +void PragmaCommentDecl::anchor() {} PragmaCommentDecl *PragmaCommentDecl::Create(const ASTContext &C, TranslationUnitDecl *DC, @@ -4074,7 +4100,7 @@ PragmaCommentDecl *PragmaCommentDecl::Cr PragmaCommentDecl(nullptr, SourceLocation(), PCK_Unknown); } -void PragmaDetectMismatchDecl::anchor() { } +void PragmaDetectMismatchDecl::anchor() {} PragmaDetectMismatchDecl * PragmaDetectMismatchDecl::Create(const ASTContext &C, TranslationUnitDecl *DC, @@ -4099,14 +4125,14 @@ PragmaDetectMismatchDecl::CreateDeserial PragmaDetectMismatchDecl(nullptr, SourceLocation(), 0); } -void ExternCContextDecl::anchor() { } +void ExternCContextDecl::anchor() {} ExternCContextDecl *ExternCContextDecl::Create(const ASTContext &C, TranslationUnitDecl *DC) { return new (C, DC) ExternCContextDecl(DC); } -void LabelDecl::anchor() { } +void LabelDecl::anchor() {} LabelDecl *LabelDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation IdentL, IdentifierInfo *II) { @@ -4132,7 +4158,7 @@ void LabelDecl::setMSAsmLabel(StringRef MSAsmName = Buffer; } -void ValueDecl::anchor() { } +void ValueDecl::anchor() {} bool ValueDecl::isWeak() const { for (const auto *I : attrs()) @@ -4142,7 +4168,7 @@ bool ValueDecl::isWeak() const { return isWeakImported(); } -void ImplicitParamDecl::anchor() { } +void ImplicitParamDecl::anchor() {} ImplicitParamDecl *ImplicitParamDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, @@ -4225,7 +4251,7 @@ EnumConstantDecl::CreateDeserialized(AST QualType(), nullptr, llvm::APSInt()); } -void IndirectFieldDecl::anchor() { } +void IndirectFieldDecl::anchor() {} IndirectFieldDecl::IndirectFieldDecl(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName N, @@ -4259,7 +4285,7 @@ SourceRange EnumConstantDecl::getSourceR return SourceRange(getLocation(), End); } -void TypeDecl::anchor() { } +void TypeDecl::anchor() {} TypedefDecl *TypedefDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, @@ -4267,7 +4293,7 @@ TypedefDecl *TypedefDecl::Create(ASTCont return new (C, DC) TypedefDecl(C, DC, StartLoc, IdLoc, Id, TInfo); } -void TypedefNameDecl::anchor() { } +void TypedefNameDecl::anchor() {} TagDecl *TypedefNameDecl::getAnonDeclWithTypedefName(bool AnyRedecl) const { if (auto *TT = getTypeSourceInfo()->getType()->getAs<TagType>()) { @@ -4341,7 +4367,7 @@ SourceRange TypeAliasDecl::getSourceRang return SourceRange(getLocStart(), RangeEnd); } -void FileScopeAsmDecl::anchor() { } +void FileScopeAsmDecl::anchor() {} FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C, DeclContext *DC, StringLiteral *Str, @@ -4384,9 +4410,7 @@ static unsigned getNumModuleIdentifiers( ImportDecl::ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported, ArrayRef<SourceLocation> IdentifierLocs) - : Decl(Import, DC, StartLoc), ImportedAndComplete(Imported, true), - NextLocalImport() -{ + : Decl(Import, DC, StartLoc), ImportedAndComplete(Imported, true) { assert(getNumModuleIdentifiers(Imported) == IdentifierLocs.size()); auto *StoredLocs = getTrailingObjects<SourceLocation>(); std::uninitialized_copy(IdentifierLocs.begin(), IdentifierLocs.end(), @@ -4395,9 +4419,7 @@ ImportDecl::ImportDecl(DeclContext *DC, ImportDecl::ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported, SourceLocation EndLoc) - : Decl(Import, DC, StartLoc), ImportedAndComplete(Imported, false), - NextLocalImport() -{ + : Decl(Import, DC, StartLoc), ImportedAndComplete(Imported, false) { *getTrailingObjects<SourceLocation>() = EndLoc; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits