Simplify ASTReader ctor by using in-class initializers for many member variables

llvm-svn: 291155
This commit is contained in:
David Blaikie 2017-01-05 18:45:45 +00:00
parent 9d7c1ba5cf
commit 95dd362c77
2 changed files with 44 additions and 60 deletions

View File

@ -107,16 +107,16 @@ private:
llvm::BitstreamWriter &Stream; llvm::BitstreamWriter &Stream;
/// \brief The ASTContext we're writing. /// \brief The ASTContext we're writing.
ASTContext *Context; ASTContext *Context = nullptr;
/// \brief The preprocessor we're writing. /// \brief The preprocessor we're writing.
Preprocessor *PP; Preprocessor *PP = nullptr;
/// \brief The reader of existing AST files, if we're chaining. /// \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. /// \brief The module we're currently writing, if any.
Module *WritingModule; Module *WritingModule = nullptr;
/// \brief The base directory for any relative paths we emit. /// \brief The base directory for any relative paths we emit.
std::string BaseDirectory; std::string BaseDirectory;
@ -129,14 +129,14 @@ private:
/// \brief Indicates when the AST writing is actively performing /// \brief Indicates when the AST writing is actively performing
/// serialization, rather than just queueing updates. /// serialization, rather than just queueing updates.
bool WritingAST; bool WritingAST = false;
/// \brief Indicates that we are done serializing the collection of decls /// \brief Indicates that we are done serializing the collection of decls
/// and types to emit. /// and types to emit.
bool DoneWritingDeclsAndTypes; bool DoneWritingDeclsAndTypes = false;
/// \brief Indicates that the AST contained compiler errors. /// \brief Indicates that the AST contained compiler errors.
bool ASTHasCompilerErrors; bool ASTHasCompilerErrors = false;
/// \brief Mapping from input file entries to the index into the /// \brief Mapping from input file entries to the index into the
/// offset table where information about that input file is stored. /// offset table where information about that input file is stored.
@ -170,10 +170,10 @@ private:
std::queue<DeclOrType> DeclTypesToEmit; std::queue<DeclOrType> DeclTypesToEmit;
/// \brief The first ID number we can use for our own declarations. /// \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. /// \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 /// \brief Map that provides the ID numbers of each declaration within
/// the output stream, as well as those deserialized from a chained PCH. /// the output stream, as well as those deserialized from a chained PCH.
@ -205,10 +205,10 @@ private:
void associateDeclWithFile(const Decl *D, serialization::DeclID); void associateDeclWithFile(const Decl *D, serialization::DeclID);
/// \brief The first ID number we can use for our own types. /// \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. /// \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 /// \brief Map that provides the ID numbers of each type within the
/// output stream, plus those deserialized from a chained PCH. /// output stream, plus those deserialized from a chained PCH.
@ -226,10 +226,10 @@ private:
std::vector<uint32_t> TypeOffsets; std::vector<uint32_t> TypeOffsets;
/// \brief The first ID number we can use for our own identifiers. /// \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. /// \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 /// \brief Map that provides the ID numbers of each identifier in
/// the output stream. /// the output stream.
@ -240,10 +240,10 @@ private:
llvm::MapVector<const IdentifierInfo *, serialization::IdentID> IdentifierIDs; llvm::MapVector<const IdentifierInfo *, serialization::IdentID> IdentifierIDs;
/// \brief The first ID number we can use for our own macros. /// \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. /// \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. /// \brief Map that provides the ID numbers of each macro.
llvm::DenseMap<MacroInfo *, serialization::MacroID> MacroIDs; llvm::DenseMap<MacroInfo *, serialization::MacroID> MacroIDs;
@ -275,16 +275,18 @@ private:
std::vector<uint32_t> IdentifierOffsets; std::vector<uint32_t> IdentifierOffsets;
/// \brief The first ID number we can use for our own submodules. /// \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. /// \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. /// \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. /// \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. /// \brief Map that provides the ID numbers of each Selector.
llvm::MapVector<Selector, serialization::SelectorID> SelectorIDs; llvm::MapVector<Selector, serialization::SelectorID> SelectorIDs;
@ -394,18 +396,18 @@ private:
llvm::DenseMap<SwitchCase *, unsigned> SwitchCaseIDs; llvm::DenseMap<SwitchCase *, unsigned> SwitchCaseIDs;
/// \brief The number of statements written to the AST file. /// \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. /// \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 /// \brief The number of lexical declcontexts written to the AST
/// file. /// file.
unsigned NumLexicalDeclContexts; unsigned NumLexicalDeclContexts = 0;
/// \brief The number of visible declcontexts written to the AST /// \brief The number of visible declcontexts written to the AST
/// file. /// file.
unsigned NumVisibleDeclContexts; unsigned NumVisibleDeclContexts = 0;
/// \brief A mapping from each known submodule to its ID number, which will /// \brief A mapping from each known submodule to its ID number, which will
/// be a positive integer. /// be a positive integer.
@ -436,8 +438,8 @@ private:
void WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag, void WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag,
bool isModule); bool isModule);
unsigned TypeExtQualAbbrev; unsigned TypeExtQualAbbrev = 0;
unsigned TypeFunctionProtoAbbrev; unsigned TypeFunctionProtoAbbrev = 0;
void WriteTypeAbbrevs(); void WriteTypeAbbrevs();
void WriteType(QualType T); void WriteType(QualType T);
@ -470,22 +472,22 @@ private:
void WriteModuleFileExtension(Sema &SemaRef, void WriteModuleFileExtension(Sema &SemaRef,
ModuleFileExtensionWriter &Writer); ModuleFileExtensionWriter &Writer);
unsigned DeclParmVarAbbrev; unsigned DeclParmVarAbbrev = 0;
unsigned DeclContextLexicalAbbrev; unsigned DeclContextLexicalAbbrev = 0;
unsigned DeclContextVisibleLookupAbbrev; unsigned DeclContextVisibleLookupAbbrev = 0;
unsigned UpdateVisibleAbbrev; unsigned UpdateVisibleAbbrev = 0;
unsigned DeclRecordAbbrev; unsigned DeclRecordAbbrev = 0;
unsigned DeclTypedefAbbrev; unsigned DeclTypedefAbbrev = 0;
unsigned DeclVarAbbrev; unsigned DeclVarAbbrev = 0;
unsigned DeclFieldAbbrev; unsigned DeclFieldAbbrev = 0;
unsigned DeclEnumAbbrev; unsigned DeclEnumAbbrev = 0;
unsigned DeclObjCIvarAbbrev; unsigned DeclObjCIvarAbbrev = 0;
unsigned DeclCXXMethodAbbrev; unsigned DeclCXXMethodAbbrev = 0;
unsigned DeclRefExprAbbrev; unsigned DeclRefExprAbbrev = 0;
unsigned CharacterLiteralAbbrev; unsigned CharacterLiteralAbbrev = 0;
unsigned IntegerLiteralAbbrev; unsigned IntegerLiteralAbbrev = 0;
unsigned ExprImplicitCastAbbrev; unsigned ExprImplicitCastAbbrev = 0;
void WriteDeclAbbrevs(); void WriteDeclAbbrevs();
void WriteDecl(ASTContext &Context, Decl *D); void WriteDecl(ASTContext &Context, Decl *D);

View File

@ -4224,25 +4224,7 @@ void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) {
ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream, ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream,
ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions, ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
bool IncludeTimestamps) bool IncludeTimestamps)
: Stream(Stream), Context(nullptr), PP(nullptr), Chain(nullptr), : Stream(Stream), IncludeTimestamps(IncludeTimestamps) {
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) {
for (const auto &Ext : Extensions) { for (const auto &Ext : Extensions) {
if (auto Writer = Ext->createExtensionWriter(*this)) if (auto Writer = Ext->createExtensionWriter(*this))
ModuleFileExtensionWriters.push_back(std::move(Writer)); ModuleFileExtensionWriters.push_back(std::move(Writer));