From 88c7b76b1033506e286aab7ba0a4ee66e906eb5e Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Thu, 5 Jan 2017 18:45:45 +0000 Subject: [PATCH] Simplify ASTReader ctor by using in-class initializers for many member variables git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291155 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Serialization/ASTWriter.h | 86 +++++++++++++------------ lib/Serialization/ASTWriter.cpp | 20 +----- 2 files changed, 45 insertions(+), 61 deletions(-) diff --git a/include/clang/Serialization/ASTWriter.h b/include/clang/Serialization/ASTWriter.h index ce3178771a..0d6b026810 100644 --- a/include/clang/Serialization/ASTWriter.h +++ b/include/clang/Serialization/ASTWriter.h @@ -107,16 +107,16 @@ private: llvm::BitstreamWriter &Stream; /// \brief The ASTContext we're writing. - ASTContext *Context; + ASTContext *Context = nullptr; /// \brief The preprocessor we're writing. - Preprocessor *PP; + Preprocessor *PP = nullptr; /// \brief The reader of existing AST files, if we're chaining. - ASTReader *Chain; + ASTReader *Chain = nullptr; /// \brief The module we're currently writing, if any. - Module *WritingModule; + Module *WritingModule = nullptr; /// \brief The base directory for any relative paths we emit. std::string BaseDirectory; @@ -129,14 +129,14 @@ private: /// \brief Indicates when the AST writing is actively performing /// serialization, rather than just queueing updates. - bool WritingAST; + bool WritingAST = false; /// \brief Indicates that we are done serializing the collection of decls /// and types to emit. - bool DoneWritingDeclsAndTypes; + bool DoneWritingDeclsAndTypes = false; /// \brief Indicates that the AST contained compiler errors. - bool ASTHasCompilerErrors; + bool ASTHasCompilerErrors = false; /// \brief Mapping from input file entries to the index into the /// offset table where information about that input file is stored. @@ -170,10 +170,10 @@ private: std::queue DeclTypesToEmit; /// \brief The first ID number we can use for our own declarations. - serialization::DeclID FirstDeclID; + serialization::DeclID FirstDeclID = serialization::NUM_PREDEF_DECL_IDS; /// \brief The decl ID that will be assigned to the next new decl. - serialization::DeclID NextDeclID; + serialization::DeclID NextDeclID = FirstDeclID; /// \brief Map that provides the ID numbers of each declaration within /// the output stream, as well as those deserialized from a chained PCH. @@ -205,10 +205,10 @@ private: void associateDeclWithFile(const Decl *D, serialization::DeclID); /// \brief The first ID number we can use for our own types. - serialization::TypeID FirstTypeID; + serialization::TypeID FirstTypeID = serialization::NUM_PREDEF_TYPE_IDS; /// \brief The type ID that will be assigned to the next new type. - serialization::TypeID NextTypeID; + serialization::TypeID NextTypeID = FirstTypeID; /// \brief Map that provides the ID numbers of each type within the /// output stream, plus those deserialized from a chained PCH. @@ -226,10 +226,10 @@ private: std::vector TypeOffsets; /// \brief The first ID number we can use for our own identifiers. - serialization::IdentID FirstIdentID; + serialization::IdentID FirstIdentID = serialization::NUM_PREDEF_IDENT_IDS; /// \brief The identifier ID that will be assigned to the next new identifier. - serialization::IdentID NextIdentID; + serialization::IdentID NextIdentID = FirstIdentID; /// \brief Map that provides the ID numbers of each identifier in /// the output stream. @@ -240,10 +240,10 @@ private: llvm::MapVector IdentifierIDs; /// \brief The first ID number we can use for our own macros. - serialization::MacroID FirstMacroID; + serialization::MacroID FirstMacroID = serialization::NUM_PREDEF_MACRO_IDS; /// \brief The identifier ID that will be assigned to the next new identifier. - serialization::MacroID NextMacroID; + serialization::MacroID NextMacroID = FirstMacroID; /// \brief Map that provides the ID numbers of each macro. llvm::DenseMap MacroIDs; @@ -275,16 +275,18 @@ private: std::vector IdentifierOffsets; /// \brief The first ID number we can use for our own submodules. - serialization::SubmoduleID FirstSubmoduleID; - + serialization::SubmoduleID FirstSubmoduleID = + serialization::NUM_PREDEF_SUBMODULE_IDS; + /// \brief The submodule ID that will be assigned to the next new submodule. - serialization::SubmoduleID NextSubmoduleID; + serialization::SubmoduleID NextSubmoduleID = FirstSubmoduleID; /// \brief The first ID number we can use for our own selectors. - serialization::SelectorID FirstSelectorID; + serialization::SelectorID FirstSelectorID = + serialization::NUM_PREDEF_SELECTOR_IDS; /// \brief The selector ID that will be assigned to the next new selector. - serialization::SelectorID NextSelectorID; + serialization::SelectorID NextSelectorID = FirstSelectorID; /// \brief Map that provides the ID numbers of each Selector. llvm::MapVector SelectorIDs; @@ -394,18 +396,18 @@ private: llvm::DenseMap SwitchCaseIDs; /// \brief The number of statements written to the AST file. - unsigned NumStatements; + unsigned NumStatements = 0; /// \brief The number of macros written to the AST file. - unsigned NumMacros; + unsigned NumMacros = 0; /// \brief The number of lexical declcontexts written to the AST /// file. - unsigned NumLexicalDeclContexts; + unsigned NumLexicalDeclContexts = 0; /// \brief The number of visible declcontexts written to the AST /// file. - unsigned NumVisibleDeclContexts; + unsigned NumVisibleDeclContexts = 0; /// \brief A mapping from each known submodule to its ID number, which will /// be a positive integer. @@ -436,8 +438,8 @@ private: void WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag, bool isModule); - unsigned TypeExtQualAbbrev; - unsigned TypeFunctionProtoAbbrev; + unsigned TypeExtQualAbbrev = 0; + unsigned TypeFunctionProtoAbbrev = 0; void WriteTypeAbbrevs(); void WriteType(QualType T); @@ -470,22 +472,22 @@ private: void WriteModuleFileExtension(Sema &SemaRef, ModuleFileExtensionWriter &Writer); - unsigned DeclParmVarAbbrev; - unsigned DeclContextLexicalAbbrev; - unsigned DeclContextVisibleLookupAbbrev; - unsigned UpdateVisibleAbbrev; - unsigned DeclRecordAbbrev; - unsigned DeclTypedefAbbrev; - unsigned DeclVarAbbrev; - unsigned DeclFieldAbbrev; - unsigned DeclEnumAbbrev; - unsigned DeclObjCIvarAbbrev; - unsigned DeclCXXMethodAbbrev; - - unsigned DeclRefExprAbbrev; - unsigned CharacterLiteralAbbrev; - unsigned IntegerLiteralAbbrev; - unsigned ExprImplicitCastAbbrev; + unsigned DeclParmVarAbbrev = 0; + unsigned DeclContextLexicalAbbrev = 0; + unsigned DeclContextVisibleLookupAbbrev = 0; + unsigned UpdateVisibleAbbrev = 0; + unsigned DeclRecordAbbrev = 0; + unsigned DeclTypedefAbbrev = 0; + unsigned DeclVarAbbrev = 0; + unsigned DeclFieldAbbrev = 0; + unsigned DeclEnumAbbrev = 0; + unsigned DeclObjCIvarAbbrev = 0; + unsigned DeclCXXMethodAbbrev = 0; + + unsigned DeclRefExprAbbrev = 0; + unsigned CharacterLiteralAbbrev = 0; + unsigned IntegerLiteralAbbrev = 0; + unsigned ExprImplicitCastAbbrev = 0; void WriteDeclAbbrevs(); void WriteDecl(ASTContext &Context, Decl *D); diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 6bdb381b1e..2a5eda436f 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -4224,25 +4224,7 @@ void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream, ArrayRef> Extensions, bool IncludeTimestamps) - : Stream(Stream), Context(nullptr), PP(nullptr), Chain(nullptr), - WritingModule(nullptr), IncludeTimestamps(IncludeTimestamps), - WritingAST(false), DoneWritingDeclsAndTypes(false), - ASTHasCompilerErrors(false), FirstDeclID(NUM_PREDEF_DECL_IDS), - NextDeclID(FirstDeclID), FirstTypeID(NUM_PREDEF_TYPE_IDS), - NextTypeID(FirstTypeID), FirstIdentID(NUM_PREDEF_IDENT_IDS), - NextIdentID(FirstIdentID), FirstMacroID(NUM_PREDEF_MACRO_IDS), - NextMacroID(FirstMacroID), FirstSubmoduleID(NUM_PREDEF_SUBMODULE_IDS), - NextSubmoduleID(FirstSubmoduleID), - FirstSelectorID(NUM_PREDEF_SELECTOR_IDS), NextSelectorID(FirstSelectorID), - NumStatements(0), NumMacros(0), NumLexicalDeclContexts(0), - NumVisibleDeclContexts(0), TypeExtQualAbbrev(0), - TypeFunctionProtoAbbrev(0), DeclParmVarAbbrev(0), - DeclContextLexicalAbbrev(0), DeclContextVisibleLookupAbbrev(0), - UpdateVisibleAbbrev(0), DeclRecordAbbrev(0), DeclTypedefAbbrev(0), - DeclVarAbbrev(0), DeclFieldAbbrev(0), DeclEnumAbbrev(0), - DeclObjCIvarAbbrev(0), DeclCXXMethodAbbrev(0), DeclRefExprAbbrev(0), - CharacterLiteralAbbrev(0), IntegerLiteralAbbrev(0), - ExprImplicitCastAbbrev(0) { + : Stream(Stream), IncludeTimestamps(IncludeTimestamps) { for (const auto &Ext : Extensions) { if (auto Writer = Ext->createExtensionWriter(*this)) ModuleFileExtensionWriters.push_back(std::move(Writer)); -- 2.40.0