summaryrefslogtreecommitdiff
path: root/include/clang/Frontend
diff options
context:
space:
mode:
authorRoman Divacky <rdivacky@FreeBSD.org>2009-10-23 14:22:18 +0000
committerRoman Divacky <rdivacky@FreeBSD.org>2009-10-23 14:22:18 +0000
commit73490b890977362d28dd6326843a1ecae413921d (patch)
tree3fdd91eae574e32453a4baf462961c742df2691a /include/clang/Frontend
parenta5f348eb914e67b51914117fac117c18c1f8d650 (diff)
Diffstat (limited to 'include/clang/Frontend')
-rw-r--r--include/clang/Frontend/ASTUnit.h38
-rw-r--r--include/clang/Frontend/PCHBitCodes.h65
-rw-r--r--include/clang/Frontend/PCHReader.h16
-rw-r--r--include/clang/Frontend/PCHWriter.h43
4 files changed, 106 insertions, 56 deletions
diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h
index 89eb3b8821ca0..9573777b5f6fb 100644
--- a/include/clang/Frontend/ASTUnit.h
+++ b/include/clang/Frontend/ASTUnit.h
@@ -16,6 +16,8 @@
#include "clang/Basic/SourceManager.h"
#include "llvm/ADT/OwningPtr.h"
+#include "clang/Frontend/TextDiagnosticBuffer.h"
+#include "clang/Basic/FileManager.h"
#include <string>
namespace clang {
@@ -23,6 +25,7 @@ namespace clang {
class FileEntry;
class SourceManager;
class Diagnostic;
+ class TextDiagnosticBuffer;
class HeaderSearch;
class TargetInfo;
class Preprocessor;
@@ -32,18 +35,27 @@ namespace clang {
/// \brief Utility class for loading a ASTContext from a PCH file.
///
class ASTUnit {
- Diagnostic &Diags;
+ Diagnostic Diags;
+ FileManager FileMgr;
+
SourceManager SourceMgr;
llvm::OwningPtr<HeaderSearch> HeaderInfo;
llvm::OwningPtr<TargetInfo> Target;
llvm::OwningPtr<Preprocessor> PP;
llvm::OwningPtr<ASTContext> Ctx;
-
+ bool tempFile;
+
+ // OnlyLocalDecls - when true, walking this AST should only visit declarations
+ // that come from the AST itself, not from included precompiled headers.
+ // FIXME: This is temporary; eventually, CIndex will always do this.
+ bool OnlyLocalDecls;
+
ASTUnit(const ASTUnit&); // DO NOT IMPLEMENT
ASTUnit &operator=(const ASTUnit &); // DO NOT IMPLEMENT
- ASTUnit(Diagnostic &_Diag);
+ ASTUnit();
public:
+ ASTUnit(DiagnosticClient *diagClient = NULL);
~ASTUnit();
const SourceManager &getSourceManager() const { return SourceMgr; }
@@ -58,14 +70,23 @@ public:
const Diagnostic &getDiagnostic() const { return Diags; }
Diagnostic &getDiagnostic() { return Diags; }
- FileManager &getFileManager();
+ const FileManager &getFileManager() const { return FileMgr; }
+ FileManager &getFileManager() { return FileMgr; }
+
const std::string &getOriginalSourceFileName();
+ const std::string &getPCHFileName();
+ void unlinkTemporaryFile() { tempFile = true; }
+
+ bool getOnlyLocalDecls() const { return OnlyLocalDecls; }
+
/// \brief Create a ASTUnit from a PCH file.
///
/// \param Filename - The PCH file to load.
///
- /// \param Diags - The Diagnostic implementation to use.
+ /// \param diagClient - The diagnostics client to use. Specify NULL
+ /// to use a default client that emits warnings/errors to standard error.
+ /// The ASTUnit objects takes ownership of this object.
///
/// \param FileMgr - The FileManager to use.
///
@@ -74,9 +95,10 @@ public:
///
/// \returns - The initialized ASTUnit or null if the PCH failed to load.
static ASTUnit *LoadFromPCHFile(const std::string &Filename,
- Diagnostic &Diags,
- FileManager &FileMgr,
- std::string *ErrMsg = 0);
+ std::string *ErrMsg = 0,
+ DiagnosticClient *diagClient = NULL,
+ bool OnlyLocalDecls = false,
+ bool UseBumpAllocator = false);
};
} // namespace clang
diff --git a/include/clang/Frontend/PCHBitCodes.h b/include/clang/Frontend/PCHBitCodes.h
index 716780e68a528..1e953d6712266 100644
--- a/include/clang/Frontend/PCHBitCodes.h
+++ b/include/clang/Frontend/PCHBitCodes.h
@@ -86,38 +86,33 @@ namespace clang {
PREPROCESSOR_BLOCK_ID,
/// \brief The block containing the definitions of all of the
- /// types used within the PCH file.
- TYPES_BLOCK_ID,
-
- /// \brief The block containing the definitions of all of the
- /// declarations stored in the PCH file.
- DECLS_BLOCK_ID
+ /// types and decls used within the PCH file.
+ DECLTYPES_BLOCK_ID
};
/// \brief Record types that occur within the PCH block itself.
enum PCHRecordTypes {
- /// \brief Offset of each type within the types block.
+ /// \brief Record code for the offsets of each type.
///
/// The TYPE_OFFSET constant describes the record that occurs
- /// within the block identified by TYPE_OFFSETS_BLOCK_ID within
- /// the PCH file. The record itself is an array of offsets that
- /// point into the types block (identified by TYPES_BLOCK_ID in
- /// the PCH file). The index into the array is based on the ID
+ /// within the PCH 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 TYPES_BLOCK_ID block.
+ /// 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 identifier by DECL_OFFSETS_BLOCK_ID within
- /// the PCH file. The record itself is an array of offsets that
- /// point into the declarations block (identified by
- /// DECLS_BLOCK_ID). The declaration ID is an index into this
+ /// within the block identified by DECL_OFFSETS_BLOCK_ID within
+ /// the PCH 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.
@@ -353,8 +348,8 @@ namespace clang {
/// \brief Record codes for each kind of type.
///
- /// These constants describe the records that can occur within a
- /// block identified by TYPES_BLOCK_ID in the PCH file. Each
+ /// These constants describe the type records that can occur within a
+ /// block identified by DECLTYPES_BLOCK_ID in the PCH file. Each
/// constant describes a record for a specific type class in the
/// AST.
enum TypeCode {
@@ -402,16 +397,12 @@ namespace clang {
TYPE_OBJC_INTERFACE = 21,
/// \brief An ObjCObjectPointerType record.
TYPE_OBJC_OBJECT_POINTER = 22,
- /// \brief An ObjCProtocolListType record.
- TYPE_OBJC_PROTOCOL_LIST = 23,
/// \brief a DecltypeType record.
- TYPE_DECLTYPE = 24,
- /// \brief A ConstantArrayWithExprType record.
- TYPE_CONSTANT_ARRAY_WITH_EXPR = 25,
- /// \brief A ConstantArrayWithoutExprType record.
- TYPE_CONSTANT_ARRAY_WITHOUT_EXPR = 26,
+ TYPE_DECLTYPE = 23,
/// \brief An ElaboratedType record.
- TYPE_ELABORATED = 27
+ TYPE_ELABORATED = 24,
+ /// \brief A SubstTemplateTypeParmType record.
+ TYPE_SUBST_TEMPLATE_TYPE_PARM = 25
};
/// \brief The type IDs for special types constructed by semantic
@@ -443,18 +434,22 @@ namespace clang {
/// \brief Objective-C "id" redefinition type
SPECIAL_TYPE_OBJC_ID_REDEFINITION = 10,
/// \brief Objective-C "Class" redefinition type
- SPECIAL_TYPE_OBJC_CLASS_REDEFINITION = 11
+ 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 Record codes for each kind of declaration.
///
- /// These constants describe the records that can occur within a
- /// declarations block (identified by DECLS_BLOCK_ID). Each
+ /// 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 = 1,
+ DECL_ATTR = 50,
/// \brief A TranslationUnitDecl record.
DECL_TRANSLATION_UNIT,
/// \brief A TypedefDecl record.
@@ -529,14 +524,14 @@ namespace clang {
/// \brief Record codes for each kind of statement or expression.
///
/// These constants describe the records that describe statements
- /// or expressions. These records can occur within either the type
- /// or declaration blocks, so they begin with record values of
- /// 50. Each constant describes a record for a specific
- /// statement or expression class in the AST.
+ /// 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 = 50,
+ STMT_STOP = 100,
/// \brief A NULL expression.
STMT_NULL_PTR,
/// \brief A NullStmt record.
diff --git a/include/clang/Frontend/PCHReader.h b/include/clang/Frontend/PCHReader.h
index 1230e3753e04d..cc16970b00401 100644
--- a/include/clang/Frontend/PCHReader.h
+++ b/include/clang/Frontend/PCHReader.h
@@ -169,6 +169,11 @@ private:
/// \brief The AST context into which we'll read the PCH file.
ASTContext *Context;
+ /// \brief The PCH stat cache installed by this PCHReader, if any.
+ ///
+ /// The dynamic type of this stat cache is always PCHStatCache
+ void *StatCache;
+
/// \brief The AST consumer.
ASTConsumer *Consumer;
@@ -492,8 +497,8 @@ public:
/// \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 "/".
- PCHReader(SourceManager &SourceMgr, FileManager &FileMgr,
- Diagnostic &Diags, const char *isysroot = 0);
+ PCHReader(SourceManager &SourceMgr, FileManager &FileMgr,
+ Diagnostic &Diags, const char *isysroot = 0);
~PCHReader();
/// \brief Load the precompiled header designated by the given file
@@ -513,6 +518,9 @@ public:
/// \brief Sets and initializes the given Context.
void InitializeContext(ASTContext &Context);
+ /// \brief Retrieve the name of the PCH file
+ const std::string &getFileName() { return FileName; }
+
/// \brief Retrieve the name of the original source file name
const std::string &getOriginalSourceFile() { return OriginalFileName; }
@@ -534,6 +542,10 @@ public:
/// comments in the source code.
virtual void ReadComments(std::vector<SourceRange> &Comments);
+ /// \brief Reads a declarator info from the given record.
+ virtual DeclaratorInfo *GetDeclaratorInfo(const RecordData &Record,
+ unsigned &Idx);
+
/// \brief Resolve a type ID into a type, potentially building a new
/// type.
virtual QualType GetType(pch::TypeID ID);
diff --git a/include/clang/Frontend/PCHWriter.h b/include/clang/Frontend/PCHWriter.h
index a807cd7c4d1fa..728e138d9e7c6 100644
--- a/include/clang/Frontend/PCHWriter.h
+++ b/include/clang/Frontend/PCHWriter.h
@@ -73,6 +73,33 @@ private:
/// \brief The bitstream writer used to emit this precompiled header.
llvm::BitstreamWriter &Stream;
+ /// \brief Stores a declaration or a type to be written to the PCH 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 Map that provides the ID numbers of each declaration within
/// the output stream.
///
@@ -85,10 +112,6 @@ private:
/// the declaration's ID.
std::vector<uint32_t> DeclOffsets;
- /// \brief Queue containing the declarations that we still need to
- /// emit.
- std::queue<Decl *> DeclsToEmit;
-
/// \brief Map that provides the ID numbers of each type within the
/// output stream.
///
@@ -107,10 +130,6 @@ private:
/// \brief The type ID that will be assigned to the next new type.
pch::TypeID NextTypeID;
- /// \brief Queue containing the types that we still need to
- /// emit.
- std::queue<QualType> TypesToEmit;
-
/// \brief Map that provides the ID numbers of each identifier in
/// the output stream.
///
@@ -189,18 +208,17 @@ private:
void WritePreprocessor(const Preprocessor &PP);
void WriteComments(ASTContext &Context);
void WriteType(QualType T);
- void WriteTypesBlock(ASTContext &Context);
uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC);
uint64_t WriteDeclContextVisibleBlock(ASTContext &Context, DeclContext *DC);
- void WriteDeclsBlock(ASTContext &Context);
void WriteMethodPool(Sema &SemaRef);
void WriteIdentifierTable(Preprocessor &PP);
void WriteAttributeRecord(const Attr *Attr);
unsigned ParmVarDeclAbbrev;
void WriteDeclsBlockAbbrevs();
-
+ void WriteDecl(ASTContext &Context, Decl *D);
+
public:
/// \brief Create a new precompiled header writer that outputs to
/// the given bitstream.
@@ -254,6 +272,9 @@ public:
/// \brief Emit a reference to a type.
void AddTypeRef(QualType T, RecordData &Record);
+ /// \brief Emits a reference to a declarator info.
+ void AddDeclaratorInfo(DeclaratorInfo *DInfo, RecordData &Record);
+
/// \brief Emit a reference to a declaration.
void AddDeclRef(const Decl *D, RecordData &Record);