diff options
author | dim <dim@FreeBSD.org> | 2010-09-17 15:54:40 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2010-09-17 15:54:40 +0000 |
commit | 36c49e3f258dced101949edabd72e9bc3f1dedc4 (patch) | |
tree | 0bbe07708f7571f8b5291f6d7b96c102b7c99dee /include/clang/Serialization | |
parent | fc84956ac8b7cd244ef30e7a4d4d38a58dec5904 (diff) | |
download | FreeBSD-src-36c49e3f258dced101949edabd72e9bc3f1dedc4.zip FreeBSD-src-36c49e3f258dced101949edabd72e9bc3f1dedc4.tar.gz |
Vendor import of clang r114020 (from the release_28 branch):
http://llvm.org/svn/llvm-project/cfe/branches/release_28@114020
Approved by: rpaulo (mentor)
Diffstat (limited to 'include/clang/Serialization')
-rw-r--r-- | include/clang/Serialization/ASTBitCodes.h | 917 | ||||
-rw-r--r-- | include/clang/Serialization/ASTDeserializationListener.h | 49 | ||||
-rw-r--r-- | include/clang/Serialization/ASTReader.h | 1100 | ||||
-rw-r--r-- | include/clang/Serialization/ASTWriter.h | 513 | ||||
-rw-r--r-- | include/clang/Serialization/CMakeLists.txt | 12 | ||||
-rw-r--r-- | include/clang/Serialization/Makefile | 19 |
6 files changed, 2610 insertions, 0 deletions
diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h new file mode 100644 index 0000000..0fa446d --- /dev/null +++ b/include/clang/Serialization/ASTBitCodes.h @@ -0,0 +1,917 @@ +//===- ASTBitCodes.h - Enum values for the PCH bitcode format ---*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This header defines Bitcode enum values for Clang serialized AST files. +// +// The enum values defined in this file should be considered permanent. If +// new features are added, they should have values added at the end of the +// respective lists. +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_CLANG_FRONTEND_PCHBITCODES_H +#define LLVM_CLANG_FRONTEND_PCHBITCODES_H + +#include "clang/AST/Type.h" +#include "llvm/Bitcode/BitCodes.h" +#include "llvm/System/DataTypes.h" +#include "llvm/ADT/DenseMap.h" + +namespace clang { + namespace serialization { + /// \brief AST file major version number supported by this version of + /// Clang. + /// + /// Whenever the AST file format changes in a way that makes it + /// incompatible with previous versions (such that a reader + /// designed for the previous version could not support reading + /// the new version), this number should be increased. + /// + /// Version 4 of AST files also requires that the version control branch and + /// revision match exactly, since there is no backward compatibility of + /// AST files at this time. + const unsigned VERSION_MAJOR = 4; + + /// \brief AST file minor version number supported by this version of + /// Clang. + /// + /// Whenever the AST format changes in a way that is still + /// compatible with previous versions (such that a reader designed + /// for the previous version could still support reading the new + /// version by ignoring new kinds of subblocks), this number + /// should be increased. + const unsigned VERSION_MINOR = 0; + + /// \brief An ID number that refers to a declaration in an AST file. + /// + /// The ID numbers of declarations are consecutive (in order of + /// discovery) and start at 2. 0 is reserved for NULL, and 1 is + /// reserved for the translation unit declaration. + typedef uint32_t DeclID; + + /// \brief An ID number that refers to a type in an AST file. + /// + /// The ID of a type is partitioned into two parts: the lower + /// three bits are used to store the const/volatile/restrict + /// qualifiers (as with QualType) and the upper bits provide a + /// type index. The type index values are partitioned into two + /// sets. The values below NUM_PREDEF_TYPE_IDs are predefined type + /// IDs (based on the PREDEF_TYPE_*_ID constants), with 0 as a + /// placeholder for "no type". Values from NUM_PREDEF_TYPE_IDs are + /// other types that have serialized representations. + typedef uint32_t TypeID; + + /// \brief A type index; the type ID with the qualifier bits removed. + class TypeIdx { + uint32_t Idx; + public: + TypeIdx() : Idx(0) { } + explicit TypeIdx(uint32_t index) : Idx(index) { } + + uint32_t getIndex() const { return Idx; } + TypeID asTypeID(unsigned FastQuals) const { + return (Idx << Qualifiers::FastWidth) | FastQuals; + } + static TypeIdx fromTypeID(TypeID ID) { + return TypeIdx(ID >> Qualifiers::FastWidth); + } + }; + + /// A structure for putting "fast"-unqualified QualTypes into a + /// DenseMap. This uses the standard pointer hash function. + struct UnsafeQualTypeDenseMapInfo { + static inline bool isEqual(QualType A, QualType B) { return A == B; } + static inline QualType getEmptyKey() { + return QualType::getFromOpaquePtr((void*) 1); + } + static inline QualType getTombstoneKey() { + return QualType::getFromOpaquePtr((void*) 2); + } + static inline unsigned getHashValue(QualType T) { + assert(!T.getLocalFastQualifiers() && + "hash invalid for types with fast quals"); + uintptr_t v = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr()); + return (unsigned(v) >> 4) ^ (unsigned(v) >> 9); + } + }; + + /// \brief Map that provides the ID numbers of each type within the + /// output stream, plus those deserialized from a chained PCH. + /// + /// The ID numbers of types are consecutive (in order of discovery) + /// and start at 1. 0 is reserved for NULL. When types are actually + /// stored in the stream, the ID number is shifted by 2 bits to + /// allow for the const/volatile qualifiers. + /// + /// Keys in the map never have const/volatile qualifiers. + typedef llvm::DenseMap<QualType, TypeIdx, UnsafeQualTypeDenseMapInfo> + TypeIdxMap; + + /// \brief An ID number that refers to an identifier in an AST + /// file. + typedef uint32_t IdentID; + + typedef uint32_t SelectorID; + + /// \brief Describes the various kinds of blocks that occur within + /// an AST file. + enum BlockIDs { + /// \brief The AST block, which acts as a container around the + /// full AST block. + AST_BLOCK_ID = llvm::bitc::FIRST_APPLICATION_BLOCKID, + + /// \brief The block containing information about the source + /// manager. + SOURCE_MANAGER_BLOCK_ID, + + /// \brief The block containing information about the + /// preprocessor. + PREPROCESSOR_BLOCK_ID, + + /// \brief The block containing the definitions of all of the + /// types and decls used within the AST file. + DECLTYPES_BLOCK_ID + }; + + /// \brief Record types that occur within the AST block itself. + enum ASTRecordTypes { + /// \brief Record code for the offsets of each type. + /// + /// The TYPE_OFFSET constant describes the record that occurs + /// within the AST block. The record itself is an array of offsets that + /// point into the declarations and types block (identified by + /// DECLTYPES_BLOCK_ID). The index into the array is based on the ID + /// of a type. For a given type ID @c T, the lower three bits of + /// @c T are its qualifiers (const, volatile, restrict), as in + /// the QualType class. The upper bits, after being shifted and + /// subtracting NUM_PREDEF_TYPE_IDS, are used to index into the + /// TYPE_OFFSET block to determine the offset of that type's + /// corresponding record within the DECLTYPES_BLOCK_ID block. + TYPE_OFFSET = 1, + + /// \brief Record code for the offsets of each decl. + /// + /// The DECL_OFFSET constant describes the record that occurs + /// within the block identified by DECL_OFFSETS_BLOCK_ID within + /// the AST block. The record itself is an array of offsets that + /// point into the declarations and types block (identified by + /// DECLTYPES_BLOCK_ID). The declaration ID is an index into this + /// record, after subtracting one to account for the use of + /// declaration ID 0 for a NULL declaration pointer. Index 0 is + /// reserved for the translation unit declaration. + DECL_OFFSET = 2, + + /// \brief Record code for the language options table. + /// + /// The record with this code contains the contents of the + /// LangOptions structure. We serialize the entire contents of + /// the structure, and let the reader decide which options are + /// actually important to check. + LANGUAGE_OPTIONS = 3, + + /// \brief AST file metadata, including the AST file version number + /// and the target triple used to build the AST file. + METADATA = 4, + + /// \brief Record code for the table of offsets of each + /// identifier ID. + /// + /// The offset table contains offsets into the blob stored in + /// the IDENTIFIER_TABLE record. Each offset points to the + /// NULL-terminated string that corresponds to that identifier. + IDENTIFIER_OFFSET = 5, + + /// \brief Record code for the identifier table. + /// + /// The identifier table is a simple blob that contains + /// NULL-terminated strings for all of the identifiers + /// referenced by the AST file. The IDENTIFIER_OFFSET table + /// contains the mapping from identifier IDs to the characters + /// in this blob. Note that the starting offsets of all of the + /// identifiers are odd, so that, when the identifier offset + /// table is loaded in, we can use the low bit to distinguish + /// between offsets (for unresolved identifier IDs) and + /// IdentifierInfo pointers (for already-resolved identifier + /// IDs). + IDENTIFIER_TABLE = 6, + + /// \brief Record code for the array of external definitions. + /// + /// The AST file contains a list of all of the unnamed external + /// definitions present within the parsed headers, stored as an + /// array of declaration IDs. These external definitions will be + /// reported to the AST consumer after the AST file has been + /// read, since their presence can affect the semantics of the + /// program (e.g., for code generation). + EXTERNAL_DEFINITIONS = 7, + + /// \brief Record code for the set of non-builtin, special + /// types. + /// + /// This record contains the type IDs for the various type nodes + /// that are constructed during semantic analysis (e.g., + /// __builtin_va_list). The SPECIAL_TYPE_* constants provide + /// offsets into this record. + SPECIAL_TYPES = 8, + + /// \brief Record code for the extra statistics we gather while + /// generating an AST file. + STATISTICS = 9, + + /// \brief Record code for the array of tentative definitions. + TENTATIVE_DEFINITIONS = 10, + + /// \brief Record code for the array of locally-scoped external + /// declarations. + LOCALLY_SCOPED_EXTERNAL_DECLS = 11, + + /// \brief Record code for the table of offsets into the + /// Objective-C method pool. + SELECTOR_OFFSETS = 12, + + /// \brief Record code for the Objective-C method pool, + METHOD_POOL = 13, + + /// \brief The value of the next __COUNTER__ to dispense. + /// [PP_COUNTER_VALUE, Val] + PP_COUNTER_VALUE = 14, + + /// \brief Record code for the table of offsets into the block + /// of source-location information. + SOURCE_LOCATION_OFFSETS = 15, + + /// \brief Record code for the set of source location entries + /// that need to be preloaded by the AST reader. + /// + /// This set contains the source location entry for the + /// predefines buffer and for any file entries that need to be + /// preloaded. + SOURCE_LOCATION_PRELOADS = 16, + + /// \brief Record code for the stat() cache. + STAT_CACHE = 17, + + /// \brief Record code for the set of ext_vector type names. + EXT_VECTOR_DECLS = 18, + + /// \brief Record code for the original file that was used to + /// generate the AST file. + ORIGINAL_FILE_NAME = 19, + + /// Record #20 intentionally left blank. + + /// \brief Record code for the version control branch and revision + /// information of the compiler used to build this AST file. + VERSION_CONTROL_BRANCH_REVISION = 21, + + /// \brief Record code for the array of unused file scoped decls. + UNUSED_FILESCOPED_DECLS = 22, + + /// \brief Record code for the table of offsets to macro definition + /// entries in the preprocessing record. + MACRO_DEFINITION_OFFSETS = 23, + + /// \brief Record code for the array of VTable uses. + VTABLE_USES = 24, + + /// \brief Record code for the array of dynamic classes. + DYNAMIC_CLASSES = 25, + + /// \brief Record code for the chained AST metadata, including the + /// AST file version and the name of the PCH this depends on. + CHAINED_METADATA = 26, + + /// \brief Record code for referenced selector pool. + REFERENCED_SELECTOR_POOL = 27, + + /// \brief Record code for an update to the TU's lexically contained + /// declarations. + TU_UPDATE_LEXICAL = 28, + + /// \brief Record code for an update to first decls pointing to the + /// latest redeclarations. + REDECLS_UPDATE_LATEST = 29, + + /// \brief Record code for declarations that Sema keeps references of. + SEMA_DECL_REFS = 30, + + /// \brief Record code for weak undeclared identifiers. + WEAK_UNDECLARED_IDENTIFIERS = 31, + + /// \brief Record code for pending implicit instantiations. + PENDING_IMPLICIT_INSTANTIATIONS = 32, + + /// \brief Record code for a decl replacement block. + /// + /// If a declaration is modified after having been deserialized, and then + /// written to a dependent AST file, its ID and offset must be added to + /// the replacement block. + DECL_REPLACEMENTS = 33, + + /// \brief Record code for an update to a decl context's lookup table. + /// + /// In practice, this should only be used for the TU and namespaces. + UPDATE_VISIBLE = 34, + + /// \brief Record code for template specializations introduced after + /// serializations of the original template decl. + ADDITIONAL_TEMPLATE_SPECIALIZATIONS = 35 + }; + + /// \brief Record types used within a source manager block. + enum SourceManagerRecordTypes { + /// \brief Describes a source location entry (SLocEntry) for a + /// file. + SM_SLOC_FILE_ENTRY = 1, + /// \brief Describes a source location entry (SLocEntry) for a + /// buffer. + SM_SLOC_BUFFER_ENTRY = 2, + /// \brief Describes a blob that contains the data for a buffer + /// entry. This kind of record always directly follows a + /// SM_SLOC_BUFFER_ENTRY record. + SM_SLOC_BUFFER_BLOB = 3, + /// \brief Describes a source location entry (SLocEntry) for a + /// macro instantiation. + SM_SLOC_INSTANTIATION_ENTRY = 4, + /// \brief Describes the SourceManager's line table, with + /// information about #line directives. + SM_LINE_TABLE = 5 + }; + + /// \brief Record types used within a preprocessor block. + enum PreprocessorRecordTypes { + // The macros in the PP section are a PP_MACRO_* instance followed by a + // list of PP_TOKEN instances for each token in the definition. + + /// \brief An object-like macro definition. + /// [PP_MACRO_OBJECT_LIKE, IdentInfoID, SLoc, IsUsed] + PP_MACRO_OBJECT_LIKE = 1, + + /// \brief A function-like macro definition. + /// [PP_MACRO_FUNCTION_LIKE, <ObjectLikeStuff>, IsC99Varargs, IsGNUVarars, + /// NumArgs, ArgIdentInfoID* ] + PP_MACRO_FUNCTION_LIKE = 2, + + /// \brief Describes one token. + /// [PP_TOKEN, SLoc, Length, IdentInfoID, Kind, Flags] + PP_TOKEN = 3, + + /// \brief Describes a macro instantiation within the preprocessing + /// record. + PP_MACRO_INSTANTIATION = 4, + + /// \brief Describes a macro definition within the preprocessing record. + PP_MACRO_DEFINITION = 5 + }; + + /// \defgroup ASTAST AST file AST constants + /// + /// The constants in this group describe various components of the + /// abstract syntax tree within an AST file. + /// + /// @{ + + /// \brief Predefined type IDs. + /// + /// These type IDs correspond to predefined types in the AST + /// context, such as built-in types (int) and special place-holder + /// types (the <overload> and <dependent> type markers). Such + /// types are never actually serialized, since they will be built + /// by the AST context when it is created. + enum PredefinedTypeIDs { + /// \brief The NULL type. + PREDEF_TYPE_NULL_ID = 0, + /// \brief The void type. + PREDEF_TYPE_VOID_ID = 1, + /// \brief The 'bool' or '_Bool' type. + PREDEF_TYPE_BOOL_ID = 2, + /// \brief The 'char' type, when it is unsigned. + PREDEF_TYPE_CHAR_U_ID = 3, + /// \brief The 'unsigned char' type. + PREDEF_TYPE_UCHAR_ID = 4, + /// \brief The 'unsigned short' type. + PREDEF_TYPE_USHORT_ID = 5, + /// \brief The 'unsigned int' type. + PREDEF_TYPE_UINT_ID = 6, + /// \brief The 'unsigned long' type. + PREDEF_TYPE_ULONG_ID = 7, + /// \brief The 'unsigned long long' type. + PREDEF_TYPE_ULONGLONG_ID = 8, + /// \brief The 'char' type, when it is signed. + PREDEF_TYPE_CHAR_S_ID = 9, + /// \brief The 'signed char' type. + PREDEF_TYPE_SCHAR_ID = 10, + /// \brief The C++ 'wchar_t' type. + PREDEF_TYPE_WCHAR_ID = 11, + /// \brief The (signed) 'short' type. + PREDEF_TYPE_SHORT_ID = 12, + /// \brief The (signed) 'int' type. + PREDEF_TYPE_INT_ID = 13, + /// \brief The (signed) 'long' type. + PREDEF_TYPE_LONG_ID = 14, + /// \brief The (signed) 'long long' type. + PREDEF_TYPE_LONGLONG_ID = 15, + /// \brief The 'float' type. + PREDEF_TYPE_FLOAT_ID = 16, + /// \brief The 'double' type. + PREDEF_TYPE_DOUBLE_ID = 17, + /// \brief The 'long double' type. + PREDEF_TYPE_LONGDOUBLE_ID = 18, + /// \brief The placeholder type for overloaded function sets. + PREDEF_TYPE_OVERLOAD_ID = 19, + /// \brief The placeholder type for dependent types. + PREDEF_TYPE_DEPENDENT_ID = 20, + /// \brief The '__uint128_t' type. + PREDEF_TYPE_UINT128_ID = 21, + /// \brief The '__int128_t' type. + PREDEF_TYPE_INT128_ID = 22, + /// \brief The type of 'nullptr'. + PREDEF_TYPE_NULLPTR_ID = 23, + /// \brief The C++ 'char16_t' type. + PREDEF_TYPE_CHAR16_ID = 24, + /// \brief The C++ 'char32_t' type. + PREDEF_TYPE_CHAR32_ID = 25, + /// \brief The ObjC 'id' type. + PREDEF_TYPE_OBJC_ID = 26, + /// \brief The ObjC 'Class' type. + PREDEF_TYPE_OBJC_CLASS = 27, + /// \brief The ObjC 'SEL' type. + PREDEF_TYPE_OBJC_SEL = 28 + }; + + /// \brief The number of predefined type IDs that are reserved for + /// the PREDEF_TYPE_* constants. + /// + /// Type IDs for non-predefined types will start at + /// NUM_PREDEF_TYPE_IDs. + const unsigned NUM_PREDEF_TYPE_IDS = 100; + + /// \brief Record codes for each kind of type. + /// + /// These constants describe the type records that can occur within a + /// block identified by DECLTYPES_BLOCK_ID in the AST file. Each + /// constant describes a record for a specific type class in the + /// AST. + enum TypeCode { + /// \brief An ExtQualType record. + TYPE_EXT_QUAL = 1, + /// \brief A ComplexType record. + TYPE_COMPLEX = 3, + /// \brief A PointerType record. + TYPE_POINTER = 4, + /// \brief A BlockPointerType record. + TYPE_BLOCK_POINTER = 5, + /// \brief An LValueReferenceType record. + TYPE_LVALUE_REFERENCE = 6, + /// \brief An RValueReferenceType record. + TYPE_RVALUE_REFERENCE = 7, + /// \brief A MemberPointerType record. + TYPE_MEMBER_POINTER = 8, + /// \brief A ConstantArrayType record. + TYPE_CONSTANT_ARRAY = 9, + /// \brief An IncompleteArrayType record. + TYPE_INCOMPLETE_ARRAY = 10, + /// \brief A VariableArrayType record. + TYPE_VARIABLE_ARRAY = 11, + /// \brief A VectorType record. + TYPE_VECTOR = 12, + /// \brief An ExtVectorType record. + TYPE_EXT_VECTOR = 13, + /// \brief A FunctionNoProtoType record. + TYPE_FUNCTION_NO_PROTO = 14, + /// \brief A FunctionProtoType record. + TYPE_FUNCTION_PROTO = 15, + /// \brief A TypedefType record. + TYPE_TYPEDEF = 16, + /// \brief A TypeOfExprType record. + TYPE_TYPEOF_EXPR = 17, + /// \brief A TypeOfType record. + TYPE_TYPEOF = 18, + /// \brief A RecordType record. + TYPE_RECORD = 19, + /// \brief An EnumType record. + TYPE_ENUM = 20, + /// \brief An ObjCInterfaceType record. + TYPE_OBJC_INTERFACE = 21, + /// \brief An ObjCObjectPointerType record. + TYPE_OBJC_OBJECT_POINTER = 22, + /// \brief a DecltypeType record. + TYPE_DECLTYPE = 23, + /// \brief An ElaboratedType record. + TYPE_ELABORATED = 24, + /// \brief A SubstTemplateTypeParmType record. + TYPE_SUBST_TEMPLATE_TYPE_PARM = 25, + /// \brief An UnresolvedUsingType record. + TYPE_UNRESOLVED_USING = 26, + /// \brief An InjectedClassNameType record. + TYPE_INJECTED_CLASS_NAME = 27, + /// \brief An ObjCObjectType record. + TYPE_OBJC_OBJECT = 28, + /// \brief An TemplateTypeParmType record. + TYPE_TEMPLATE_TYPE_PARM = 29, + /// \brief An TemplateSpecializationType record. + TYPE_TEMPLATE_SPECIALIZATION = 30, + /// \brief A DependentNameType record. + TYPE_DEPENDENT_NAME = 31, + /// \brief A DependentTemplateSpecializationType record. + TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION = 32, + /// \brief A DependentSizedArrayType record. + TYPE_DEPENDENT_SIZED_ARRAY = 33 + }; + + /// \brief The type IDs for special types constructed by semantic + /// analysis. + /// + /// The constants in this enumeration are indices into the + /// SPECIAL_TYPES record. + enum SpecialTypeIDs { + /// \brief __builtin_va_list + SPECIAL_TYPE_BUILTIN_VA_LIST = 0, + /// \brief Objective-C "id" type + SPECIAL_TYPE_OBJC_ID = 1, + /// \brief Objective-C selector type + SPECIAL_TYPE_OBJC_SELECTOR = 2, + /// \brief Objective-C Protocol type + SPECIAL_TYPE_OBJC_PROTOCOL = 3, + /// \brief Objective-C Class type + SPECIAL_TYPE_OBJC_CLASS = 4, + /// \brief CFConstantString type + SPECIAL_TYPE_CF_CONSTANT_STRING = 5, + /// \brief Objective-C fast enumeration state type + SPECIAL_TYPE_OBJC_FAST_ENUMERATION_STATE = 6, + /// \brief C FILE typedef type + SPECIAL_TYPE_FILE = 7, + /// \brief C jmp_buf typedef type + SPECIAL_TYPE_jmp_buf = 8, + /// \brief C sigjmp_buf typedef type + SPECIAL_TYPE_sigjmp_buf = 9, + /// \brief Objective-C "id" redefinition type + SPECIAL_TYPE_OBJC_ID_REDEFINITION = 10, + /// \brief Objective-C "Class" redefinition type + SPECIAL_TYPE_OBJC_CLASS_REDEFINITION = 11, + /// \brief Block descriptor type for Blocks CodeGen + SPECIAL_TYPE_BLOCK_DESCRIPTOR = 12, + /// \brief Block extedned descriptor type for Blocks CodeGen + SPECIAL_TYPE_BLOCK_EXTENDED_DESCRIPTOR = 13, + /// \brief Objective-C "SEL" redefinition type + SPECIAL_TYPE_OBJC_SEL_REDEFINITION = 14, + /// \brief NSConstantString type + SPECIAL_TYPE_NS_CONSTANT_STRING = 15, + /// \brief Whether __[u]int128_t identifier is installed. + SPECIAL_TYPE_INT128_INSTALLED = 16 + }; + + /// \brief Record codes for each kind of declaration. + /// + /// These constants describe the declaration records that can occur within + /// a declarations block (identified by DECLS_BLOCK_ID). Each + /// constant describes a record for a specific declaration class + /// in the AST. + enum DeclCode { + /// \brief Attributes attached to a declaration. + DECL_ATTR = 50, + /// \brief A TranslationUnitDecl record. + DECL_TRANSLATION_UNIT, + /// \brief A TypedefDecl record. + DECL_TYPEDEF, + /// \brief An EnumDecl record. + DECL_ENUM, + /// \brief A RecordDecl record. + DECL_RECORD, + /// \brief An EnumConstantDecl record. + DECL_ENUM_CONSTANT, + /// \brief A FunctionDecl record. + DECL_FUNCTION, + /// \brief A ObjCMethodDecl record. + DECL_OBJC_METHOD, + /// \brief A ObjCInterfaceDecl record. + DECL_OBJC_INTERFACE, + /// \brief A ObjCProtocolDecl record. + DECL_OBJC_PROTOCOL, + /// \brief A ObjCIvarDecl record. + DECL_OBJC_IVAR, + /// \brief A ObjCAtDefsFieldDecl record. + DECL_OBJC_AT_DEFS_FIELD, + /// \brief A ObjCClassDecl record. + DECL_OBJC_CLASS, + /// \brief A ObjCForwardProtocolDecl record. + DECL_OBJC_FORWARD_PROTOCOL, + /// \brief A ObjCCategoryDecl record. + DECL_OBJC_CATEGORY, + /// \brief A ObjCCategoryImplDecl record. + DECL_OBJC_CATEGORY_IMPL, + /// \brief A ObjCImplementationDecl record. + DECL_OBJC_IMPLEMENTATION, + /// \brief A ObjCCompatibleAliasDecl record. + DECL_OBJC_COMPATIBLE_ALIAS, + /// \brief A ObjCPropertyDecl record. + DECL_OBJC_PROPERTY, + /// \brief A ObjCPropertyImplDecl record. + DECL_OBJC_PROPERTY_IMPL, + /// \brief A FieldDecl record. + DECL_FIELD, + /// \brief A VarDecl record. + DECL_VAR, + /// \brief An ImplicitParamDecl record. + DECL_IMPLICIT_PARAM, + /// \brief A ParmVarDecl record. + DECL_PARM_VAR, + /// \brief A FileScopeAsmDecl record. + DECL_FILE_SCOPE_ASM, + /// \brief A BlockDecl record. + DECL_BLOCK, + /// \brief A record that stores the set of declarations that are + /// lexically stored within a given DeclContext. + /// + /// The record itself is a blob that is an array of declaration IDs, + /// in the order in which those declarations were added to the + /// declaration context. This data is used when iterating over + /// the contents of a DeclContext, e.g., via + /// DeclContext::decls_begin()/DeclContext::decls_end(). + DECL_CONTEXT_LEXICAL, + /// \brief A record that stores the set of declarations that are + /// visible from a given DeclContext. + /// + /// The record itself stores a set of mappings, each of which + /// associates a declaration name with one or more declaration + /// IDs. This data is used when performing qualified name lookup + /// into a DeclContext via DeclContext::lookup. + DECL_CONTEXT_VISIBLE, + /// \brief A NamespaceDecl rcord. + DECL_NAMESPACE, + /// \brief A NamespaceAliasDecl record. + DECL_NAMESPACE_ALIAS, + /// \brief A UsingDecl record. + DECL_USING, + /// \brief A UsingShadowDecl record. + DECL_USING_SHADOW, + /// \brief A UsingDirecitveDecl record. + DECL_USING_DIRECTIVE, + /// \brief An UnresolvedUsingValueDecl record. + DECL_UNRESOLVED_USING_VALUE, + /// \brief An UnresolvedUsingTypenameDecl record. + DECL_UNRESOLVED_USING_TYPENAME, + /// \brief A LinkageSpecDecl record. + DECL_LINKAGE_SPEC, + /// \brief A CXXRecordDecl record. + DECL_CXX_RECORD, + /// \brief A CXXMethodDecl record. + DECL_CXX_METHOD, + /// \brief A CXXConstructorDecl record. + DECL_CXX_CONSTRUCTOR, + /// \brief A CXXDestructorDecl record. + DECL_CXX_DESTRUCTOR, + /// \brief A CXXConversionDecl record. + DECL_CXX_CONVERSION, + /// \brief An AccessSpecDecl record. + DECL_ACCESS_SPEC, + + /// \brief A FriendDecl record. + DECL_FRIEND, + /// \brief A FriendTemplateDecl record. + DECL_FRIEND_TEMPLATE, + /// \brief A ClassTemplateDecl record. + DECL_CLASS_TEMPLATE, + /// \brief A ClassTemplateSpecializationDecl record. + DECL_CLASS_TEMPLATE_SPECIALIZATION, + /// \brief A ClassTemplatePartialSpecializationDecl record. + DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION, + /// \brief A FunctionTemplateDecl record. + DECL_FUNCTION_TEMPLATE, + /// \brief A TemplateTypeParmDecl record. + DECL_TEMPLATE_TYPE_PARM, + /// \brief A NonTypeTemplateParmDecl record. + DECL_NON_TYPE_TEMPLATE_PARM, + /// \brief A TemplateTemplateParmDecl record. + DECL_TEMPLATE_TEMPLATE_PARM, + /// \brief A StaticAssertDecl record. + DECL_STATIC_ASSERT + }; + + /// \brief Record codes for each kind of statement or expression. + /// + /// These constants describe the records that describe statements + /// or expressions. These records occur within type and declarations + /// block, so they begin with record values of 100. Each constant + /// describes a record for a specific statement or expression class in the + /// AST. + enum StmtCode { + /// \brief A marker record that indicates that we are at the end + /// of an expression. + STMT_STOP = 100, + /// \brief A NULL expression. + STMT_NULL_PTR, + /// \brief A NullStmt record. + STMT_NULL, + /// \brief A CompoundStmt record. + STMT_COMPOUND, + /// \brief A CaseStmt record. + STMT_CASE, + /// \brief A DefaultStmt record. + STMT_DEFAULT, + /// \brief A LabelStmt record. + STMT_LABEL, + /// \brief An IfStmt record. + STMT_IF, + /// \brief A SwitchStmt record. + STMT_SWITCH, + /// \brief A WhileStmt record. + STMT_WHILE, + /// \brief A DoStmt record. + STMT_DO, + /// \brief A ForStmt record. + STMT_FOR, + /// \brief A GotoStmt record. + STMT_GOTO, + /// \brief An IndirectGotoStmt record. + STMT_INDIRECT_GOTO, + /// \brief A ContinueStmt record. + STMT_CONTINUE, + /// \brief A BreakStmt record. + STMT_BREAK, + /// \brief A ReturnStmt record. + STMT_RETURN, + /// \brief A DeclStmt record. + STMT_DECL, + /// \brief An AsmStmt record. + STMT_ASM, + /// \brief A PredefinedExpr record. + EXPR_PREDEFINED, + /// \brief A DeclRefExpr record. + EXPR_DECL_REF, + /// \brief An IntegerLiteral record. + EXPR_INTEGER_LITERAL, + /// \brief A FloatingLiteral record. + EXPR_FLOATING_LITERAL, + /// \brief An ImaginaryLiteral record. + EXPR_IMAGINARY_LITERAL, + /// \brief A StringLiteral record. + EXPR_STRING_LITERAL, + /// \brief A CharacterLiteral record. + EXPR_CHARACTER_LITERAL, + /// \brief A ParenExpr record. + EXPR_PAREN, + /// \brief A ParenListExpr record. + EXPR_PAREN_LIST, + /// \brief A UnaryOperator record. + EXPR_UNARY_OPERATOR, + /// \brief An OffsetOfExpr record. + EXPR_OFFSETOF, + /// \brief A SizefAlignOfExpr record. + EXPR_SIZEOF_ALIGN_OF, + /// \brief An ArraySubscriptExpr record. + EXPR_ARRAY_SUBSCRIPT, + /// \brief A CallExpr record. + EXPR_CALL, + /// \brief A MemberExpr record. + EXPR_MEMBER, + /// \brief A BinaryOperator record. + EXPR_BINARY_OPERATOR, + /// \brief A CompoundAssignOperator record. + EXPR_COMPOUND_ASSIGN_OPERATOR, + /// \brief A ConditionOperator record. + EXPR_CONDITIONAL_OPERATOR, + /// \brief An ImplicitCastExpr record. + EXPR_IMPLICIT_CAST, + /// \brief A CStyleCastExpr record. + EXPR_CSTYLE_CAST, + /// \brief A CompoundLiteralExpr record. + EXPR_COMPOUND_LITERAL, + /// \brief An ExtVectorElementExpr record. + EXPR_EXT_VECTOR_ELEMENT, + /// \brief An InitListExpr record. + EXPR_INIT_LIST, + /// \brief A DesignatedInitExpr record. + EXPR_DESIGNATED_INIT, + /// \brief An ImplicitValueInitExpr record. + EXPR_IMPLICIT_VALUE_INIT, + /// \brief A VAArgExpr record. + EXPR_VA_ARG, + /// \brief An AddrLabelExpr record. + EXPR_ADDR_LABEL, + /// \brief A StmtExpr record. + EXPR_STMT, + /// \brief A TypesCompatibleExpr record. + EXPR_TYPES_COMPATIBLE, + /// \brief A ChooseExpr record. + EXPR_CHOOSE, + /// \brief A GNUNullExpr record. + EXPR_GNU_NULL, + /// \brief A ShuffleVectorExpr record. + EXPR_SHUFFLE_VECTOR, + /// \brief BlockExpr + EXPR_BLOCK, + /// \brief A BlockDeclRef record. + EXPR_BLOCK_DECL_REF, + + // Objective-C + + /// \brief An ObjCStringLiteral record. + EXPR_OBJC_STRING_LITERAL, + /// \brief An ObjCEncodeExpr record. + EXPR_OBJC_ENCODE, + /// \brief An ObjCSelectorExpr record. + EXPR_OBJC_SELECTOR_EXPR, + /// \brief An ObjCProtocolExpr record. + EXPR_OBJC_PROTOCOL_EXPR, + /// \brief An ObjCIvarRefExpr record. + EXPR_OBJC_IVAR_REF_EXPR, + /// \brief An ObjCPropertyRefExpr record. + EXPR_OBJC_PROPERTY_REF_EXPR, + /// \brief An ObjCImplicitSetterGetterRefExpr record. + EXPR_OBJC_KVC_REF_EXPR, + /// \brief An ObjCMessageExpr record. + EXPR_OBJC_MESSAGE_EXPR, + /// \brief An ObjCSuperExpr record. + EXPR_OBJC_SUPER_EXPR, + /// \brief An ObjCIsa Expr record. + EXPR_OBJC_ISA, + + /// \brief An ObjCForCollectionStmt record. + STMT_OBJC_FOR_COLLECTION, + /// \brief An ObjCAtCatchStmt record. + STMT_OBJC_CATCH, + /// \brief An ObjCAtFinallyStmt record. + STMT_OBJC_FINALLY, + /// \brief An ObjCAtTryStmt record. + STMT_OBJC_AT_TRY, + /// \brief An ObjCAtSynchronizedStmt record. + STMT_OBJC_AT_SYNCHRONIZED, + /// \brief An ObjCAtThrowStmt record. + STMT_OBJC_AT_THROW, + + // C++ + + /// \brief A CXXCatchStmt record. + STMT_CXX_CATCH, + /// \brief A CXXTryStmt record. + STMT_CXX_TRY, + + /// \brief A CXXOperatorCallExpr record. + EXPR_CXX_OPERATOR_CALL, + /// \brief A CXXMemberCallExpr record. + EXPR_CXX_MEMBER_CALL, + /// \brief A CXXConstructExpr record. + EXPR_CXX_CONSTRUCT, + /// \brief A CXXTemporaryObjectExpr record. + EXPR_CXX_TEMPORARY_OBJECT, + /// \brief A CXXStaticCastExpr record. + EXPR_CXX_STATIC_CAST, + /// \brief A CXXDynamicCastExpr record. + EXPR_CXX_DYNAMIC_CAST, + /// \brief A CXXReinterpretCastExpr record. + EXPR_CXX_REINTERPRET_CAST, + /// \brief A CXXConstCastExpr record. + EXPR_CXX_CONST_CAST, + /// \brief A CXXFunctionalCastExpr record. + EXPR_CXX_FUNCTIONAL_CAST, + /// \brief A CXXBoolLiteralExpr record. + EXPR_CXX_BOOL_LITERAL, + EXPR_CXX_NULL_PTR_LITERAL, // CXXNullPtrLiteralExpr + EXPR_CXX_TYPEID_EXPR, // CXXTypeidExpr (of expr). + EXPR_CXX_TYPEID_TYPE, // CXXTypeidExpr (of type). + EXPR_CXX_THIS, // CXXThisExpr + EXPR_CXX_THROW, // CXXThrowExpr + EXPR_CXX_DEFAULT_ARG, // CXXDefaultArgExpr + EXPR_CXX_BIND_TEMPORARY, // CXXBindTemporaryExpr + + EXPR_CXX_SCALAR_VALUE_INIT, // CXXScalarValueInitExpr + EXPR_CXX_NEW, // CXXNewExpr + EXPR_CXX_DELETE, // CXXDeleteExpr + EXPR_CXX_PSEUDO_DESTRUCTOR, // CXXPseudoDestructorExpr + + EXPR_CXX_EXPR_WITH_TEMPORARIES, // CXXExprWithTemporaries + + EXPR_CXX_DEPENDENT_SCOPE_MEMBER, // CXXDependentScopeMemberExpr + EXPR_CXX_DEPENDENT_SCOPE_DECL_REF, // DependentScopeDeclRefExpr + EXPR_CXX_UNRESOLVED_CONSTRUCT, // CXXUnresolvedConstructExpr + EXPR_CXX_UNRESOLVED_MEMBER, // UnresolvedMemberExpr + EXPR_CXX_UNRESOLVED_LOOKUP, // UnresolvedLookupExpr + + EXPR_CXX_UNARY_TYPE_TRAIT // UnaryTypeTraitExpr + }; + + /// \brief The kinds of designators that can occur in a + /// DesignatedInitExpr. + enum DesignatorTypes { + /// \brief Field designator where only the field name is known. + DESIG_FIELD_NAME = 0, + /// \brief Field designator where the field has been resolved to + /// a declaration. + DESIG_FIELD_DECL = 1, + /// \brief Array designator. + DESIG_ARRAY = 2, + /// \brief GNU array range designator. + DESIG_ARRAY_RANGE = 3 + }; + + /// @} + } +} // end namespace clang + +#endif diff --git a/include/clang/Serialization/ASTDeserializationListener.h b/include/clang/Serialization/ASTDeserializationListener.h new file mode 100644 index 0000000..f8114de --- /dev/null +++ b/include/clang/Serialization/ASTDeserializationListener.h @@ -0,0 +1,49 @@ +//===- ASTDeserializationListener.h - Decl/Type PCH Read Events -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the ASTDeserializationListener class, which is notified +// by the ASTReader whenever a type or declaration is deserialized. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_FRONTEND_AST_DESERIALIZATION_LISTENER_H +#define LLVM_CLANG_FRONTEND_AST_DESERIALIZATION_LISTENER_H + +#include "clang/Serialization/ASTBitCodes.h" + +namespace clang { + +class Decl; +class ASTReader; +class QualType; + +class ASTDeserializationListener { +protected: + virtual ~ASTDeserializationListener() {} + +public: + /// \brief Tell the listener about the reader. + virtual void SetReader(ASTReader *Reader) = 0; + + /// \brief An identifier was deserialized from the AST file. + virtual void IdentifierRead(serialization::IdentID ID, + IdentifierInfo *II) = 0; + /// \brief A type was deserialized from the AST file. The ID here has the + /// qualifier bits already removed, and T is guaranteed to be locally + /// unqualified. + virtual void TypeRead(serialization::TypeIdx Idx, QualType T) = 0; + /// \brief A decl was deserialized from the AST file. + virtual void DeclRead(serialization::DeclID ID, const Decl *D) = 0; + /// \brief A selector was read from the AST file. + virtual void SelectorRead(serialization::SelectorID iD, Selector Sel) = 0; +}; + +} + +#endif diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h new file mode 100644 index 0000000..d31be88 --- /dev/null +++ b/include/clang/Serialization/ASTReader.h @@ -0,0 +1,1100 @@ +//===--- ASTReader.h - AST File Reader --------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the ASTReader class, which reads AST files. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_FRONTEND_AST_READER_H +#define LLVM_CLANG_FRONTEND_AST_READER_H + +#include "clang/Serialization/ASTBitCodes.h" +#include "clang/Sema/ExternalSemaSource.h" +#include "clang/AST/DeclarationName.h" +#include "clang/AST/DeclObjC.h" +#include "clang/AST/TemplateBase.h" +#include "clang/Lex/ExternalPreprocessorSource.h" +#include "clang/Lex/PreprocessingRecord.h" +#include "clang/Basic/Diagnostic.h" +#include "clang/Basic/IdentifierTable.h" +#include "clang/Basic/SourceManager.h" +#include "llvm/ADT/APFloat.h" +#include "llvm/ADT/APInt.h" +#include "llvm/ADT/APSInt.h" +#include "llvm/ADT/OwningPtr.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Bitcode/BitstreamReader.h" +#include "llvm/System/DataTypes.h" +#include <deque> +#include <map> +#include <string> +#include <utility> +#include <vector> + +namespace llvm { + class MemoryBuffer; +} + +namespace clang { + +class AddrLabelExpr; +class ASTConsumer; +class ASTContext; +class Attr; +class Decl; +class DeclContext; +class NestedNameSpecifier; +class CXXBaseSpecifier; +class CXXBaseOrMemberInitializer; +class GotoStmt; +class LabelStmt; +class MacroDefinition; +class NamedDecl; +class ASTDeserializationListener; +class Preprocessor; +class Sema; +class SwitchCase; +class ASTReader; +class ASTDeclReader; +struct HeaderFileInfo; + +struct PCHPredefinesBlock { + /// \brief The file ID for this predefines buffer in a PCH file. + FileID BufferID; + + /// \brief This predefines buffer in a PCH file. + llvm::StringRef Data; +}; +typedef llvm::SmallVector<PCHPredefinesBlock, 2> PCHPredefinesBlocks; + +/// \brief Abstract interface for callback invocations by the ASTReader. +/// +/// While reading an AST file, the ASTReader will call the methods of the +/// listener to pass on specific information. Some of the listener methods can +/// return true to indicate to the ASTReader that the information (and +/// consequently the AST file) is invalid. +class ASTReaderListener { +public: + virtual ~ASTReaderListener(); + + /// \brief Receives the language options. + /// + /// \returns true to indicate the options are invalid or false otherwise. + virtual bool ReadLanguageOptions(const LangOptions &LangOpts) { + return false; + } + + /// \brief Receives the target triple. + /// + /// \returns true to indicate the target triple is invalid or false otherwise. + virtual bool ReadTargetTriple(llvm::StringRef Triple) { + return false; + } + + /// \brief Receives the contents of the predefines buffer. + /// + /// \param Buffers Information about the predefines buffers. + /// + /// \param OriginalFileName The original file name for the AST file, which + /// will appear as an entry in the predefines buffer. + /// + /// \param SuggestedPredefines If necessary, additional definitions are added + /// here. + /// + /// \returns true to indicate the predefines are invalid or false otherwise. + virtual bool ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, + llvm::StringRef OriginalFileName, + std::string &SuggestedPredefines) { + return false; + } + + /// \brief Receives a HeaderFileInfo entry. + virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID) {} + + /// \brief Receives __COUNTER__ value. + virtual void ReadCounter(unsigned Value) {} +}; + +/// \brief ASTReaderListener implementation to validate the information of +/// the PCH file against an initialized Preprocessor. +class PCHValidator : public ASTReaderListener { + Preprocessor &PP; + ASTReader &Reader; + + unsigned NumHeaderInfos; + +public: + PCHValidator(Preprocessor &PP, ASTReader &Reader) + : PP(PP), Reader(Reader), NumHeaderInfos(0) {} + + virtual bool ReadLanguageOptions(const LangOptions &LangOpts); + virtual bool ReadTargetTriple(llvm::StringRef Triple); + virtual bool ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, + llvm::StringRef OriginalFileName, + std::string &SuggestedPredefines); + virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID); + virtual void ReadCounter(unsigned Value); + +private: + void Error(const char *Msg); +}; + +/// \brief Reads an AST files chain containing the contents of a translation +/// unit. +/// +/// The ASTReader class reads bitstreams (produced by the ASTWriter +/// class) containing the serialized representation of a given +/// abstract syntax tree and its supporting data structures. An +/// instance of the ASTReader can be attached to an ASTContext object, +/// which will provide access to the contents of the AST files. +/// +/// The AST reader provides lazy de-serialization of declarations, as +/// required when traversing the AST. Only those AST nodes that are +/// actually required will be de-serialized. +class ASTReader + : public ExternalPreprocessorSource, + public ExternalPreprocessingRecordSource, + public ExternalSemaSource, + public IdentifierInfoLookup, + public ExternalIdentifierLookup, + public ExternalSLocEntrySource { +public: + enum ASTReadResult { Success, Failure, IgnorePCH }; + friend class PCHValidator; + friend class ASTDeclReader; +private: + /// \brief The receiver of some callbacks invoked by ASTReader. + llvm::OwningPtr<ASTReaderListener> Listener; + + /// \brief The receiver of deserialization events. + ASTDeserializationListener *DeserializationListener; + + SourceManager &SourceMgr; + FileManager &FileMgr; + Diagnostic &Diags; + + /// \brief The semantic analysis object that will be processing the + /// AST files and the translation unit that uses it. + Sema *SemaObj; + + /// \brief The preprocessor that will be loading the source file. + Preprocessor *PP; + + /// \brief The AST context into which we'll read the AST files. + ASTContext *Context; + + /// \brief The AST consumer. + ASTConsumer *Consumer; + + /// \brief Information that is needed for every file in the chain. + struct PerFileData { + PerFileData(); + ~PerFileData(); + + /// \brief The AST stat cache installed for this file, if any. + /// + /// The dynamic type of this stat cache is always ASTStatCache + void *StatCache; + + /// \brief The bitstream reader from which we'll read the AST file. + llvm::BitstreamReader StreamFile; + llvm::BitstreamCursor Stream; + + /// \brief The size of this file, in bits. + uint64_t SizeInBits; + + /// \brief The cursor to the start of the preprocessor block, which stores + /// all of the macro definitions. + llvm::BitstreamCursor MacroCursor; + + /// DeclsCursor - This is a cursor to the start of the DECLS_BLOCK block. It + /// has read all the abbreviations at the start of the block and is ready to + /// jump around with these in context. + llvm::BitstreamCursor DeclsCursor; + + /// \brief The file name of the AST file. + std::string FileName; + + /// \brief The memory buffer that stores the data associated with + /// this AST file. + llvm::OwningPtr<llvm::MemoryBuffer> Buffer; + + /// \brief Cursor used to read source location entries. + llvm::BitstreamCursor SLocEntryCursor; + + /// \brief The number of source location entries in this AST file. + unsigned LocalNumSLocEntries; + + /// \brief Offsets for all of the source location entries in the + /// AST file. + const uint32_t *SLocOffsets; + + /// \brief The number of types in this AST file. + unsigned LocalNumTypes; + + /// \brief Offset of each type within the bitstream, indexed by the + /// type ID, or the representation of a Type*. + const uint32_t *TypeOffsets; + + /// \brief The number of declarations in this AST file. + unsigned LocalNumDecls; + + /// \brief Offset of each declaration within the bitstream, indexed + /// by the declaration ID (-1). + const uint32_t *DeclOffsets; + + /// \brief The number of identifiers in this AST file. + unsigned LocalNumIdentifiers; + + /// \brief Offsets into the identifier table data. + /// + /// This array is indexed by the identifier ID (-1), and provides + /// the offset into IdentifierTableData where the string data is + /// stored. + const uint32_t *IdentifierOffsets; + + /// \brief Actual data for the on-disk hash table. + /// + // This pointer points into a memory buffer, where the on-disk hash + // table for identifiers actually lives. + const char *IdentifierTableData; + + /// \brief A pointer to an on-disk hash table of opaque type + /// IdentifierHashTable. + void *IdentifierLookupTable; + + /// \brief The number of macro definitions in this file. + unsigned LocalNumMacroDefinitions; + + /// \brief Offsets of all of the macro definitions in the preprocessing + /// record in the AST file. + const uint32_t *MacroDefinitionOffsets; + + /// \brief The number of preallocated preprocessing entities in the + /// preprocessing record. + unsigned NumPreallocatedPreprocessingEntities; + + /// \brief A pointer to an on-disk hash table of opaque type + /// ASTSelectorLookupTable. + /// + /// This hash table provides the IDs of all selectors, and the associated + /// instance and factory methods. + void *SelectorLookupTable; + + /// \brief A pointer to the character data that comprises the selector table + /// + /// The SelectorOffsets table refers into this memory. + const unsigned char *SelectorLookupTableData; + + /// \brief Offsets into the method pool lookup table's data array + /// where each selector resides. + const uint32_t *SelectorOffsets; + + /// \brief The number of selectors new to this file. + /// + /// This is the number of entries in SelectorOffsets. + unsigned LocalNumSelectors; + }; + + /// \brief The chain of AST files. The first entry is the one named by the + /// user, the last one is the one that doesn't depend on anything further. + /// That is, the entry I was created with -include-pch I+1. + llvm::SmallVector<PerFileData*, 2> Chain; + + /// \brief Types that have already been loaded from the chain. + /// + /// When the pointer at index I is non-NULL, the type with + /// ID = (I + 1) << FastQual::Width has already been loaded + std::vector<QualType> TypesLoaded; + + /// \brief Map that provides the ID numbers of each type within the + /// output stream, plus those deserialized from a chained PCH. + /// + /// The ID numbers of types are consecutive (in order of discovery) + /// and start at 1. 0 is reserved for NULL. When types are actually + /// stored in the stream, the ID number is shifted by 2 bits to + /// allow for the const/volatile qualifiers. + /// + /// Keys in the map never have const/volatile qualifiers. + serialization::TypeIdxMap TypeIdxs; + + /// \brief Declarations that have already been loaded from the chain. + /// + /// When the pointer at index I is non-NULL, the declaration with ID + /// = I + 1 has already been loaded. + std::vector<Decl *> DeclsLoaded; + + typedef llvm::DenseMap<serialization::DeclID, + std::pair<PerFileData *, uint64_t> > + DeclReplacementMap; + /// \brief Declarations that have been replaced in a later file in the chain. + DeclReplacementMap ReplacedDecls; + + /// \brief Information about the contents of a DeclContext. + struct DeclContextInfo { + void *NameLookupTableData; // a ASTDeclContextNameLookupTable. + const serialization::DeclID *LexicalDecls; + unsigned NumLexicalDecls; + }; + // In a full chain, there could be multiple updates to every decl context, + // so this is a vector. However, typically a chain is only two elements long, + // with only one file containing updates, so there will be only one update + // per decl context. + typedef llvm::SmallVector<DeclContextInfo, 1> DeclContextInfos; + typedef llvm::DenseMap<const DeclContext *, DeclContextInfos> + DeclContextOffsetsMap; + // Updates for visible decls can occur for other contexts than just the + // TU, and when we read those update records, the actual context will not + // be available yet (unless it's the TU), so have this pending map using the + // ID as a key. It will be realized when the context is actually loaded. + typedef llvm::SmallVector<void *, 1> DeclContextVisibleUpdates; + typedef llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates> + DeclContextVisibleUpdatesPending; + + /// \brief Offsets of the lexical and visible declarations for each + /// DeclContext. + DeclContextOffsetsMap DeclContextOffsets; + + /// \brief Updates to the visible declarations of declaration contexts that + /// haven't been loaded yet. + DeclContextVisibleUpdatesPending PendingVisibleUpdates; + + typedef llvm::DenseMap<serialization::DeclID, serialization::DeclID> + FirstLatestDeclIDMap; + /// \brief Map of first declarations from a chained PCH that point to the + /// most recent declarations in another AST file. + FirstLatestDeclIDMap FirstLatestDeclIDs; + + typedef llvm::SmallVector<serialization::DeclID, 4> + AdditionalTemplateSpecializations; + typedef llvm::DenseMap<serialization::DeclID, + AdditionalTemplateSpecializations> + AdditionalTemplateSpecializationsMap; + + /// \brief Additional specializations (including partial) of templates that + /// were introduced after the template was serialized. + AdditionalTemplateSpecializationsMap AdditionalTemplateSpecializationsPending; + + /// \brief Read the records that describe the contents of declcontexts. + bool ReadDeclContextStorage(llvm::BitstreamCursor &Cursor, + const std::pair<uint64_t, uint64_t> &Offsets, + DeclContextInfo &Info); + + /// \brief A vector containing identifiers that have already been + /// loaded. + /// + /// If the pointer at index I is non-NULL, then it refers to the + /// IdentifierInfo for the identifier with ID=I+1 that has already + /// been loaded. + std::vector<IdentifierInfo *> IdentifiersLoaded; + + /// \brief A vector containing selectors that have already been loaded. + /// + /// This vector is indexed by the Selector ID (-1). NULL selector + /// entries indicate that the particular selector ID has not yet + /// been loaded. + llvm::SmallVector<Selector, 16> SelectorsLoaded; + + /// \brief The macro definitions we have already loaded. + llvm::SmallVector<MacroDefinition *, 16> MacroDefinitionsLoaded; + + /// \name CodeGen-relevant special data + /// \brief Fields containing data that is relevant to CodeGen. + //@{ + + /// \brief The IDs of all declarations that fulfill the criteria of + /// "interesting" decls. + /// + /// This contains the data loaded from all EXTERNAL_DEFINITIONS blocks in the + /// chain. The referenced declarations are deserialized and passed to the + /// consumer eagerly. + llvm::SmallVector<uint64_t, 16> ExternalDefinitions; + + /// \brief The IDs of all tentative definitions stored in the the chain. + /// + /// Sema keeps track of all tentative definitions in a TU because it has to + /// complete them and pass them on to CodeGen. Thus, tentative definitions in + /// the PCH chain must be eagerly deserialized. + llvm::SmallVector<uint64_t, 16> TentativeDefinitions; + + /// \brief The IDs of all CXXRecordDecls stored in the chain whose VTables are + /// used. + /// + /// CodeGen has to emit VTables for these records, so they have to be eagerly + /// deserialized. + llvm::SmallVector<uint64_t, 64> VTableUses; + + //@} + + /// \name Diagnostic-relevant special data + /// \brief Fields containing data that is used for generating diagnostics + //@{ + + /// \brief Method selectors used in a @selector expression. Used for + /// implementation of -Wselector. + llvm::SmallVector<uint64_t, 64> ReferencedSelectorsData; + + /// \brief A snapshot of Sema's unused file-scoped variable tracking, for + /// generating warnings. + llvm::SmallVector<uint64_t, 16> UnusedFileScopedDecls; + + /// \brief A snapshot of Sema's weak undeclared identifier tracking, for + /// generating warnings. + llvm::SmallVector<uint64_t, 64> WeakUndeclaredIdentifiers; + + /// \brief The IDs of type aliases for ext_vectors that exist in the chain. + /// + /// Used by Sema for finding sugared names for ext_vectors in diagnostics. + llvm::SmallVector<uint64_t, 4> ExtVectorDecls; + + //@} + + /// \name Sema-relevant special data + /// \brief Fields containing data that is used for semantic analysis + //@{ + + /// \brief The IDs of all locally scoped external decls in the chain. + /// + /// Sema tracks these to validate that the types are consistent across all + /// local external declarations. + llvm::SmallVector<uint64_t, 16> LocallyScopedExternalDecls; + + /// \brief A snapshot of the pwnsinf instantiations in the chain. + /// + /// This record tracks the instantiations that Sema has to perform at the end + /// of the TU. It consists of a pair of values for every pending instantiation + /// where the first value is the ID of the decl and the second is the + /// instantiation location. + llvm::SmallVector<uint64_t, 64> PendingInstantiations; + + /// \brief The IDs of all dynamic class declarations in the chain. + /// + /// Sema tracks these because it checks for the key functions being defined + /// at the end of the TU, in which case it directs CodeGen to emit the VTable. + llvm::SmallVector<uint64_t, 16> DynamicClasses; + + /// \brief The IDs of the declarations Sema stores directly. + /// + /// Sema tracks a few important decls, such as namespace std, directly. + llvm::SmallVector<uint64_t, 4> SemaDeclRefs; + + /// \brief The IDs of the types ASTContext stores directly. + /// + /// The AST context tracks a few important types, such as va_list, directly. + llvm::SmallVector<uint64_t, 16> SpecialTypes; + + //@} + + /// \brief The original file name that was used to build the primary AST file, + /// which may have been modified for relocatable-pch support. + std::string OriginalFileName; + + /// \brief The actual original file name that was used to build the primary + /// AST file. + std::string ActualOriginalFileName; + + /// \brief Whether this precompiled header is a relocatable PCH file. + bool RelocatablePCH; + + /// \brief The system include root to be used when loading the + /// precompiled header. + const char *isysroot; + + /// \brief Whether to disable the normal validation performed on precompiled + /// headers when they are loaded. + bool DisableValidation; + + /// \brief Mapping from switch-case IDs in the chain to switch-case statements + /// + /// Statements usually don't have IDs, but switch cases need them, so that the + /// switch statement can refer to them. + std::map<unsigned, SwitchCase *> SwitchCaseStmts; + + /// \brief Mapping from label statement IDs in the chain to label statements. + /// + /// Statements usually don't have IDs, but labeled statements need them, so + /// that goto statements and address-of-label expressions can refer to them. + std::map<unsigned, LabelStmt *> LabelStmts; + + /// \brief Mapping from label IDs to the set of "goto" statements + /// that point to that label before the label itself has been + /// de-serialized. + std::multimap<unsigned, GotoStmt *> UnresolvedGotoStmts; + + /// \brief Mapping from label IDs to the set of address label + /// expressions that point to that label before the label itself has + /// been de-serialized. + std::multimap<unsigned, AddrLabelExpr *> UnresolvedAddrLabelExprs; + + /// \brief The number of stat() calls that hit/missed the stat + /// cache. + unsigned NumStatHits, NumStatMisses; + + /// \brief The number of source location entries de-serialized from + /// the PCH file. + unsigned NumSLocEntriesRead; + + /// \brief The number of source location entries in the chain. + unsigned TotalNumSLocEntries; + + /// \brief The number of statements (and expressions) de-serialized + /// from the chain. + unsigned NumStatementsRead; + + /// \brief The total number of statements (and expressions) stored + /// in the chain. + unsigned TotalNumStatements; + + /// \brief The number of macros de-serialized from the chain. + unsigned NumMacrosRead; + + /// \brief The total number of macros stored in the chain. + unsigned TotalNumMacros; + + /// \brief The number of selectors that have been read. + unsigned NumSelectorsRead; + + /// \brief The number of method pool entries that have been read. + unsigned NumMethodPoolEntriesRead; + + /// \brief The number of times we have looked up a selector in the method + /// pool and not found anything interesting. + unsigned NumMethodPoolMisses; + + /// \brief The total number of method pool entries in the selector table. + unsigned TotalNumMethodPoolEntries; + + /// Number of lexical decl contexts read/total. + unsigned NumLexicalDeclContextsRead, TotalLexicalDeclContexts; + + /// Number of visible decl contexts read/total. + unsigned NumVisibleDeclContextsRead, TotalVisibleDeclContexts; + + /// \brief Number of Decl/types that are currently deserializing. + unsigned NumCurrentElementsDeserializing; + + /// \brief An IdentifierInfo that has been loaded but whose top-level + /// declarations of the same name have not (yet) been loaded. + struct PendingIdentifierInfo { + IdentifierInfo *II; + llvm::SmallVector<uint32_t, 4> DeclIDs; + }; + + /// \brief The set of identifiers that were read while the AST reader was + /// (recursively) loading declarations. + /// + /// The declarations on the identifier chain for these identifiers will be + /// loaded once the recursive loading has completed. + std::deque<PendingIdentifierInfo> PendingIdentifierInfos; + + /// \brief Contains declarations and definitions that will be + /// "interesting" to the ASTConsumer, when we get that AST consumer. + /// + /// "Interesting" declarations are those that have data that may + /// need to be emitted, such as inline function definitions or + /// Objective-C protocols. + std::deque<Decl *> InterestingDecls; + + /// \brief When reading a Stmt tree, Stmt operands are placed in this stack. + llvm::SmallVector<Stmt *, 16> StmtStack; + + /// \brief What kind of records we are reading. + enum ReadingKind { + Read_Decl, Read_Type, Read_Stmt + }; + + /// \brief What kind of records we are reading. + ReadingKind ReadingKind; + + /// \brief RAII object to change the reading kind. + class ReadingKindTracker { + ASTReader &Reader; + enum ReadingKind PrevKind; + + ReadingKindTracker(const ReadingKindTracker&); // do not implement + ReadingKindTracker &operator=(const ReadingKindTracker&);// do not implement + + public: + ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader) + : Reader(reader), PrevKind(Reader.ReadingKind) { + Reader.ReadingKind = newKind; + } + + ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; } + }; + + /// \brief All predefines buffers in the chain, to be treated as if + /// concatenated. + PCHPredefinesBlocks PCHPredefinesBuffers; + + /// \brief Suggested contents of the predefines buffer, after this + /// PCH file has been processed. + /// + /// In most cases, this string will be empty, because the predefines + /// buffer computed to build the PCH file will be identical to the + /// predefines buffer computed from the command line. However, when + /// there are differences that the PCH reader can work around, this + /// predefines buffer may contain additional definitions. + std::string SuggestedPredefines; + + /// \brief Reads a statement from the specified cursor. + Stmt *ReadStmtFromStream(llvm::BitstreamCursor &Cursor); + + void MaybeAddSystemRootToFilename(std::string &Filename); + + ASTReadResult ReadASTCore(llvm::StringRef FileName); + ASTReadResult ReadASTBlock(PerFileData &F); + bool CheckPredefinesBuffers(); + bool ParseLineTable(llvm::SmallVectorImpl<uint64_t> &Record); + ASTReadResult ReadSourceManagerBlock(PerFileData &F); + ASTReadResult ReadSLocEntryRecord(unsigned ID); + llvm::BitstreamCursor &SLocCursorForID(unsigned ID); + bool ParseLanguageOptions(const llvm::SmallVectorImpl<uint64_t> &Record); + + typedef std::pair<llvm::BitstreamCursor *, uint64_t> RecordLocation; + + QualType ReadTypeRecord(unsigned Index); + RecordLocation TypeCursorForIndex(unsigned Index); + void LoadedDecl(unsigned Index, Decl *D); + Decl *ReadDeclRecord(unsigned Index, serialization::DeclID ID); + RecordLocation DeclCursorForIndex(unsigned Index, serialization::DeclID ID); + + void PassInterestingDeclsToConsumer(); + + /// \brief Produce an error diagnostic and return true. + /// + /// This routine should only be used for fatal errors that have to + /// do with non-routine failures (e.g., corrupted AST file). + void Error(const char *Msg); + + ASTReader(const ASTReader&); // do not implement + ASTReader &operator=(const ASTReader &); // do not implement +public: + typedef llvm::SmallVector<uint64_t, 64> RecordData; + + /// \brief Load the AST file and validate its contents against the given + /// Preprocessor. + /// + /// \param PP the preprocessor associated with the context in which this + /// precompiled header will be loaded. + /// + /// \param Context the AST context that this precompiled header will be + /// loaded into. + /// + /// \param isysroot If non-NULL, the system include path specified by the + /// user. This is only used with relocatable PCH files. If non-NULL, + /// a relocatable PCH file will use the default path "/". + /// + /// \param DisableValidation If true, the AST reader will suppress most + /// of its regular consistency checking, allowing the use of precompiled + /// headers that cannot be determined to be compatible. + ASTReader(Preprocessor &PP, ASTContext *Context, const char *isysroot = 0, + bool DisableValidation = false); + + /// \brief Load the AST file without using any pre-initialized Preprocessor. + /// + /// The necessary information to initialize a Preprocessor later can be + /// obtained by setting a ASTReaderListener. + /// + /// \param SourceMgr the source manager into which the AST file will be loaded + /// + /// \param FileMgr the file manager into which the AST file will be loaded. + /// + /// \param Diags the diagnostics system to use for reporting errors and + /// warnings relevant to loading the AST file. + /// + /// \param isysroot If non-NULL, the system include path specified by the + /// user. This is only used with relocatable PCH files. If non-NULL, + /// a relocatable PCH file will use the default path "/". + /// + /// \param DisableValidation If true, the AST reader will suppress most + /// of its regular consistency checking, allowing the use of precompiled + /// headers that cannot be determined to be compatible. + ASTReader(SourceManager &SourceMgr, FileManager &FileMgr, + Diagnostic &Diags, const char *isysroot = 0, + bool DisableValidation = false); + ~ASTReader(); + + /// \brief Load the precompiled header designated by the given file + /// name. + ASTReadResult ReadAST(const std::string &FileName); + + /// \brief Set the AST callbacks listener. + void setListener(ASTReaderListener *listener) { + Listener.reset(listener); + } + + /// \brief Set the AST deserialization listener. + void setDeserializationListener(ASTDeserializationListener *Listener); + + /// \brief Set the Preprocessor to use. + void setPreprocessor(Preprocessor &pp); + + /// \brief Sets and initializes the given Context. + void InitializeContext(ASTContext &Context); + + /// \brief Retrieve the name of the named (primary) AST file + const std::string &getFileName() const { return Chain[0]->FileName; } + + /// \brief Retrieve the name of the original source file name + const std::string &getOriginalSourceFile() { return OriginalFileName; } + + /// \brief Retrieve the name of the original source file name directly from + /// the AST file, without actually loading the AST file. + static std::string getOriginalSourceFile(const std::string &ASTFileName, + Diagnostic &Diags); + + /// \brief Returns the suggested contents of the predefines buffer, + /// which contains a (typically-empty) subset of the predefines + /// build prior to including the precompiled header. + const std::string &getSuggestedPredefines() { return SuggestedPredefines; } + + /// \brief Read preprocessed entities into the + virtual void ReadPreprocessedEntities(); + + /// \brief Returns the number of source locations found in the chain. + unsigned getTotalNumSLocs() const { + return TotalNumSLocEntries; + } + + /// \brief Returns the number of identifiers found in the chain. + unsigned getTotalNumIdentifiers() const { + return static_cast<unsigned>(IdentifiersLoaded.size()); + } + + /// \brief Returns the number of types found in the chain. + unsigned getTotalNumTypes() const { + return static_cast<unsigned>(TypesLoaded.size()); + } + + /// \brief Returns the number of declarations found in the chain. + unsigned getTotalNumDecls() const { + return static_cast<unsigned>(DeclsLoaded.size()); + } + + /// \brief Returns the number of selectors found in the chain. + unsigned getTotalNumSelectors() const { + return static_cast<unsigned>(SelectorsLoaded.size()); + } + + /// \brief Reads a TemplateArgumentLocInfo appropriate for the + /// given TemplateArgument kind. + TemplateArgumentLocInfo + GetTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, + llvm::BitstreamCursor &DeclsCursor, + const RecordData &Record, unsigned &Idx); + + /// \brief Reads a TemplateArgumentLoc. + TemplateArgumentLoc + ReadTemplateArgumentLoc(llvm::BitstreamCursor &DeclsCursor, + const RecordData &Record, unsigned &Idx); + + /// \brief Reads a declarator info from the given record. + TypeSourceInfo *GetTypeSourceInfo(llvm::BitstreamCursor &DeclsCursor, + const RecordData &Record, unsigned &Idx); + + /// \brief Resolve and return the translation unit declaration. + TranslationUnitDecl *GetTranslationUnitDecl(); + + /// \brief Resolve a type ID into a type, potentially building a new + /// type. + QualType GetType(serialization::TypeID ID); + + /// \brief Returns the type ID associated with the given type. + /// If the type didn't come from the AST file the ID that is returned is + /// marked as "doesn't exist in AST". + serialization::TypeID GetTypeID(QualType T) const; + + /// \brief Returns the type index associated with the given type. + /// If the type didn't come from the AST file the index that is returned is + /// marked as "doesn't exist in AST". + serialization::TypeIdx GetTypeIdx(QualType T) const; + + /// \brief Resolve a declaration ID into a declaration, potentially + /// building a new declaration. + Decl *GetDecl(serialization::DeclID ID); + virtual Decl *GetExternalDecl(uint32_t ID); + + /// \brief Resolve the offset of a statement into a statement. + /// + /// This operation will read a new statement from the external + /// source each time it is called, and is meant to be used via a + /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). + virtual Stmt *GetExternalDeclStmt(uint64_t Offset); + + /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the + /// specified cursor. Read the abbreviations that are at the top of the block + /// and then leave the cursor pointing into the block. + bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID); + + /// \brief Finds all the visible declarations with a given name. + /// The current implementation of this method just loads the entire + /// lookup table as unmaterialized references. + virtual DeclContext::lookup_result + FindExternalVisibleDeclsByName(const DeclContext *DC, + DeclarationName Name); + + virtual void MaterializeVisibleDecls(const DeclContext *DC); + + /// \brief Read all of the declarations lexically stored in a + /// declaration context. + /// + /// \param DC The declaration context whose declarations will be + /// read. + /// + /// \param Decls Vector that will contain the declarations loaded + /// from the external source. The caller is responsible for merging + /// these declarations with any declarations already stored in the + /// declaration context. + /// + /// \returns true if there was an error while reading the + /// declarations for this declaration context. + virtual bool FindExternalLexicalDecls(const DeclContext *DC, + llvm::SmallVectorImpl<Decl*> &Decls); + + /// \brief Notify ASTReader that we started deserialization of + /// a decl or type so until FinishedDeserializing is called there may be + /// decls that are initializing. Must be paired with FinishedDeserializing. + virtual void StartedDeserializing() { ++NumCurrentElementsDeserializing; } + + /// \brief Notify ASTReader that we finished the deserialization of + /// a decl or type. Must be paired with StartedDeserializing. + virtual void FinishedDeserializing(); + + /// \brief Function that will be invoked when we begin parsing a new + /// translation unit involving this external AST source. + /// + /// This function will provide all of the external definitions to + /// the ASTConsumer. + virtual void StartTranslationUnit(ASTConsumer *Consumer); + + /// \brief Print some statistics about AST usage. + virtual void PrintStats(); + + /// \brief Initialize the semantic source with the Sema instance + /// being used to perform semantic analysis on the abstract syntax + /// tree. + virtual void InitializeSema(Sema &S); + + /// \brief Inform the semantic consumer that Sema is no longer available. + virtual void ForgetSema() { SemaObj = 0; } + + /// \brief Retrieve the IdentifierInfo for the named identifier. + /// + /// This routine builds a new IdentifierInfo for the given identifier. If any + /// declarations with this name are visible from translation unit scope, their + /// declarations will be deserialized and introduced into the declaration + /// chain of the identifier. + virtual IdentifierInfo *get(const char *NameStart, const char *NameEnd); + IdentifierInfo *get(llvm::StringRef Name) { + return get(Name.begin(), Name.end()); + } + + /// \brief Load the contents of the global method pool for a given + /// selector. + /// + /// \returns a pair of Objective-C methods lists containing the + /// instance and factory methods, respectively, with this selector. + virtual std::pair<ObjCMethodList, ObjCMethodList> + ReadMethodPool(Selector Sel); + + /// \brief Load a selector from disk, registering its ID if it exists. + void LoadSelector(Selector Sel); + + void SetIdentifierInfo(unsigned ID, IdentifierInfo *II); + void SetGloballyVisibleDecls(IdentifierInfo *II, + const llvm::SmallVectorImpl<uint32_t> &DeclIDs, + bool Nonrecursive = false); + + /// \brief Report a diagnostic. + DiagnosticBuilder Diag(unsigned DiagID); + + /// \brief Report a diagnostic. + DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID); + + IdentifierInfo *DecodeIdentifierInfo(unsigned Idx); + + IdentifierInfo *GetIdentifierInfo(const RecordData &Record, unsigned &Idx) { + return DecodeIdentifierInfo(Record[Idx++]); + } + + virtual IdentifierInfo *GetIdentifier(unsigned ID) { + return DecodeIdentifierInfo(ID); + } + + /// \brief Read the source location entry with index ID. + virtual void ReadSLocEntry(unsigned ID); + + Selector DecodeSelector(unsigned Idx); + + virtual Selector GetExternalSelector(uint32_t ID); + uint32_t GetNumExternalSelectors(); + + Selector GetSelector(const RecordData &Record, unsigned &Idx) { + return DecodeSelector(Record[Idx++]); + } + + /// \brief Read a declaration name. + DeclarationName ReadDeclarationName(const RecordData &Record, unsigned &Idx); + + NestedNameSpecifier *ReadNestedNameSpecifier(const RecordData &Record, + unsigned &Idx); + + /// \brief Read a template name. + TemplateName ReadTemplateName(const RecordData &Record, unsigned &Idx); + + /// \brief Read a template argument. + TemplateArgument ReadTemplateArgument(llvm::BitstreamCursor &DeclsCursor, + const RecordData &Record,unsigned &Idx); + + /// \brief Read a template parameter list. + TemplateParameterList *ReadTemplateParameterList(const RecordData &Record, + unsigned &Idx); + + /// \brief Read a template argument array. + void + ReadTemplateArgumentList(llvm::SmallVector<TemplateArgument, 8> &TemplArgs, + llvm::BitstreamCursor &DeclsCursor, + const RecordData &Record, unsigned &Idx); + + /// \brief Read a UnresolvedSet structure. + void ReadUnresolvedSet(UnresolvedSetImpl &Set, + const RecordData &Record, unsigned &Idx); + + /// \brief Read a C++ base specifier. + CXXBaseSpecifier ReadCXXBaseSpecifier(llvm::BitstreamCursor &DeclsCursor, + const RecordData &Record,unsigned &Idx); + + /// \brief Read a CXXBaseOrMemberInitializer array. + std::pair<CXXBaseOrMemberInitializer **, unsigned> + ReadCXXBaseOrMemberInitializers(llvm::BitstreamCursor &DeclsCursor, + const RecordData &Record, unsigned &Idx); + + /// \brief Read a source location. + SourceLocation ReadSourceLocation(const RecordData &Record, unsigned& Idx) { + return SourceLocation::getFromRawEncoding(Record[Idx++]); + } + + /// \brief Read a source range. + SourceRange ReadSourceRange(const RecordData &Record, unsigned& Idx); + + /// \brief Read an integral value + llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx); + + /// \brief Read a signed integral value + llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx); + + /// \brief Read a floating-point value + llvm::APFloat ReadAPFloat(const RecordData &Record, unsigned &Idx); + + // \brief Read a string + std::string ReadString(const RecordData &Record, unsigned &Idx); + + CXXTemporary *ReadCXXTemporary(const RecordData &Record, unsigned &Idx); + + /// \brief Reads attributes from the current stream position. + void ReadAttributes(llvm::BitstreamCursor &DeclsCursor, AttrVec &Attrs); + + /// \brief Reads a statement. + Stmt *ReadStmt(llvm::BitstreamCursor &Cursor); + + /// \brief Reads an expression. + Expr *ReadExpr(llvm::BitstreamCursor &Cursor); + + /// \brief Reads a sub-statement operand during statement reading. + Stmt *ReadSubStmt() { + assert(ReadingKind == Read_Stmt && + "Should be called only during statement reading!"); + // Subexpressions are stored from last to first, so the next Stmt we need + // is at the back of the stack. + assert(!StmtStack.empty() && "Read too many sub statements!"); + return StmtStack.pop_back_val(); + } + + /// \brief Reads a sub-expression operand during statement reading. + Expr *ReadSubExpr(); + + /// \brief Reads the macro record located at the given offset. + void ReadMacroRecord(llvm::BitstreamCursor &Stream, uint64_t Offset); + + /// \brief Read the set of macros defined by this external macro source. + virtual void ReadDefinedMacros(); + + /// \brief Retrieve the macro definition with the given ID. + MacroDefinition *getMacroDefinition(serialization::IdentID ID); + + /// \brief Retrieve the AST context that this AST reader supplements. + ASTContext *getContext() { return Context; } + + // \brief Contains declarations that were loaded before we have + // access to a Sema object. + llvm::SmallVector<NamedDecl *, 16> PreloadedDecls; + + /// \brief Retrieve the semantic analysis object used to analyze the + /// translation unit in which the precompiled header is being + /// imported. + Sema *getSema() { return SemaObj; } + + /// \brief Retrieve the identifier table associated with the + /// preprocessor. + IdentifierTable &getIdentifierTable(); + + /// \brief Record that the given ID maps to the given switch-case + /// statement. + void RecordSwitchCaseID(SwitchCase *SC, unsigned ID); + + /// \brief Retrieve the switch-case statement with the given ID. + SwitchCase *getSwitchCaseWithID(unsigned ID); + + /// \brief Record that the given label statement has been + /// deserialized and has the given ID. + void RecordLabelStmt(LabelStmt *S, unsigned ID); + + /// \brief Set the label of the given statement to the label + /// identified by ID. + /// + /// Depending on the order in which the label and other statements + /// referencing that label occur, this operation may complete + /// immediately (updating the statement) or it may queue the + /// statement to be back-patched later. + void SetLabelOf(GotoStmt *S, unsigned ID); + + /// \brief Set the label of the given expression to the label + /// identified by ID. + /// + /// Depending on the order in which the label and other statements + /// referencing that label occur, this operation may complete + /// immediately (updating the statement) or it may queue the + /// statement to be back-patched later. + void SetLabelOf(AddrLabelExpr *S, unsigned ID); +}; + +/// \brief Helper class that saves the current stream position and +/// then restores it when destroyed. +struct SavedStreamPosition { + explicit SavedStreamPosition(llvm::BitstreamCursor &Cursor) + : Cursor(Cursor), Offset(Cursor.GetCurrentBitNo()) { } + + ~SavedStreamPosition() { + Cursor.JumpToBit(Offset); + } + +private: + llvm::BitstreamCursor &Cursor; + uint64_t Offset; +}; + +inline void PCHValidator::Error(const char *Msg) { + Reader.Error(Msg); +} + +} // end namespace clang + +#endif diff --git a/include/clang/Serialization/ASTWriter.h b/include/clang/Serialization/ASTWriter.h new file mode 100644 index 0000000..426fc47 --- /dev/null +++ b/include/clang/Serialization/ASTWriter.h @@ -0,0 +1,513 @@ +//===--- ASTWriter.h - AST File Writer --------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the ASTWriter class, which writes an AST file +// containing a serialized representation of a translation unit. +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_CLANG_FRONTEND_AST_WRITER_H +#define LLVM_CLANG_FRONTEND_AST_WRITER_H + +#include "clang/AST/Decl.h" +#include "clang/AST/DeclarationName.h" +#include "clang/AST/TemplateBase.h" +#include "clang/Serialization/ASTBitCodes.h" +#include "clang/Serialization/ASTDeserializationListener.h" +#include "clang/Sema/SemaConsumer.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/Bitcode/BitstreamWriter.h" +#include <map> +#include <queue> +#include <vector> + +namespace llvm { + class APFloat; + class APInt; + class BitstreamWriter; +} + +namespace clang { + +class ASTContext; +class NestedNameSpecifier; +class CXXBaseSpecifier; +class CXXBaseOrMemberInitializer; +class LabelStmt; +class MacroDefinition; +class MemorizeStatCalls; +class ASTReader; +class Preprocessor; +class Sema; +class SourceManager; +class SwitchCase; +class TargetInfo; + +/// \brief Writes an AST file containing the contents of a translation unit. +/// +/// The ASTWriter class produces a bitstream containing the serialized +/// representation of a given abstract syntax tree and its supporting +/// data structures. This bitstream can be de-serialized via an +/// instance of the ASTReader class. +class ASTWriter : public ASTDeserializationListener { +public: + typedef llvm::SmallVector<uint64_t, 64> RecordData; + + friend class ASTDeclWriter; +private: + /// \brief The bitstream writer used to emit this precompiled header. + llvm::BitstreamWriter &Stream; + + /// \brief The reader of existing AST files, if we're chaining. + ASTReader *Chain; + + /// \brief Stores a declaration or a type to be written to the AST file. + class DeclOrType { + public: + DeclOrType(Decl *D) : Stored(D), IsType(false) { } + DeclOrType(QualType T) : Stored(T.getAsOpaquePtr()), IsType(true) { } + + bool isType() const { return IsType; } + bool isDecl() const { return !IsType; } + + QualType getType() const { + assert(isType() && "Not a type!"); + return QualType::getFromOpaquePtr(Stored); + } + + Decl *getDecl() const { + assert(isDecl() && "Not a decl!"); + return static_cast<Decl *>(Stored); + } + + private: + void *Stored; + bool IsType; + }; + + /// \brief The declarations and types to emit. + std::queue<DeclOrType> DeclTypesToEmit; + + /// \brief The first ID number we can use for our own declarations. + serialization::DeclID FirstDeclID; + + /// \brief The decl ID that will be assigned to the next new decl. + serialization::DeclID NextDeclID; + + /// \brief Map that provides the ID numbers of each declaration within + /// the output stream, as well as those deserialized from a chained PCH. + /// + /// The ID numbers of declarations are consecutive (in order of + /// discovery) and start at 2. 1 is reserved for the translation + /// unit, while 0 is reserved for NULL. + llvm::DenseMap<const Decl *, serialization::DeclID> DeclIDs; + + /// \brief Offset of each declaration in the bitstream, indexed by + /// the declaration's ID. + std::vector<uint32_t> DeclOffsets; + + /// \brief The first ID number we can use for our own types. + serialization::TypeID FirstTypeID; + + /// \brief The type ID that will be assigned to the next new type. + serialization::TypeID NextTypeID; + + /// \brief Map that provides the ID numbers of each type within the + /// output stream, plus those deserialized from a chained PCH. + /// + /// The ID numbers of types are consecutive (in order of discovery) + /// and start at 1. 0 is reserved for NULL. When types are actually + /// stored in the stream, the ID number is shifted by 2 bits to + /// allow for the const/volatile qualifiers. + /// + /// Keys in the map never have const/volatile qualifiers. + serialization::TypeIdxMap TypeIdxs; + + /// \brief Offset of each type in the bitstream, indexed by + /// the type's ID. + std::vector<uint32_t> TypeOffsets; + + /// \brief The first ID number we can use for our own identifiers. + serialization::IdentID FirstIdentID; + + /// \brief The identifier ID that will be assigned to the next new identifier. + serialization::IdentID NextIdentID; + + /// \brief Map that provides the ID numbers of each identifier in + /// the output stream. + /// + /// The ID numbers for identifiers are consecutive (in order of + /// discovery), starting at 1. An ID of zero refers to a NULL + /// IdentifierInfo. + llvm::DenseMap<const IdentifierInfo *, serialization::IdentID> IdentifierIDs; + + /// \brief Offsets of each of the identifier IDs into the identifier + /// table. + std::vector<uint32_t> IdentifierOffsets; + + /// \brief The first ID number we can use for our own selectors. + serialization::SelectorID FirstSelectorID; + + /// \brief The selector ID that will be assigned to the next new identifier. + serialization::SelectorID NextSelectorID; + + /// \brief Map that provides the ID numbers of each Selector. + llvm::DenseMap<Selector, serialization::SelectorID> SelectorIDs; + + /// \brief Offset of each selector within the method pool/selector + /// table, indexed by the Selector ID (-1). + std::vector<uint32_t> SelectorOffsets; + + /// \brief Offsets of each of the macro identifiers into the + /// bitstream. + /// + /// For each identifier that is associated with a macro, this map + /// provides the offset into the bitstream where that macro is + /// defined. + llvm::DenseMap<const IdentifierInfo *, uint64_t> MacroOffsets; + + /// \brief Mapping from macro definitions (as they occur in the preprocessing + /// record) to the index into the macro definitions table. + llvm::DenseMap<const MacroDefinition *, serialization::IdentID> + MacroDefinitions; + + /// \brief Mapping from the macro definition indices in \c MacroDefinitions + /// to the corresponding offsets within the preprocessor block. + std::vector<uint32_t> MacroDefinitionOffsets; + + typedef llvm::DenseMap<Decl *, Decl *> FirstLatestDeclMap; + /// \brief Map of first declarations from a chained PCH that point to the + /// most recent declarations in another PCH. + FirstLatestDeclMap FirstLatestDecls; + + /// \brief Declarations encountered that might be external + /// definitions. + /// + /// We keep track of external definitions (as well as tentative + /// definitions) as we are emitting declarations to the AST + /// file. The AST file contains a separate record for these external + /// definitions, which are provided to the AST consumer by the AST + /// reader. This is behavior is required to properly cope with, + /// e.g., tentative variable definitions that occur within + /// headers. The declarations themselves are stored as declaration + /// IDs, since they will be written out to an EXTERNAL_DEFINITIONS + /// record. + llvm::SmallVector<uint64_t, 16> ExternalDefinitions; + + /// \brief Namespaces that have received extensions since their serialized + /// form. + /// + /// Basically, when we're chaining and encountering a namespace, we check if + /// its primary namespace comes from the chain. If it does, we add the primary + /// to this set, so that we can write out lexical content updates for it. + llvm::SmallPtrSet<const NamespaceDecl *, 16> UpdatedNamespaces; + + /// \brief Decls that have been replaced in the current dependent AST file. + /// + /// When a decl changes fundamentally after being deserialized (this shouldn't + /// happen, but the ObjC AST nodes are designed this way), it will be + /// serialized again. In this case, it is registered here, so that the reader + /// knows to read the updated version. + llvm::SmallVector<std::pair<serialization::DeclID, uint64_t>, 16> + ReplacedDecls; + + typedef llvm::SmallVector<serialization::DeclID, 4> + AdditionalTemplateSpecializationsList; + typedef llvm::DenseMap<serialization::DeclID, + AdditionalTemplateSpecializationsList> + AdditionalTemplateSpecializationsMap; + + /// \brief Additional specializations (including partial) of templates that + /// were introduced after the template was serialized. + AdditionalTemplateSpecializationsMap AdditionalTemplateSpecializations; + + /// \brief Statements that we've encountered while serializing a + /// declaration or type. + llvm::SmallVector<Stmt *, 16> StmtsToEmit; + + /// \brief Statements collection to use for ASTWriter::AddStmt(). + /// It will point to StmtsToEmit unless it is overriden. + llvm::SmallVector<Stmt *, 16> *CollectedStmts; + + /// \brief Mapping from SwitchCase statements to IDs. + std::map<SwitchCase *, unsigned> SwitchCaseIDs; + + /// \brief Mapping from LabelStmt statements to IDs. + std::map<LabelStmt *, unsigned> LabelIDs; + + /// \brief The number of statements written to the AST file. + unsigned NumStatements; + + /// \brief The number of macros written to the AST file. + unsigned NumMacros; + + /// \brief The number of lexical declcontexts written to the AST + /// file. + unsigned NumLexicalDeclContexts; + + /// \brief The number of visible declcontexts written to the AST + /// file. + unsigned NumVisibleDeclContexts; + + /// \brief Write the given subexpression to the bitstream. + void WriteSubStmt(Stmt *S); + + void WriteBlockInfoBlock(); + void WriteMetadata(ASTContext &Context, const char *isysroot); + void WriteLanguageOptions(const LangOptions &LangOpts); + void WriteStatCache(MemorizeStatCalls &StatCalls); + void WriteSourceManagerBlock(SourceManager &SourceMgr, + const Preprocessor &PP, + const char* isysroot); + void WritePreprocessor(const Preprocessor &PP); + void WriteType(QualType T); + uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC); + uint64_t WriteDeclContextVisibleBlock(ASTContext &Context, DeclContext *DC); + void WriteTypeDeclOffsets(); + void WriteSelectors(Sema &SemaRef); + void WriteReferencedSelectorsPool(Sema &SemaRef); + void WriteIdentifierTable(Preprocessor &PP); + void WriteAttributeRecord(const AttrVec &Attrs); + void WriteDeclUpdateBlock(); + void WriteDeclContextVisibleUpdate(const DeclContext *DC); + void WriteAdditionalTemplateSpecializations(); + + unsigned ParmVarDeclAbbrev; + unsigned DeclContextLexicalAbbrev; + unsigned DeclContextVisibleLookupAbbrev; + unsigned UpdateVisibleAbbrev; + void WriteDeclsBlockAbbrevs(); + void WriteDecl(ASTContext &Context, Decl *D); + + void WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls, + const char* isysroot); + void WriteASTChain(Sema &SemaRef, MemorizeStatCalls *StatCalls, + const char* isysroot); + +public: + /// \brief Create a new precompiled header writer that outputs to + /// the given bitstream. + ASTWriter(llvm::BitstreamWriter &Stream); + + /// \brief Write a precompiled header for the given semantic analysis. + /// + /// \param SemaRef a reference to the semantic analysis object that processed + /// the AST to be written into the precompiled header. + /// + /// \param StatCalls the object that cached all of the stat() calls made while + /// searching for source files and headers. + /// + /// \param isysroot if non-NULL, write a relocatable PCH file whose headers + /// are relative to the given system root. + /// + /// \param PPRec Record of the preprocessing actions that occurred while + /// preprocessing this file, e.g., macro instantiations + void WriteAST(Sema &SemaRef, MemorizeStatCalls *StatCalls, + const char* isysroot); + + /// \brief Emit a source location. + void AddSourceLocation(SourceLocation Loc, RecordData &Record); + + /// \brief Emit a source range. + void AddSourceRange(SourceRange Range, RecordData &Record); + + /// \brief Emit an integral value. + void AddAPInt(const llvm::APInt &Value, RecordData &Record); + + /// \brief Emit a signed integral value. + void AddAPSInt(const llvm::APSInt &Value, RecordData &Record); + + /// \brief Emit a floating-point value. + void AddAPFloat(const llvm::APFloat &Value, RecordData &Record); + + /// \brief Emit a reference to an identifier. + void AddIdentifierRef(const IdentifierInfo *II, RecordData &Record); + + /// \brief Emit a Selector (which is a smart pointer reference). + void AddSelectorRef(Selector, RecordData &Record); + + /// \brief Emit a CXXTemporary. + void AddCXXTemporary(const CXXTemporary *Temp, RecordData &Record); + + /// \brief Get the unique number used to refer to the given selector. + serialization::SelectorID getSelectorRef(Selector Sel); + + /// \brief Get the unique number used to refer to the given identifier. + serialization::IdentID getIdentifierRef(const IdentifierInfo *II); + + /// \brief Retrieve the offset of the macro definition for the given + /// identifier. + /// + /// The identifier must refer to a macro. + uint64_t getMacroOffset(const IdentifierInfo *II) { + assert(MacroOffsets.find(II) != MacroOffsets.end() && + "Identifier does not name a macro"); + return MacroOffsets[II]; + } + + /// \brief Retrieve the ID number corresponding to the given macro + /// definition. + serialization::IdentID getMacroDefinitionID(MacroDefinition *MD); + + /// \brief Emit a reference to a type. + void AddTypeRef(QualType T, RecordData &Record); + + /// \brief Force a type to be emitted and get its ID. + serialization::TypeID GetOrCreateTypeID(QualType T); + + /// \brief Determine the type ID of an already-emitted type. + serialization::TypeID getTypeID(QualType T) const; + + /// \brief Force a type to be emitted and get its index. + serialization::TypeIdx GetOrCreateTypeIdx(QualType T); + + /// \brief Determine the type index of an already-emitted type. + serialization::TypeIdx getTypeIdx(QualType T) const; + + /// \brief Emits a reference to a declarator info. + void AddTypeSourceInfo(TypeSourceInfo *TInfo, RecordData &Record); + + /// \brief Emits a template argument location info. + void AddTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, + const TemplateArgumentLocInfo &Arg, + RecordData &Record); + + /// \brief Emits a template argument location. + void AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg, + RecordData &Record); + + /// \brief Emit a reference to a declaration. + void AddDeclRef(const Decl *D, RecordData &Record); + + /// \brief Force a declaration to be emitted and get its ID. + serialization::DeclID GetDeclRef(const Decl *D); + + /// \brief Determine the declaration ID of an already-emitted + /// declaration. + serialization::DeclID getDeclID(const Decl *D); + + /// \brief Emit a declaration name. + void AddDeclarationName(DeclarationName Name, RecordData &Record); + + /// \brief Emit a nested name specifier. + void AddNestedNameSpecifier(NestedNameSpecifier *NNS, RecordData &Record); + + /// \brief Emit a template name. + void AddTemplateName(TemplateName Name, RecordData &Record); + + /// \brief Emit a template argument. + void AddTemplateArgument(const TemplateArgument &Arg, RecordData &Record); + + /// \brief Emit a template parameter list. + void AddTemplateParameterList(const TemplateParameterList *TemplateParams, + RecordData &Record); + + /// \brief Emit a template argument list. + void AddTemplateArgumentList(const TemplateArgumentList *TemplateArgs, + RecordData &Record); + + /// \brief Emit a UnresolvedSet structure. + void AddUnresolvedSet(const UnresolvedSetImpl &Set, RecordData &Record); + + /// \brief Emit a C++ base specifier. + void AddCXXBaseSpecifier(const CXXBaseSpecifier &Base, RecordData &Record); + + /// \brief Emit a CXXBaseOrMemberInitializer array. + void AddCXXBaseOrMemberInitializers( + const CXXBaseOrMemberInitializer * const *BaseOrMembers, + unsigned NumBaseOrMembers, RecordData &Record); + + /// \brief Add a string to the given record. + void AddString(llvm::StringRef Str, RecordData &Record); + + /// \brief Mark a namespace as needing an update. + void AddUpdatedNamespace(const NamespaceDecl *NS) { + UpdatedNamespaces.insert(NS); + } + + /// \brief Record a template specialization or partial specialization of + /// a template from a previous PCH file. + void AddAdditionalTemplateSpecialization(serialization::DeclID Templ, + serialization::DeclID Spec) { + AdditionalTemplateSpecializations[Templ].push_back(Spec); + } + + /// \brief Note that the identifier II occurs at the given offset + /// within the identifier table. + void SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset); + + /// \brief Note that the selector Sel occurs at the given offset + /// within the method pool/selector table. + void SetSelectorOffset(Selector Sel, uint32_t Offset); + + /// \brief Add the given statement or expression to the queue of + /// statements to emit. + /// + /// This routine should be used when emitting types and declarations + /// that have expressions as part of their formulation. Once the + /// type or declaration has been written, call FlushStmts() to write + /// the corresponding statements just after the type or + /// declaration. + void AddStmt(Stmt *S) { + CollectedStmts->push_back(S); + } + + /// \brief Flush all of the statements and expressions that have + /// been added to the queue via AddStmt(). + void FlushStmts(); + + /// \brief Record an ID for the given switch-case statement. + unsigned RecordSwitchCaseID(SwitchCase *S); + + /// \brief Retrieve the ID for the given switch-case statement. + unsigned getSwitchCaseID(SwitchCase *S); + + /// \brief Retrieve the ID for the given label statement, which may + /// or may not have been emitted yet. + unsigned GetLabelID(LabelStmt *S); + + unsigned getParmVarDeclAbbrev() const { return ParmVarDeclAbbrev; } + + bool hasChain() const { return Chain; } + + // ASTDeserializationListener implementation + void SetReader(ASTReader *Reader); + void IdentifierRead(serialization::IdentID ID, IdentifierInfo *II); + void TypeRead(serialization::TypeIdx Idx, QualType T); + void DeclRead(serialization::DeclID ID, const Decl *D); + void SelectorRead(serialization::SelectorID iD, Selector Sel); +}; + +/// \brief AST and semantic-analysis consumer that generates a +/// precompiled header from the parsed source code. +class PCHGenerator : public SemaConsumer { + const Preprocessor &PP; + const char *isysroot; + llvm::raw_ostream *Out; + Sema *SemaPtr; + MemorizeStatCalls *StatCalls; // owned by the FileManager + std::vector<unsigned char> Buffer; + llvm::BitstreamWriter Stream; + ASTWriter Writer; + +protected: + ASTWriter &getWriter() { return Writer; } + const ASTWriter &getWriter() const { return Writer; } + +public: + PCHGenerator(const Preprocessor &PP, bool Chaining, + const char *isysroot, llvm::raw_ostream *Out); + virtual void InitializeSema(Sema &S) { SemaPtr = &S; } + virtual void HandleTranslationUnit(ASTContext &Ctx); + virtual ASTDeserializationListener *GetASTDeserializationListener(); +}; + +} // end namespace clang + +#endif diff --git a/include/clang/Serialization/CMakeLists.txt b/include/clang/Serialization/CMakeLists.txt new file mode 100644 index 0000000..3712009 --- /dev/null +++ b/include/clang/Serialization/CMakeLists.txt @@ -0,0 +1,12 @@ +set(LLVM_TARGET_DEFINITIONS ../Basic/Attr.td) +tablegen(AttrPCHRead.inc + -gen-clang-attr-pch-read + -I ${CMAKE_CURRENT_SOURCE_DIR}/../../) +add_custom_target(ClangAttrPCHRead + DEPENDS AttrPCHRead.inc) + +tablegen(AttrPCHWrite.inc + -gen-clang-attr-pch-write + -I ${CMAKE_CURRENT_SOURCE_DIR}/../../) +add_custom_target(ClangAttrPCHWrite + DEPENDS AttrPCHWrite.inc) diff --git a/include/clang/Serialization/Makefile b/include/clang/Serialization/Makefile new file mode 100644 index 0000000..79486b1 --- /dev/null +++ b/include/clang/Serialization/Makefile @@ -0,0 +1,19 @@ +CLANG_LEVEL := ../../.. +TD_SRC_DIR = $(PROJ_SRC_DIR)/../Basic +BUILT_SOURCES = AttrPCHRead.inc AttrPCHWrite.inc + +TABLEGEN_INC_FILES_COMMON = 1 + +include $(CLANG_LEVEL)/Makefile + +$(ObjDir)/AttrPCHRead.inc.tmp : $(TD_SRC_DIR)/Attr.td $(TBLGEN) \ + $(ObjDir)/.dir + $(Echo) "Building Clang PCH reader with tblgen" + $(Verb) $(TableGen) -gen-clang-attr-pch-read -o $(call SYSPATH, $@) \ + -I $(PROJ_SRC_DIR)/../../ $< + +$(ObjDir)/AttrPCHWrite.inc.tmp : $(TD_SRC_DIR)/Attr.td $(TBLGEN) \ + $(ObjDir)/.dir + $(Echo) "Building Clang PCH writer with tblgen" + $(Verb) $(TableGen) -gen-clang-attr-pch-write -o $(call SYSPATH, $@) \ + -I $(PROJ_SRC_DIR)/../../ $< |