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

David Blaikie via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 5 10:45:45 PST 2017


Author: dblaikie
Date: Thu Jan  5 12:45:45 2017
New Revision: 291155

URL: http://llvm.org/viewvc/llvm-project?rev=291155&view=rev
Log:
Simplify ASTReader ctor by using in-class initializers for many member variables

Modified:
    cfe/trunk/include/clang/Serialization/ASTWriter.h
    cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=291155&r1=291154&r2=291155&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTWriter.h Thu Jan  5 12:45:45 2017
@@ -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<DeclOrType> 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<uint32_t> 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<const IdentifierInfo *, serialization::IdentID> 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<MacroInfo *, serialization::MacroID> MacroIDs;
@@ -275,16 +275,18 @@ private:
   std::vector<uint32_t> 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<Selector, serialization::SelectorID> SelectorIDs;
@@ -394,18 +396,18 @@ private:
   llvm::DenseMap<SwitchCase *, unsigned> 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);

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=291155&r1=291154&r2=291155&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Thu Jan  5 12:45:45 2017
@@ -4224,25 +4224,7 @@ void ASTWriter::SetSelectorOffset(Select
 ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream,
                      ArrayRef<std::shared_ptr<ModuleFileExtension>> 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));




More information about the cfe-commits mailing list