1193326Sed//===--- ExternalSemaSource.h - External Sema Interface ---------*- C++ -*-===// 2193326Sed// 3193326Sed// The LLVM Compiler Infrastructure 4193326Sed// 5193326Sed// This file is distributed under the University of Illinois Open Source 6193326Sed// License. See LICENSE.TXT for details. 7193326Sed// 8193326Sed//===----------------------------------------------------------------------===// 9193326Sed// 10193326Sed// This file defines the ExternalSemaSource interface. 11193326Sed// 12193326Sed//===----------------------------------------------------------------------===// 13193326Sed#ifndef LLVM_CLANG_SEMA_EXTERNAL_SEMA_SOURCE_H 14193326Sed#define LLVM_CLANG_SEMA_EXTERNAL_SEMA_SOURCE_H 15193326Sed 16193326Sed#include "clang/AST/ExternalASTSource.h" 17263508Sdim#include "clang/AST/Type.h" 18263508Sdim#include "clang/Sema/TypoCorrection.h" 19226633Sdim#include "clang/Sema/Weak.h" 20249423Sdim#include "llvm/ADT/MapVector.h" 21218893Sdim#include <utility> 22193326Sed 23193326Sednamespace clang { 24193326Sed 25226633Sdimclass CXXConstructorDecl; 26226633Sdimclass CXXRecordDecl; 27226633Sdimclass DeclaratorDecl; 28226633Sdimclass LookupResult; 29218893Sdimstruct ObjCMethodList; 30226633Sdimclass Scope; 31193326Sedclass Sema; 32226633Sdimclass TypedefNameDecl; 33226633Sdimclass ValueDecl; 34226633Sdimclass VarDecl; 35263508Sdimstruct LateParsedTemplate; 36263508Sdim 37226633Sdim/// \brief A simple structure that captures a vtable use for the purposes of 38226633Sdim/// the \c ExternalSemaSource. 39226633Sdimstruct ExternalVTableUse { 40226633Sdim CXXRecordDecl *Record; 41226633Sdim SourceLocation Location; 42226633Sdim bool DefinitionRequired; 43226633Sdim}; 44226633Sdim 45193326Sed/// \brief An abstract interface that should be implemented by 46193326Sed/// external AST sources that also provide information for semantic 47193326Sed/// analysis. 48193326Sedclass ExternalSemaSource : public ExternalASTSource { 49193326Sedpublic: 50193326Sed ExternalSemaSource() { 51193326Sed ExternalASTSource::SemaSource = true; 52193326Sed } 53193326Sed 54210299Sed ~ExternalSemaSource(); 55210299Sed 56193326Sed /// \brief Initialize the semantic source with the Sema instance 57193326Sed /// being used to perform semantic analysis on the abstract syntax 58193326Sed /// tree. 59193326Sed virtual void InitializeSema(Sema &S) {} 60193326Sed 61200583Srdivacky /// \brief Inform the semantic consumer that Sema is no longer available. 62200583Srdivacky virtual void ForgetSema() {} 63200583Srdivacky 64193326Sed /// \brief Load the contents of the global method pool for a given 65193326Sed /// selector. 66234353Sdim virtual void ReadMethodPool(Selector Sel); 67198092Srdivacky 68224145Sdim /// \brief Load the set of namespaces that are known to the external source, 69224145Sdim /// which will be used during typo correction. 70224145Sdim virtual void ReadKnownNamespaces( 71226633Sdim SmallVectorImpl<NamespaceDecl *> &Namespaces); 72249423Sdim 73249423Sdim /// \brief Load the set of used but not defined functions or variables with 74249423Sdim /// internal linkage, or used but not defined internal functions. 75249423Sdim virtual void ReadUndefinedButUsed( 76249423Sdim llvm::DenseMap<NamedDecl*, SourceLocation> &Undefined); 77249423Sdim 78219077Sdim /// \brief Do last resort, unqualified lookup on a LookupResult that 79219077Sdim /// Sema cannot find. 80219077Sdim /// 81219077Sdim /// \param R a LookupResult that is being recovered. 82219077Sdim /// 83219077Sdim /// \param S the Scope of the identifier occurrence. 84219077Sdim /// 85219077Sdim /// \return true to tell Sema to recover using the LookupResult. 86219077Sdim virtual bool LookupUnqualified(LookupResult &R, Scope *S) { return false; } 87219077Sdim 88226633Sdim /// \brief Read the set of tentative definitions known to the external Sema 89226633Sdim /// source. 90226633Sdim /// 91226633Sdim /// The external source should append its own tentative definitions to the 92226633Sdim /// given vector of tentative definitions. Note that this routine may be 93226633Sdim /// invoked multiple times; the external source should take care not to 94226633Sdim /// introduce the same declarations repeatedly. 95226633Sdim virtual void ReadTentativeDefinitions( 96226633Sdim SmallVectorImpl<VarDecl *> &TentativeDefs) {} 97226633Sdim 98226633Sdim /// \brief Read the set of unused file-scope declarations known to the 99226633Sdim /// external Sema source. 100226633Sdim /// 101226633Sdim /// The external source should append its own unused, filed-scope to the 102226633Sdim /// given vector of declarations. Note that this routine may be 103226633Sdim /// invoked multiple times; the external source should take care not to 104226633Sdim /// introduce the same declarations repeatedly. 105226633Sdim virtual void ReadUnusedFileScopedDecls( 106226633Sdim SmallVectorImpl<const DeclaratorDecl *> &Decls) {} 107226633Sdim 108226633Sdim /// \brief Read the set of delegating constructors known to the 109226633Sdim /// external Sema source. 110226633Sdim /// 111226633Sdim /// The external source should append its own delegating constructors to the 112226633Sdim /// given vector of declarations. Note that this routine may be 113226633Sdim /// invoked multiple times; the external source should take care not to 114226633Sdim /// introduce the same declarations repeatedly. 115226633Sdim virtual void ReadDelegatingConstructors( 116226633Sdim SmallVectorImpl<CXXConstructorDecl *> &Decls) {} 117226633Sdim 118226633Sdim /// \brief Read the set of ext_vector type declarations known to the 119226633Sdim /// external Sema source. 120226633Sdim /// 121226633Sdim /// The external source should append its own ext_vector type declarations to 122226633Sdim /// the given vector of declarations. Note that this routine may be 123226633Sdim /// invoked multiple times; the external source should take care not to 124226633Sdim /// introduce the same declarations repeatedly. 125226633Sdim virtual void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) {} 126226633Sdim 127226633Sdim /// \brief Read the set of dynamic classes known to the external Sema source. 128226633Sdim /// 129226633Sdim /// The external source should append its own dynamic classes to 130226633Sdim /// the given vector of declarations. Note that this routine may be 131226633Sdim /// invoked multiple times; the external source should take care not to 132226633Sdim /// introduce the same declarations repeatedly. 133226633Sdim virtual void ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls) {} 134226633Sdim 135226633Sdim /// \brief Read the set of locally-scoped external declarations known to the 136226633Sdim /// external Sema source. 137226633Sdim /// 138226633Sdim /// The external source should append its own locally-scoped external 139226633Sdim /// declarations to the given vector of declarations. Note that this routine 140226633Sdim /// may be invoked multiple times; the external source should take care not 141226633Sdim /// to introduce the same declarations repeatedly. 142249423Sdim virtual void ReadLocallyScopedExternCDecls( 143226633Sdim SmallVectorImpl<NamedDecl *> &Decls) {} 144226633Sdim 145226633Sdim /// \brief Read the set of referenced selectors known to the 146226633Sdim /// external Sema source. 147226633Sdim /// 148226633Sdim /// The external source should append its own referenced selectors to the 149226633Sdim /// given vector of selectors. Note that this routine 150226633Sdim /// may be invoked multiple times; the external source should take care not 151226633Sdim /// to introduce the same selectors repeatedly. 152226633Sdim virtual void ReadReferencedSelectors( 153226633Sdim SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) {} 154226633Sdim 155226633Sdim /// \brief Read the set of weak, undeclared identifiers known to the 156226633Sdim /// external Sema source. 157226633Sdim /// 158226633Sdim /// The external source should append its own weak, undeclared identifiers to 159226633Sdim /// the given vector. Note that this routine may be invoked multiple times; 160226633Sdim /// the external source should take care not to introduce the same identifiers 161226633Sdim /// repeatedly. 162226633Sdim virtual void ReadWeakUndeclaredIdentifiers( 163226633Sdim SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI) {} 164226633Sdim 165226633Sdim /// \brief Read the set of used vtables known to the external Sema source. 166226633Sdim /// 167226633Sdim /// The external source should append its own used vtables to the given 168226633Sdim /// vector. Note that this routine may be invoked multiple times; the external 169226633Sdim /// source should take care not to introduce the same vtables repeatedly. 170226633Sdim virtual void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) {} 171226633Sdim 172226633Sdim /// \brief Read the set of pending instantiations known to the external 173226633Sdim /// Sema source. 174226633Sdim /// 175226633Sdim /// The external source should append its own pending instantiations to the 176226633Sdim /// given vector. Note that this routine may be invoked multiple times; the 177226633Sdim /// external source should take care not to introduce the same instantiations 178226633Sdim /// repeatedly. 179226633Sdim virtual void ReadPendingInstantiations( 180226633Sdim SmallVectorImpl<std::pair<ValueDecl *, 181226633Sdim SourceLocation> > &Pending) {} 182226633Sdim 183263508Sdim /// \brief Read the set of late parsed template functions for this source. 184263508Sdim /// 185263508Sdim /// The external source should insert its own late parsed template functions 186263508Sdim /// into the map. Note that this routine may be invoked multiple times; the 187263508Sdim /// external source should take care not to introduce the same map entries 188263508Sdim /// repeatedly. 189263508Sdim virtual void ReadLateParsedTemplates( 190263508Sdim llvm::DenseMap<const FunctionDecl *, LateParsedTemplate *> &LPTMap) {} 191263508Sdim 192263508Sdim /// \copydoc Sema::CorrectTypo 193263508Sdim /// \note LookupKind must correspond to a valid Sema::LookupNameKind 194263508Sdim /// 195263508Sdim /// ExternalSemaSource::CorrectTypo is always given the first chance to 196263508Sdim /// correct a typo (really, to offer suggestions to repair a failed lookup). 197263508Sdim /// It will even be called when SpellChecking is turned off or after a 198263508Sdim /// fatal error has already been detected. 199263508Sdim virtual TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, 200263508Sdim int LookupKind, Scope *S, CXXScopeSpec *SS, 201263508Sdim CorrectionCandidateCallback &CCC, 202263508Sdim DeclContext *MemberContext, 203263508Sdim bool EnteringContext, 204263508Sdim const ObjCObjectPointerType *OPT) { 205263508Sdim return TypoCorrection(); 206263508Sdim } 207263508Sdim 208263508Sdim /// \brief Produces a diagnostic note if the external source contains a 209263508Sdim /// complete definition for \p T. 210263508Sdim /// 211263508Sdim /// \param Loc the location at which a complete type was required but not 212263508Sdim /// provided 213263508Sdim /// 214263508Sdim /// \param T the \c QualType that should have been complete at \p Loc 215263508Sdim /// 216263508Sdim /// \return true if a diagnostic was produced, false otherwise. 217263508Sdim virtual bool MaybeDiagnoseMissingCompleteType(SourceLocation Loc, 218263508Sdim QualType T) { 219263508Sdim return false; 220263508Sdim } 221263508Sdim 222193326Sed // isa/cast/dyn_cast support 223198092Srdivacky static bool classof(const ExternalASTSource *Source) { 224193326Sed return Source->SemaSource; 225193326Sed } 226226633Sdim}; 227193326Sed 228193326Sed} // end namespace clang 229193326Sed 230193326Sed#endif 231