14 #ifndef LLVM_CLANG_SERIALIZATION_ASTWRITER_H 15 #define LLVM_CLANG_SERIALIZATION_ASTWRITER_H 26 #include "llvm/ADT/ArrayRef.h" 27 #include "llvm/ADT/DenseMap.h" 28 #include "llvm/ADT/DenseSet.h" 29 #include "llvm/ADT/MapVector.h" 30 #include "llvm/ADT/SetVector.h" 31 #include "llvm/ADT/SmallVector.h" 32 #include "llvm/ADT/StringRef.h" 33 #include "llvm/Bitstream/BitstreamWriter.h" 56 class ASTUnresolvedSet;
58 class CXXBaseSpecifier;
59 class CXXCtorInitializer;
66 class HeaderSearchOptions;
67 class IdentifierResolver;
69 class MacroDefinitionRecord;
72 class InMemoryModuleCache;
73 class ModuleFileExtension;
74 class ModuleFileExtensionWriter;
76 class ObjCInterfaceDecl;
77 class PreprocessingRecord;
84 struct StoredDeclsList;
86 class TemplateParameterList;
120 llvm::BitstreamWriter &Stream;
138 Module *WritingModule =
nullptr;
141 std::string BaseDirectory;
147 bool IncludeTimestamps;
151 bool WritingAST =
false;
155 bool DoneWritingDeclsAndTypes =
false;
158 bool ASTHasCompilerErrors =
false;
162 llvm::DenseMap<const FileEntry *, uint32_t> InputFileIDs;
167 DeclOrType(
Decl *D) : Stored(D), IsType(
false) {}
168 DeclOrType(QualType T) : Stored(T.
getAsOpaquePtr()), IsType(
true) {}
170 bool isType()
const {
return IsType; }
171 bool isDecl()
const {
return !IsType; }
173 QualType getType()
const {
174 assert(isType() &&
"Not a type!");
175 return QualType::getFromOpaquePtr(Stored);
178 Decl *getDecl()
const {
179 assert(isDecl() &&
"Not a decl!");
180 return static_cast<Decl *
>(Stored);
189 std::queue<DeclOrType> DeclTypesToEmit;
203 llvm::DenseMap<const Decl *, serialization::DeclID> DeclIDs;
207 std::vector<serialization::DeclOffset> DeclOffsets;
212 struct DeclIDInFileInfo {
217 unsigned FirstDeclIndex;
219 using FileDeclIDsTy = llvm::DenseMap<FileID, DeclIDInFileInfo *>;
223 FileDeclIDsTy FileDeclIDs;
246 std::vector<uint32_t> TypeOffsets;
260 llvm::MapVector<const IdentifierInfo *, serialization::IdentID> IdentifierIDs;
269 llvm::DenseMap<MacroInfo *, serialization::MacroID> MacroIDs;
271 struct MacroInfoToEmitData {
278 std::vector<MacroInfoToEmitData> MacroInfosToEmit;
280 llvm::DenseMap<const IdentifierInfo *, uint64_t> IdentMacroDirectivesOffsetMap;
290 llvm::DenseMap<Stmt *, uint64_t> SubStmtEntries;
296 std::vector<uint32_t> IdentifierOffsets;
313 llvm::MapVector<Selector, serialization::SelectorID> SelectorIDs;
317 std::vector<uint32_t> SelectorOffsets;
326 llvm::DenseMap<const Decl *, unsigned> AnonymousDeclarationNumbers;
338 const Attr *Attribute;
342 DeclUpdate(
unsigned Kind) :
Kind(Kind), Dcl(
nullptr) {}
343 DeclUpdate(
unsigned Kind,
const Decl *Dcl) :
Kind(Kind), Dcl(Dcl) {}
344 DeclUpdate(
unsigned Kind, QualType
Type)
348 DeclUpdate(
unsigned Kind,
unsigned Val) :
Kind(Kind), Val(Val) {}
349 DeclUpdate(
unsigned Kind,
Module *M) :
Kind(Kind), Mod(M) {}
350 DeclUpdate(
unsigned Kind,
const Attr *Attribute)
351 :
Kind(Kind), Attribute(Attribute) {}
354 const Decl *getDecl()
const {
return Dcl; }
355 QualType getType()
const {
return QualType::getFromOpaquePtr(Type); }
358 return SourceLocation::getFromRawEncoding(Loc);
361 unsigned getNumber()
const {
return Val; }
362 Module *getModule()
const {
return Mod; }
363 const Attr *getAttr()
const {
return Attribute; }
367 using DeclUpdateMap = llvm::MapVector<const Decl *, UpdateRecord>;
371 DeclUpdateMap DeclUpdates;
373 using FirstLatestDeclMap = llvm::DenseMap<Decl *, Decl *>;
377 FirstLatestDeclMap FirstLatestDecls;
409 llvm::SetVector<ObjCInterfaceDecl *> ObjCClassesWithCategories;
417 llvm::DenseMap<const Decl *, const Decl *> FirstLocalDeclCache;
420 llvm::DenseMap<SwitchCase *, unsigned> SwitchCaseIDs;
423 unsigned NumStatements = 0;
426 unsigned NumMacros = 0;
430 unsigned NumLexicalDeclContexts = 0;
434 unsigned NumVisibleDeclContexts = 0;
438 llvm::DenseMap<Module *, unsigned> SubmoduleIDs;
441 std::vector<std::unique_ptr<ModuleFileExtensionWriter>>
442 ModuleFileExtensionWriters;
445 unsigned getSubmoduleID(
Module *Mod);
448 void WriteSubStmt(
Stmt *S);
450 void WriteBlockInfoBlock();
452 StringRef isysroot,
const std::string &OutputFile);
465 void WritePreprocessor(
const Preprocessor &PP,
bool IsModule);
468 void WriteSubmodules(
Module *WritingModule);
473 unsigned TypeExtQualAbbrev = 0;
474 unsigned TypeFunctionProtoAbbrev = 0;
475 void WriteTypeAbbrevs();
476 void WriteType(QualType T);
481 void GenerateNameLookupTable(
const DeclContext *DC,
485 void WriteTypeDeclOffsets();
486 void WriteFileDeclIDsMap();
487 void WriteComments();
488 void WriteSelectors(
Sema &SemaRef);
489 void WriteReferencedSelectorsPool(
Sema &SemaRef);
493 void WriteDeclContextVisibleUpdate(
const DeclContext *DC);
494 void WriteFPPragmaOptions(
const FPOptions &Opts);
495 void WriteOpenCLExtensions(
Sema &SemaRef);
496 void WriteOpenCLExtensionTypes(
Sema &SemaRef);
497 void WriteOpenCLExtensionDecls(
Sema &SemaRef);
498 void WriteCUDAPragmas(
Sema &SemaRef);
499 void WriteObjCCategories();
500 void WriteLateParsedTemplates(
Sema &SemaRef);
501 void WriteOptimizePragmaOptions(
Sema &SemaRef);
502 void WriteMSStructPragmaOptions(
Sema &SemaRef);
503 void WriteMSPointersToMembersPragmaOptions(
Sema &SemaRef);
504 void WritePackPragmaOptions(
Sema &SemaRef);
505 void WriteModuleFileExtension(
Sema &SemaRef,
508 unsigned DeclParmVarAbbrev = 0;
509 unsigned DeclContextLexicalAbbrev = 0;
510 unsigned DeclContextVisibleLookupAbbrev = 0;
511 unsigned UpdateVisibleAbbrev = 0;
512 unsigned DeclRecordAbbrev = 0;
513 unsigned DeclTypedefAbbrev = 0;
514 unsigned DeclVarAbbrev = 0;
515 unsigned DeclFieldAbbrev = 0;
516 unsigned DeclEnumAbbrev = 0;
517 unsigned DeclObjCIvarAbbrev = 0;
518 unsigned DeclCXXMethodAbbrev = 0;
520 unsigned DeclRefExprAbbrev = 0;
521 unsigned CharacterLiteralAbbrev = 0;
522 unsigned IntegerLiteralAbbrev = 0;
523 unsigned ExprImplicitCastAbbrev = 0;
525 void WriteDeclAbbrevs();
529 const std::string &OutputFile,
537 ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
538 bool IncludeTimestamps =
true);
546 time_t getTimestampForOutput(
const FileEntry *E)
const;
563 Module *WritingModule, StringRef isysroot,
564 bool hasErrors =
false,
565 bool ShouldCacheASTInMemory =
false);
604 const Decl *getFirstLocalDecl(
const Decl *D);
612 auto I = DeclIDs.find(D);
613 return (I == DeclIDs.end() ||
627 unsigned getAnonymousDeclarationNumber(
const NamedDecl *D);
640 void EmitRecordWithPath(
unsigned Abbrev,
RecordDataRef Record,
644 void AddVersionTuple(
const VersionTuple &Version,
RecordDataImpl &Record);
649 unsigned getLocalOrImportedSubmoduleID(
Module *Mod);
657 void SetSelectorOffset(
Selector Sel, uint32_t Offset);
665 void ClearSwitchCaseIDs();
668 return TypeExtQualAbbrev;
672 return TypeFunctionProtoAbbrev;
694 void ReaderInitialized(
ASTReader *Reader)
override;
697 void TypeRead(serialization::TypeIdx Idx, QualType T)
override;
700 MacroDefinitionRecord *MD)
override;
704 void CompletedTagDefinition(
const TagDecl *D)
override;
707 void AddedCXXTemplateSpecialization(
710 void AddedCXXTemplateSpecialization(
715 void ResolvedExceptionSpec(
const FunctionDecl *FD)
override;
716 void DeducedReturnType(
const FunctionDecl *FD, QualType ReturnType)
override;
719 Expr *ThisArg)
override;
720 void CompletedImplicitDefinition(
const FunctionDecl *D)
override;
721 void InstantiationRequested(
const ValueDecl *D)
override;
722 void VariableDefinitionInstantiated(
const VarDecl *D)
override;
723 void FunctionDefinitionInstantiated(
const FunctionDecl *D)
override;
724 void DefaultArgumentInstantiated(
const ParmVarDecl *D)
override;
725 void DefaultMemberInitializerInstantiated(
const FieldDecl *D)
override;
728 void DeclarationMarkedUsed(
const Decl *D)
override;
729 void DeclarationMarkedOpenMPThreadPrivate(
const Decl *D)
override;
730 void DeclarationMarkedOpenMPDeclareTarget(
const Decl *D,
732 void DeclarationMarkedOpenMPAllocate(
const Decl *D,
const Attr *A)
override;
733 void RedefinedHiddenDefinition(
const NamedDecl *D,
Module *M)
override;
734 void AddedAttributeToRecord(
const Attr *Attr,
742 std::string OutputFile;
743 std::string isysroot;
745 std::shared_ptr<PCHBuffer> Buffer;
746 llvm::BitstreamWriter Stream;
748 bool AllowASTWithErrors;
749 bool ShouldCacheASTInMemory;
758 StringRef OutputFile, StringRef isysroot,
759 std::shared_ptr<PCHBuffer> Buffer,
760 ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
761 bool AllowASTWithErrors =
false,
bool IncludeTimestamps =
true,
762 bool ShouldCacheASTInMemory =
false);
766 void HandleTranslationUnit(
ASTContext &Ctx)
override;
774 #endif // LLVM_CLANG_SERIALIZATION_ASTWRITER_H unsigned getDeclEnumAbbrev() const
Represents a function declaration or definition.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
Smart pointer class that efficiently represents Objective-C method names.
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
A (possibly-)qualified type.
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
A structure for putting "fast"-unqualified QualTypes into a DenseMap.
const unsigned NUM_PREDEF_TYPE_IDS
The number of predefined type IDs that are reserved for the PREDEF_TYPE_* constants.
Stmt - This represents one statement.
C Language Family Type Representation.
void InitializeSema(Sema &S) override
Initialize the semantic consumer with the Sema instance being used to perform semantic analysis on th...
const unsigned int NUM_PREDEF_SELECTOR_IDS
The number of predefined selector IDs.
Decl - This represents one declaration (or definition), e.g.
The base class of the type hierarchy.
Declaration of a variable template.
Floating point control options.
unsigned getDeclRefExprAbbrev() const
Represents a variable declaration or definition.
const unsigned int NUM_PREDEF_DECL_IDS
The number of declaration IDs that are predefined.
Represents a variable template specialization, which refers to a variable template with a given set o...
SmallVectorImpl< char > & getPCH() const
Represents a parameter to a function.
const ASTWriter & getWriter() const
bool hasEmittedPCH() const
Represents a struct/union/class.
Represents a class template specialization, which refers to a class template with a given set of temp...
One of these records is kept for each identifier that is lexed.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Record the location of a macro definition.
Represents a member of a struct/union/class.
Token - This structure provides full information about a lexed token.
ASTReader * getChain() const
uint32_t MacroID
An ID number that refers to a macro in an AST file.
The signature of a module, which is a hash of the AST content.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Describes a module or submodule.
unsigned getDeclFieldAbbrev() const
An abstract interface that should be implemented by clients that read ASTs and then require further s...
unsigned getIntegerLiteralAbbrev() const
A record of the steps taken while preprocessing a source file, including the various preprocessing di...
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
Concrete class used by the front-end to report problems and issues.
unsigned getCharacterLiteralAbbrev() const
void * getAsOpaquePtr() const
Represents an ObjC class declaration.
unsigned getTypeFunctionProtoAbbrev() const
Sema - This implements semantic analysis and AST building for C.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
This represents one expression.
Represents a C++ destructor within a class.
unsigned getDeclRecordAbbrev() const
IdentifierResolver - Keeps track of shadowed decls on enclosing scopes.
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
unsigned getDeclTypedefAbbrev() const
Abstract base class that writes a module file extension block into a module file. ...
In-memory cache for modules.
const unsigned int NUM_PREDEF_IDENT_IDS
The number of predefined identifier IDs.
uint32_t SubmoduleID
An ID number that refers to a submodule in a module file.
Encodes a location in the source.
unsigned getDeclVarAbbrev() const
Represents the declaration of a struct/union/class/enum.
Cached information about one file (either on disk or in the virtual file system). ...
ObjCCategoryDecl - Represents a category declaration.
unsigned getDeclCXXMethodAbbrev() const
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
uint32_t TypeID
An ID number that refers to a type in an AST file.
An array of decls optimized for the common case of only containing one entry.
uint32_t PreprocessedEntityID
An ID number that refers to an entity in the detailed preprocessing record.
unsigned getExprImplicitCastAbbrev() const
unsigned getTypeExtQualAbbrev() const
uint32_t SelectorID
An ID number that refers to an ObjC selector in an AST file.
Dataflow Directional Tag Classes.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Reads an AST files chain containing the contents of a translation unit.
unsigned getDeclParmVarAbbrev() const
uint32_t DeclID
An ID number that refers to a declaration in an AST file.
bool IsLocalDecl(const Decl *D)
Is this a local declaration (that is, one that will be written to our AST file)? This is the case for...
Encapsulates the data about a macro definition (e.g.
uint32_t IdentID
An ID number that refers to an identifier in an AST file.
const unsigned int NUM_PREDEF_MACRO_IDS
The number of predefined macro IDs.
Defines the clang::SourceLocation class and associated facilities.
Represents a C++ struct/union/class.
An object for streaming information to a record.
Declaration of a class template.
Writes an AST file containing the contents of a translation unit.
static Decl::Kind getKind(const Decl *D)
AST and semantic-analysis consumer that generates a precompiled header from the parsed source code...
A trivial tuple used to represent a source range.
This represents a decl that may have a name.
unsigned getDeclObjCIvarAbbrev() const
This class handles loading and caching of source files into memory.
Declaration of a template function.
A type index; the type ID with the qualifier bits removed.
Attr - This represents one attribute.
const unsigned int NUM_PREDEF_SUBMODULE_IDS
The number of predefined submodule IDs.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.