clang API Documentation

MultiplexExternalSemaSource.h
Go to the documentation of this file.
00001 //===--- MultiplexExternalSemaSource.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 ExternalSemaSource interface, dispatching to all clients
00011 //
00012 //===----------------------------------------------------------------------===//
00013 #ifndef LLVM_CLANG_SEMA_MULTIPLEXEXTERNALSEMASOURCE_H
00014 #define LLVM_CLANG_SEMA_MULTIPLEXEXTERNALSEMASOURCE_H
00015 
00016 #include "clang/Sema/ExternalSemaSource.h"
00017 #include "clang/Sema/Weak.h"
00018 #include "llvm/ADT/SmallVector.h"
00019 #include <utility>
00020 
00021 namespace clang {
00022 
00023   class CXXConstructorDecl;
00024   class CXXRecordDecl;
00025   class DeclaratorDecl;
00026   struct ExternalVTableUse;
00027   class LookupResult;
00028   class NamespaceDecl;
00029   class Scope;
00030   class Sema;
00031   class TypedefNameDecl;
00032   class ValueDecl;
00033   class VarDecl;
00034 
00035 
00036 /// \brief An abstract interface that should be implemented by
00037 /// external AST sources that also provide information for semantic
00038 /// analysis.
00039 class MultiplexExternalSemaSource : public ExternalSemaSource {
00040 
00041 private:
00042   SmallVector<ExternalSemaSource *, 2> Sources; // doesn't own them.
00043 
00044 public:
00045   
00046   ///\brief Constructs a new multiplexing external sema source and appends the
00047   /// given element to it.
00048   ///
00049   ///\param[in] s1 - A non-null (old) ExternalSemaSource.
00050   ///\param[in] s2 - A non-null (new) ExternalSemaSource.
00051   ///
00052   MultiplexExternalSemaSource(ExternalSemaSource& s1, ExternalSemaSource& s2);
00053 
00054   ~MultiplexExternalSemaSource();
00055 
00056   ///\brief Appends new source to the source list.
00057   ///
00058   ///\param[in] source - An ExternalSemaSource.
00059   ///
00060   void addSource(ExternalSemaSource &source);
00061 
00062   //===--------------------------------------------------------------------===//
00063   // ExternalASTSource.
00064   //===--------------------------------------------------------------------===//
00065 
00066   /// \brief Resolve a declaration ID into a declaration, potentially
00067   /// building a new declaration.
00068   Decl *GetExternalDecl(uint32_t ID) override;
00069 
00070   /// \brief Complete the redeclaration chain if it's been extended since the
00071   /// previous generation of the AST source.
00072   void CompleteRedeclChain(const Decl *D) override;
00073 
00074   /// \brief Resolve a selector ID into a selector.
00075   Selector GetExternalSelector(uint32_t ID) override;
00076 
00077   /// \brief Returns the number of selectors known to the external AST
00078   /// source.
00079   uint32_t GetNumExternalSelectors() override;
00080 
00081   /// \brief Resolve the offset of a statement in the decl stream into
00082   /// a statement.
00083   Stmt *GetExternalDeclStmt(uint64_t Offset) override;
00084 
00085   /// \brief Resolve the offset of a set of C++ base specifiers in the decl
00086   /// stream into an array of specifiers.
00087   CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override;
00088 
00089   /// \brief Find all declarations with the given name in the
00090   /// given context.
00091   bool
00092   FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) override;
00093 
00094   /// \brief Ensures that the table of all visible declarations inside this
00095   /// context is up to date.
00096   void completeVisibleDeclsMap(const DeclContext *DC) override;
00097 
00098   /// \brief Finds all declarations lexically contained within the given
00099   /// DeclContext, after applying an optional filter predicate.
00100   ///
00101   /// \param isKindWeWant a predicate function that returns true if the passed
00102   /// declaration kind is one we are looking for. If NULL, all declarations
00103   /// are returned.
00104   ///
00105   /// \return an indication of whether the load succeeded or failed.
00106   ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
00107                                 bool (*isKindWeWant)(Decl::Kind),
00108                                 SmallVectorImpl<Decl*> &Result) override;
00109 
00110   /// \brief Finds all declarations lexically contained within the given
00111   /// DeclContext.
00112   ///
00113   /// \return true if an error occurred
00114   ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
00115                                 SmallVectorImpl<Decl*> &Result) {
00116     return FindExternalLexicalDecls(DC, nullptr, Result);
00117   }
00118 
00119   template <typename DeclTy>
00120   ExternalLoadResult FindExternalLexicalDeclsBy(const DeclContext *DC,
00121                                   SmallVectorImpl<Decl*> &Result) {
00122     return FindExternalLexicalDecls(DC, DeclTy::classofKind, Result);
00123   }
00124 
00125   /// \brief Get the decls that are contained in a file in the Offset/Length
00126   /// range. \p Length can be 0 to indicate a point at \p Offset instead of
00127   /// a range. 
00128   void FindFileRegionDecls(FileID File, unsigned Offset,unsigned Length,
00129                            SmallVectorImpl<Decl *> &Decls) override;
00130 
00131   /// \brief Gives the external AST source an opportunity to complete
00132   /// an incomplete type.
00133   void CompleteType(TagDecl *Tag) override;
00134 
00135   /// \brief Gives the external AST source an opportunity to complete an
00136   /// incomplete Objective-C class.
00137   ///
00138   /// This routine will only be invoked if the "externally completed" bit is
00139   /// set on the ObjCInterfaceDecl via the function 
00140   /// \c ObjCInterfaceDecl::setExternallyCompleted().
00141   void CompleteType(ObjCInterfaceDecl *Class) override;
00142 
00143   /// \brief Loads comment ranges.
00144   void ReadComments() override;
00145 
00146   /// \brief Notify ExternalASTSource that we started deserialization of
00147   /// a decl or type so until FinishedDeserializing is called there may be
00148   /// decls that are initializing. Must be paired with FinishedDeserializing.
00149   void StartedDeserializing() override;
00150 
00151   /// \brief Notify ExternalASTSource that we finished the deserialization of
00152   /// a decl or type. Must be paired with StartedDeserializing.
00153   void FinishedDeserializing() override;
00154 
00155   /// \brief Function that will be invoked when we begin parsing a new
00156   /// translation unit involving this external AST source.
00157   void StartTranslationUnit(ASTConsumer *Consumer) override;
00158 
00159   /// \brief Print any statistics that have been gathered regarding
00160   /// the external AST source.
00161   void PrintStats() override;
00162   
00163   
00164   /// \brief Perform layout on the given record.
00165   ///
00166   /// This routine allows the external AST source to provide an specific 
00167   /// layout for a record, overriding the layout that would normally be
00168   /// constructed. It is intended for clients who receive specific layout
00169   /// details rather than source code (such as LLDB). The client is expected
00170   /// to fill in the field offsets, base offsets, virtual base offsets, and
00171   /// complete object size.
00172   ///
00173   /// \param Record The record whose layout is being requested.
00174   ///
00175   /// \param Size The final size of the record, in bits.
00176   ///
00177   /// \param Alignment The final alignment of the record, in bits.
00178   ///
00179   /// \param FieldOffsets The offset of each of the fields within the record,
00180   /// expressed in bits. All of the fields must be provided with offsets.
00181   ///
00182   /// \param BaseOffsets The offset of each of the direct, non-virtual base
00183   /// classes. If any bases are not given offsets, the bases will be laid 
00184   /// out according to the ABI.
00185   ///
00186   /// \param VirtualBaseOffsets The offset of each of the virtual base classes
00187   /// (either direct or not). If any bases are not given offsets, the bases will 
00188   /// be laid out according to the ABI.
00189   /// 
00190   /// \returns true if the record layout was provided, false otherwise.
00191   bool
00192   layoutRecordType(const RecordDecl *Record,
00193                    uint64_t &Size, uint64_t &Alignment,
00194                    llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
00195                  llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
00196                  llvm::DenseMap<const CXXRecordDecl *,
00197                                 CharUnits> &VirtualBaseOffsets) override;
00198 
00199   /// Return the amount of memory used by memory buffers, breaking down
00200   /// by heap-backed versus mmap'ed memory.
00201   void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override;
00202 
00203   //===--------------------------------------------------------------------===//
00204   // ExternalSemaSource.
00205   //===--------------------------------------------------------------------===//
00206 
00207   /// \brief Initialize the semantic source with the Sema instance
00208   /// being used to perform semantic analysis on the abstract syntax
00209   /// tree.
00210   void InitializeSema(Sema &S) override;
00211 
00212   /// \brief Inform the semantic consumer that Sema is no longer available.
00213   void ForgetSema() override;
00214 
00215   /// \brief Load the contents of the global method pool for a given
00216   /// selector.
00217   void ReadMethodPool(Selector Sel) override;
00218 
00219   /// \brief Load the set of namespaces that are known to the external source,
00220   /// which will be used during typo correction.
00221   void
00222   ReadKnownNamespaces(SmallVectorImpl<NamespaceDecl*> &Namespaces) override;
00223 
00224   /// \brief Load the set of used but not defined functions or variables with
00225   /// internal linkage, or used but not defined inline functions.
00226   void ReadUndefinedButUsed(
00227                 llvm::DenseMap<NamedDecl*, SourceLocation> &Undefined) override;
00228 
00229   /// \brief Do last resort, unqualified lookup on a LookupResult that
00230   /// Sema cannot find.
00231   ///
00232   /// \param R a LookupResult that is being recovered.
00233   ///
00234   /// \param S the Scope of the identifier occurrence.
00235   ///
00236   /// \return true to tell Sema to recover using the LookupResult.
00237   bool LookupUnqualified(LookupResult &R, Scope *S) override;
00238 
00239   /// \brief Read the set of tentative definitions known to the external Sema
00240   /// source.
00241   ///
00242   /// The external source should append its own tentative definitions to the
00243   /// given vector of tentative definitions. Note that this routine may be
00244   /// invoked multiple times; the external source should take care not to
00245   /// introduce the same declarations repeatedly.
00246   void ReadTentativeDefinitions(SmallVectorImpl<VarDecl*> &Defs) override;
00247 
00248   /// \brief Read the set of unused file-scope declarations known to the
00249   /// external Sema source.
00250   ///
00251   /// The external source should append its own unused, filed-scope to the
00252   /// given vector of declarations. Note that this routine may be
00253   /// invoked multiple times; the external source should take care not to
00254   /// introduce the same declarations repeatedly.
00255   void ReadUnusedFileScopedDecls(
00256                         SmallVectorImpl<const DeclaratorDecl*> &Decls) override;
00257 
00258   /// \brief Read the set of delegating constructors known to the
00259   /// external Sema source.
00260   ///
00261   /// The external source should append its own delegating constructors to the
00262   /// given vector of declarations. Note that this routine may be
00263   /// invoked multiple times; the external source should take care not to
00264   /// introduce the same declarations repeatedly.
00265   void ReadDelegatingConstructors(
00266                           SmallVectorImpl<CXXConstructorDecl*> &Decls) override;
00267 
00268   /// \brief Read the set of ext_vector type declarations known to the
00269   /// external Sema source.
00270   ///
00271   /// The external source should append its own ext_vector type declarations to
00272   /// the given vector of declarations. Note that this routine may be
00273   /// invoked multiple times; the external source should take care not to
00274   /// introduce the same declarations repeatedly.
00275   void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl*> &Decls) override;
00276 
00277   /// \brief Read the set of dynamic classes known to the external Sema source.
00278   ///
00279   /// The external source should append its own dynamic classes to
00280   /// the given vector of declarations. Note that this routine may be
00281   /// invoked multiple times; the external source should take care not to
00282   /// introduce the same declarations repeatedly.
00283   void ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl*> &Decls) override;
00284 
00285   /// \brief Read the set of potentially unused typedefs known to the source.
00286   ///
00287   /// The external source should append its own potentially unused local
00288   /// typedefs to the given vector of declarations. Note that this routine may
00289   /// be invoked multiple times; the external source should take care not to
00290   /// introduce the same declarations repeatedly.
00291   void ReadUnusedLocalTypedefNameCandidates(
00292       llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) override;
00293 
00294   /// \brief Read the set of locally-scoped extern "C" declarations known to the
00295   /// external Sema source.
00296   ///
00297   /// The external source should append its own locally-scoped external
00298   /// declarations to the given vector of declarations. Note that this routine
00299   /// may be invoked multiple times; the external source should take care not
00300   /// to introduce the same declarations repeatedly.
00301   void ReadLocallyScopedExternCDecls(
00302                                    SmallVectorImpl<NamedDecl*> &Decls) override;
00303 
00304   /// \brief Read the set of referenced selectors known to the
00305   /// external Sema source.
00306   ///
00307   /// The external source should append its own referenced selectors to the 
00308   /// given vector of selectors. Note that this routine 
00309   /// may be invoked multiple times; the external source should take care not 
00310   /// to introduce the same selectors repeatedly.
00311   void ReadReferencedSelectors(SmallVectorImpl<std::pair<Selector,
00312                                               SourceLocation> > &Sels) override;
00313 
00314   /// \brief Read the set of weak, undeclared identifiers known to the
00315   /// external Sema source.
00316   ///
00317   /// The external source should append its own weak, undeclared identifiers to
00318   /// the given vector. Note that this routine may be invoked multiple times; 
00319   /// the external source should take care not to introduce the same identifiers
00320   /// repeatedly.
00321   void ReadWeakUndeclaredIdentifiers(
00322            SmallVectorImpl<std::pair<IdentifierInfo*, WeakInfo> > &WI) override;
00323 
00324   /// \brief Read the set of used vtables known to the external Sema source.
00325   ///
00326   /// The external source should append its own used vtables to the given
00327   /// vector. Note that this routine may be invoked multiple times; the external
00328   /// source should take care not to introduce the same vtables repeatedly.
00329   void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) override;
00330 
00331   /// \brief Read the set of pending instantiations known to the external
00332   /// Sema source.
00333   ///
00334   /// The external source should append its own pending instantiations to the
00335   /// given vector. Note that this routine may be invoked multiple times; the
00336   /// external source should take care not to introduce the same instantiations
00337   /// repeatedly.
00338   void ReadPendingInstantiations(
00339      SmallVectorImpl<std::pair<ValueDecl*, SourceLocation> >& Pending) override;
00340 
00341   /// \brief Read the set of late parsed template functions for this source.
00342   ///
00343   /// The external source should insert its own late parsed template functions
00344   /// into the map. Note that this routine may be invoked multiple times; the
00345   /// external source should take care not to introduce the same map entries
00346   /// repeatedly.
00347   void ReadLateParsedTemplates(
00348                          llvm::DenseMap<const FunctionDecl *,
00349                                         LateParsedTemplate *> &LPTMap) override;
00350 
00351   /// \copydoc ExternalSemaSource::CorrectTypo
00352   /// \note Returns the first nonempty correction.
00353   TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo,
00354                              int LookupKind, Scope *S, CXXScopeSpec *SS,
00355                              CorrectionCandidateCallback &CCC,
00356                              DeclContext *MemberContext,
00357                              bool EnteringContext,
00358                              const ObjCObjectPointerType *OPT) override;
00359 
00360   /// \brief Produces a diagnostic note if one of the attached sources
00361   /// contains a complete definition for \p T. Queries the sources in list
00362   /// order until the first one claims that a diagnostic was produced.
00363   ///
00364   /// \param Loc the location at which a complete type was required but not
00365   /// provided
00366   ///
00367   /// \param T the \c QualType that should have been complete at \p Loc
00368   ///
00369   /// \return true if a diagnostic was produced, false otherwise.
00370   bool MaybeDiagnoseMissingCompleteType(SourceLocation Loc,
00371                                         QualType T) override;
00372 
00373   // isa/cast/dyn_cast support
00374   static bool classof(const MultiplexExternalSemaSource*) { return true; }
00375   //static bool classof(const ExternalSemaSource*) { return true; }
00376 }; 
00377 
00378 } // end namespace clang
00379 
00380 #endif