ExternalASTSource.h revision 631f6c64882b5254c5e4dbde6ec604dd4b96fd23
1//===--- ExternalASTSource.h - Abstract External AST Interface --*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines the ExternalASTSource interface, 11// 12//===----------------------------------------------------------------------===// 13#ifndef LLVM_CLANG_AST_EXTERNAL_AST_SOURCE_H 14#define LLVM_CLANG_AST_EXTERNAL_AST_SOURCE_H 15 16#include "clang/AST/DeclarationName.h" 17#include "clang/AST/Type.h" 18#include "llvm/ADT/SmallVector.h" 19namespace clang { 20 21class ASTConsumer; 22class Decl; 23class DeclContext; 24 25/// \brief The deserialized representation of a set of declarations 26/// with the same name that are visible in a given context. 27struct VisibleDeclaration { 28 /// \brief The name of the declarations. 29 DeclarationName Name; 30 31 /// \brief The ID numbers of all of the declarations with this name. 32 /// 33 /// These declarations have not necessarily been de-serialized. 34 llvm::SmallVector<unsigned, 4> Declarations; 35}; 36 37/// \brief Abstract interface for external sources of AST nodes. 38/// 39/// External AST sources provide AST nodes constructed from some 40/// external source, such as a precompiled header. External AST 41/// sources can resolve types and declarations from abstract IDs into 42/// actual type and declaration nodes, and read parts of declaration 43/// contexts. 44class ExternalASTSource { 45public: 46 virtual ~ExternalASTSource(); 47 48 /// \brief Resolve a type ID into a type, potentially building a new 49 /// type. 50 virtual QualType GetType(unsigned ID) = 0; 51 52 /// \brief Resolve a declaration ID into a declaration, potentially 53 /// building a new declaration. 54 virtual Decl *GetDecl(unsigned ID) = 0; 55 56 /// \brief Read all of the declarations lexically stored in a 57 /// declaration context. 58 /// 59 /// \param DC The declaration context whose declarations will be 60 /// read. 61 /// 62 /// \param Decls Vector that will contain the declarations loaded 63 /// from the external source. The caller is responsible for merging 64 /// these declarations with any declarations already stored in the 65 /// declaration context. 66 /// 67 /// \returns true if there was an error while reading the 68 /// declarations for this declaration context. 69 virtual bool ReadDeclsLexicallyInContext(DeclContext *DC, 70 llvm::SmallVectorImpl<unsigned> &Decls) = 0; 71 72 /// \brief Read all of the declarations visible from a declaration 73 /// context. 74 /// 75 /// \param DC The declaration context whose visible declarations 76 /// will be read. 77 /// 78 /// \param Decls A vector of visible declaration structures, 79 /// providing the mapping from each name visible in the declaration 80 /// context to the declaration IDs of declarations with that name. 81 /// 82 /// \returns true if there was an error while reading the 83 /// declarations for this declaration context. 84 virtual bool ReadDeclsVisibleInContext(DeclContext *DC, 85 llvm::SmallVectorImpl<VisibleDeclaration> & Decls) = 0; 86 87 /// \brief Function that will be invoked when we begin parsing a new 88 /// translation unit involving this external AST source. 89 virtual void StartTranslationUnit(ASTConsumer *Consumer); 90 91 /// \brief Print any statistics that have been gathered regarding 92 /// the external AST source. 93 virtual void PrintStats(); 94}; 95 96} // end namespace clang 97 98#endif // LLVM_CLANG_AST_EXTERNAL_AST_SOURCE_H 99