clang API Documentation

ExternalSemaSource.h
Go to the documentation of this file.
00001 //===--- ExternalSemaSource.h - External Sema Interface ---------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //  This file defines the ExternalSemaSource interface.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 #ifndef LLVM_CLANG_SEMA_EXTERNALSEMASOURCE_H
00014 #define LLVM_CLANG_SEMA_EXTERNALSEMASOURCE_H
00015 
00016 #include "clang/AST/ExternalASTSource.h"
00017 #include "clang/AST/Type.h"
00018 #include "clang/Sema/TypoCorrection.h"
00019 #include "clang/Sema/Weak.h"
00020 #include "llvm/ADT/MapVector.h"
00021 #include <utility>
00022 
00023 namespace llvm {
00024 template <class T, unsigned n> class SmallSetVector;
00025 }
00026 
00027 namespace clang {
00028 
00029 class CXXConstructorDecl;
00030 class CXXRecordDecl;
00031 class DeclaratorDecl;
00032 class LookupResult;
00033 struct ObjCMethodList;
00034 class Scope;
00035 class Sema;
00036 class TypedefNameDecl;
00037 class ValueDecl;
00038 class VarDecl;
00039 struct LateParsedTemplate;
00040 
00041 /// \brief A simple structure that captures a vtable use for the purposes of
00042 /// the \c ExternalSemaSource.
00043 struct ExternalVTableUse {
00044   CXXRecordDecl *Record;
00045   SourceLocation Location;
00046   bool DefinitionRequired;
00047 };
00048   
00049 /// \brief An abstract interface that should be implemented by
00050 /// external AST sources that also provide information for semantic
00051 /// analysis.
00052 class ExternalSemaSource : public ExternalASTSource {
00053 public:
00054   ExternalSemaSource() {
00055     ExternalASTSource::SemaSource = true;
00056   }
00057 
00058   ~ExternalSemaSource();
00059 
00060   /// \brief Initialize the semantic source with the Sema instance
00061   /// being used to perform semantic analysis on the abstract syntax
00062   /// tree.
00063   virtual void InitializeSema(Sema &S) {}
00064 
00065   /// \brief Inform the semantic consumer that Sema is no longer available.
00066   virtual void ForgetSema() {}
00067 
00068   /// \brief Load the contents of the global method pool for a given
00069   /// selector.
00070   virtual void ReadMethodPool(Selector Sel);
00071 
00072   /// \brief Load the set of namespaces that are known to the external source,
00073   /// which will be used during typo correction.
00074   virtual void ReadKnownNamespaces(
00075                            SmallVectorImpl<NamespaceDecl *> &Namespaces);
00076 
00077   /// \brief Load the set of used but not defined functions or variables with
00078   /// internal linkage, or used but not defined internal functions.
00079   virtual void ReadUndefinedButUsed(
00080                          llvm::DenseMap<NamedDecl*, SourceLocation> &Undefined);
00081 
00082   /// \brief Do last resort, unqualified lookup on a LookupResult that
00083   /// Sema cannot find.
00084   ///
00085   /// \param R a LookupResult that is being recovered.
00086   ///
00087   /// \param S the Scope of the identifier occurrence.
00088   ///
00089   /// \return true to tell Sema to recover using the LookupResult.
00090   virtual bool LookupUnqualified(LookupResult &R, Scope *S) { return false; }
00091 
00092   /// \brief Read the set of tentative definitions known to the external Sema
00093   /// source.
00094   ///
00095   /// The external source should append its own tentative definitions to the
00096   /// given vector of tentative definitions. Note that this routine may be
00097   /// invoked multiple times; the external source should take care not to
00098   /// introduce the same declarations repeatedly.
00099   virtual void ReadTentativeDefinitions(
00100                                   SmallVectorImpl<VarDecl *> &TentativeDefs) {}
00101   
00102   /// \brief Read the set of unused file-scope declarations known to the
00103   /// external Sema source.
00104   ///
00105   /// The external source should append its own unused, filed-scope to the
00106   /// given vector of declarations. Note that this routine may be
00107   /// invoked multiple times; the external source should take care not to
00108   /// introduce the same declarations repeatedly.
00109   virtual void ReadUnusedFileScopedDecls(
00110                  SmallVectorImpl<const DeclaratorDecl *> &Decls) {}
00111   
00112   /// \brief Read the set of delegating constructors known to the
00113   /// external Sema source.
00114   ///
00115   /// The external source should append its own delegating constructors to the
00116   /// given vector of declarations. Note that this routine may be
00117   /// invoked multiple times; the external source should take care not to
00118   /// introduce the same declarations repeatedly.
00119   virtual void ReadDelegatingConstructors(
00120                  SmallVectorImpl<CXXConstructorDecl *> &Decls) {}
00121 
00122   /// \brief Read the set of ext_vector type declarations known to the
00123   /// external Sema source.
00124   ///
00125   /// The external source should append its own ext_vector type declarations to
00126   /// the given vector of declarations. Note that this routine may be
00127   /// invoked multiple times; the external source should take care not to
00128   /// introduce the same declarations repeatedly.
00129   virtual void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) {}
00130 
00131   /// \brief Read the set of dynamic classes known to the external Sema source.
00132   ///
00133   /// The external source should append its own dynamic classes to
00134   /// the given vector of declarations. Note that this routine may be
00135   /// invoked multiple times; the external source should take care not to
00136   /// introduce the same declarations repeatedly.
00137   virtual void ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls) {}
00138 
00139   /// \brief Read the set of potentially unused typedefs known to the source.
00140   ///
00141   /// The external source should append its own potentially unused local
00142   /// typedefs to the given vector of declarations. Note that this routine may
00143   /// be invoked multiple times; the external source should take care not to
00144   /// introduce the same declarations repeatedly.
00145   virtual void ReadUnusedLocalTypedefNameCandidates(
00146       llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) {};
00147 
00148   /// \brief Read the set of locally-scoped external declarations known to the
00149   /// external Sema source.
00150   ///
00151   /// The external source should append its own locally-scoped external
00152   /// declarations to the given vector of declarations. Note that this routine 
00153   /// may be invoked multiple times; the external source should take care not 
00154   /// to introduce the same declarations repeatedly.
00155   virtual void ReadLocallyScopedExternCDecls(
00156                  SmallVectorImpl<NamedDecl *> &Decls) {}
00157 
00158   /// \brief Read the set of referenced selectors known to the
00159   /// external Sema source.
00160   ///
00161   /// The external source should append its own referenced selectors to the 
00162   /// given vector of selectors. Note that this routine 
00163   /// may be invoked multiple times; the external source should take care not 
00164   /// to introduce the same selectors repeatedly.
00165   virtual void ReadReferencedSelectors(
00166                  SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) {}
00167 
00168   /// \brief Read the set of weak, undeclared identifiers known to the
00169   /// external Sema source.
00170   ///
00171   /// The external source should append its own weak, undeclared identifiers to
00172   /// the given vector. Note that this routine may be invoked multiple times; 
00173   /// the external source should take care not to introduce the same identifiers
00174   /// repeatedly.
00175   virtual void ReadWeakUndeclaredIdentifiers(
00176                  SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI) {}
00177 
00178   /// \brief Read the set of used vtables known to the external Sema source.
00179   ///
00180   /// The external source should append its own used vtables to the given
00181   /// vector. Note that this routine may be invoked multiple times; the external
00182   /// source should take care not to introduce the same vtables repeatedly.
00183   virtual void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) {}
00184 
00185   /// \brief Read the set of pending instantiations known to the external
00186   /// Sema source.
00187   ///
00188   /// The external source should append its own pending instantiations to the
00189   /// given vector. Note that this routine may be invoked multiple times; the
00190   /// external source should take care not to introduce the same instantiations
00191   /// repeatedly.
00192   virtual void ReadPendingInstantiations(
00193                  SmallVectorImpl<std::pair<ValueDecl *, 
00194                                            SourceLocation> > &Pending) {}
00195 
00196   /// \brief Read the set of late parsed template functions for this source.
00197   ///
00198   /// The external source should insert its own late parsed template functions
00199   /// into the map. Note that this routine may be invoked multiple times; the
00200   /// external source should take care not to introduce the same map entries
00201   /// repeatedly.
00202   virtual void ReadLateParsedTemplates(
00203       llvm::DenseMap<const FunctionDecl *, LateParsedTemplate *> &LPTMap) {}
00204 
00205   /// \copydoc Sema::CorrectTypo
00206   /// \note LookupKind must correspond to a valid Sema::LookupNameKind
00207   ///
00208   /// ExternalSemaSource::CorrectTypo is always given the first chance to
00209   /// correct a typo (really, to offer suggestions to repair a failed lookup).
00210   /// It will even be called when SpellChecking is turned off or after a
00211   /// fatal error has already been detected.
00212   virtual TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo,
00213                                      int LookupKind, Scope *S, CXXScopeSpec *SS,
00214                                      CorrectionCandidateCallback &CCC,
00215                                      DeclContext *MemberContext,
00216                                      bool EnteringContext,
00217                                      const ObjCObjectPointerType *OPT) {
00218     return TypoCorrection();
00219   }
00220 
00221   /// \brief Produces a diagnostic note if the external source contains a
00222   /// complete definition for \p T.
00223   ///
00224   /// \param Loc the location at which a complete type was required but not
00225   /// provided
00226   ///
00227   /// \param T the \c QualType that should have been complete at \p Loc
00228   ///
00229   /// \return true if a diagnostic was produced, false otherwise.
00230   virtual bool MaybeDiagnoseMissingCompleteType(SourceLocation Loc,
00231                                                 QualType T) {
00232     return false;
00233   }
00234 
00235   // isa/cast/dyn_cast support
00236   static bool classof(const ExternalASTSource *Source) {
00237     return Source->SemaSource;
00238   }
00239 }; 
00240 
00241 } // end namespace clang
00242 
00243 #endif