]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Sema/MultiplexExternalSemaSource.h
Update clang to trunk r290819 and resolve conflicts.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Sema / MultiplexExternalSemaSource.h
1 //===--- MultiplexExternalSemaSource.h - External Sema 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 ExternalSemaSource interface, dispatching to all clients
11 //
12 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_SEMA_MULTIPLEXEXTERNALSEMASOURCE_H
14 #define LLVM_CLANG_SEMA_MULTIPLEXEXTERNALSEMASOURCE_H
15
16 #include "clang/Sema/ExternalSemaSource.h"
17 #include "clang/Sema/Weak.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include <utility>
20
21 namespace clang {
22
23   class CXXConstructorDecl;
24   class CXXRecordDecl;
25   class DeclaratorDecl;
26   struct ExternalVTableUse;
27   class LookupResult;
28   class NamespaceDecl;
29   class Scope;
30   class Sema;
31   class TypedefNameDecl;
32   class ValueDecl;
33   class VarDecl;
34
35
36 /// \brief An abstract interface that should be implemented by
37 /// external AST sources that also provide information for semantic
38 /// analysis.
39 class MultiplexExternalSemaSource : public ExternalSemaSource {
40
41 private:
42   SmallVector<ExternalSemaSource *, 2> Sources; // doesn't own them.
43
44 public:
45   
46   ///\brief Constructs a new multiplexing external sema source and appends the
47   /// given element to it.
48   ///
49   ///\param[in] s1 - A non-null (old) ExternalSemaSource.
50   ///\param[in] s2 - A non-null (new) ExternalSemaSource.
51   ///
52   MultiplexExternalSemaSource(ExternalSemaSource& s1, ExternalSemaSource& s2);
53
54   ~MultiplexExternalSemaSource() override;
55
56   ///\brief Appends new source to the source list.
57   ///
58   ///\param[in] source - An ExternalSemaSource.
59   ///
60   void addSource(ExternalSemaSource &source);
61
62   //===--------------------------------------------------------------------===//
63   // ExternalASTSource.
64   //===--------------------------------------------------------------------===//
65
66   /// \brief Resolve a declaration ID into a declaration, potentially
67   /// building a new declaration.
68   Decl *GetExternalDecl(uint32_t ID) override;
69
70   /// \brief Complete the redeclaration chain if it's been extended since the
71   /// previous generation of the AST source.
72   void CompleteRedeclChain(const Decl *D) override;
73
74   /// \brief Resolve a selector ID into a selector.
75   Selector GetExternalSelector(uint32_t ID) override;
76
77   /// \brief Returns the number of selectors known to the external AST
78   /// source.
79   uint32_t GetNumExternalSelectors() override;
80
81   /// \brief Resolve the offset of a statement in the decl stream into
82   /// a statement.
83   Stmt *GetExternalDeclStmt(uint64_t Offset) override;
84
85   /// \brief Resolve the offset of a set of C++ base specifiers in the decl
86   /// stream into an array of specifiers.
87   CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override;
88
89   /// \brief Resolve a handle to a list of ctor initializers into the list of
90   /// initializers themselves.
91   CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset) override;
92
93   /// \brief Find all declarations with the given name in the
94   /// given context.
95   bool FindExternalVisibleDeclsByName(const DeclContext *DC,
96                                       DeclarationName Name) override;
97
98   /// \brief Ensures that the table of all visible declarations inside this
99   /// context is up to date.
100   void completeVisibleDeclsMap(const DeclContext *DC) override;
101
102   /// \brief Finds all declarations lexically contained within the given
103   /// DeclContext, after applying an optional filter predicate.
104   ///
105   /// \param IsKindWeWant a predicate function that returns true if the passed
106   /// declaration kind is one we are looking for.
107   void
108   FindExternalLexicalDecls(const DeclContext *DC,
109                            llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
110                            SmallVectorImpl<Decl *> &Result) override;
111
112   /// \brief Get the decls that are contained in a file in the Offset/Length
113   /// range. \p Length can be 0 to indicate a point at \p Offset instead of
114   /// a range. 
115   void FindFileRegionDecls(FileID File, unsigned Offset,unsigned Length,
116                            SmallVectorImpl<Decl *> &Decls) override;
117
118   /// \brief Gives the external AST source an opportunity to complete
119   /// an incomplete type.
120   void CompleteType(TagDecl *Tag) override;
121
122   /// \brief Gives the external AST source an opportunity to complete an
123   /// incomplete Objective-C class.
124   ///
125   /// This routine will only be invoked if the "externally completed" bit is
126   /// set on the ObjCInterfaceDecl via the function 
127   /// \c ObjCInterfaceDecl::setExternallyCompleted().
128   void CompleteType(ObjCInterfaceDecl *Class) override;
129
130   /// \brief Loads comment ranges.
131   void ReadComments() override;
132
133   /// \brief Notify ExternalASTSource that we started deserialization of
134   /// a decl or type so until FinishedDeserializing is called there may be
135   /// decls that are initializing. Must be paired with FinishedDeserializing.
136   void StartedDeserializing() override;
137
138   /// \brief Notify ExternalASTSource that we finished the deserialization of
139   /// a decl or type. Must be paired with StartedDeserializing.
140   void FinishedDeserializing() override;
141
142   /// \brief Function that will be invoked when we begin parsing a new
143   /// translation unit involving this external AST source.
144   void StartTranslationUnit(ASTConsumer *Consumer) override;
145
146   /// \brief Print any statistics that have been gathered regarding
147   /// the external AST source.
148   void PrintStats() override;
149   
150   
151   /// \brief Perform layout on the given record.
152   ///
153   /// This routine allows the external AST source to provide an specific 
154   /// layout for a record, overriding the layout that would normally be
155   /// constructed. It is intended for clients who receive specific layout
156   /// details rather than source code (such as LLDB). The client is expected
157   /// to fill in the field offsets, base offsets, virtual base offsets, and
158   /// complete object size.
159   ///
160   /// \param Record The record whose layout is being requested.
161   ///
162   /// \param Size The final size of the record, in bits.
163   ///
164   /// \param Alignment The final alignment of the record, in bits.
165   ///
166   /// \param FieldOffsets The offset of each of the fields within the record,
167   /// expressed in bits. All of the fields must be provided with offsets.
168   ///
169   /// \param BaseOffsets The offset of each of the direct, non-virtual base
170   /// classes. If any bases are not given offsets, the bases will be laid 
171   /// out according to the ABI.
172   ///
173   /// \param VirtualBaseOffsets The offset of each of the virtual base classes
174   /// (either direct or not). If any bases are not given offsets, the bases will 
175   /// be laid out according to the ABI.
176   /// 
177   /// \returns true if the record layout was provided, false otherwise.
178   bool
179   layoutRecordType(const RecordDecl *Record,
180                    uint64_t &Size, uint64_t &Alignment,
181                    llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
182                  llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
183                  llvm::DenseMap<const CXXRecordDecl *,
184                                 CharUnits> &VirtualBaseOffsets) override;
185
186   /// Return the amount of memory used by memory buffers, breaking down
187   /// by heap-backed versus mmap'ed memory.
188   void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override;
189
190   //===--------------------------------------------------------------------===//
191   // ExternalSemaSource.
192   //===--------------------------------------------------------------------===//
193
194   /// \brief Initialize the semantic source with the Sema instance
195   /// being used to perform semantic analysis on the abstract syntax
196   /// tree.
197   void InitializeSema(Sema &S) override;
198
199   /// \brief Inform the semantic consumer that Sema is no longer available.
200   void ForgetSema() override;
201
202   /// \brief Load the contents of the global method pool for a given
203   /// selector.
204   void ReadMethodPool(Selector Sel) override;
205
206   /// Load the contents of the global method pool for a given
207   /// selector if necessary.
208   void updateOutOfDateSelector(Selector Sel) override;
209
210   /// \brief Load the set of namespaces that are known to the external source,
211   /// which will be used during typo correction.
212   void
213   ReadKnownNamespaces(SmallVectorImpl<NamespaceDecl*> &Namespaces) override;
214
215   /// \brief Load the set of used but not defined functions or variables with
216   /// internal linkage, or used but not defined inline functions.
217   void ReadUndefinedButUsed(
218       llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) override;
219
220   void ReadMismatchingDeleteExpressions(llvm::MapVector<
221       FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &
222                                             Exprs) override;
223
224   /// \brief Do last resort, unqualified lookup on a LookupResult that
225   /// Sema cannot find.
226   ///
227   /// \param R a LookupResult that is being recovered.
228   ///
229   /// \param S the Scope of the identifier occurrence.
230   ///
231   /// \return true to tell Sema to recover using the LookupResult.
232   bool LookupUnqualified(LookupResult &R, Scope *S) override;
233
234   /// \brief Read the set of tentative definitions known to the external Sema
235   /// source.
236   ///
237   /// The external source should append its own tentative definitions to the
238   /// given vector of tentative definitions. Note that this routine may be
239   /// invoked multiple times; the external source should take care not to
240   /// introduce the same declarations repeatedly.
241   void ReadTentativeDefinitions(SmallVectorImpl<VarDecl*> &Defs) override;
242
243   /// \brief Read the set of unused file-scope declarations known to the
244   /// external Sema source.
245   ///
246   /// The external source should append its own unused, filed-scope to the
247   /// given vector of declarations. Note that this routine may be
248   /// invoked multiple times; the external source should take care not to
249   /// introduce the same declarations repeatedly.
250   void ReadUnusedFileScopedDecls(
251                         SmallVectorImpl<const DeclaratorDecl*> &Decls) override;
252
253   /// \brief Read the set of delegating constructors known to the
254   /// external Sema source.
255   ///
256   /// The external source should append its own delegating constructors to the
257   /// given vector of declarations. Note that this routine may be
258   /// invoked multiple times; the external source should take care not to
259   /// introduce the same declarations repeatedly.
260   void ReadDelegatingConstructors(
261                           SmallVectorImpl<CXXConstructorDecl*> &Decls) override;
262
263   /// \brief Read the set of ext_vector type declarations known to the
264   /// external Sema source.
265   ///
266   /// The external source should append its own ext_vector type declarations to
267   /// the given vector of declarations. Note that this routine may be
268   /// invoked multiple times; the external source should take care not to
269   /// introduce the same declarations repeatedly.
270   void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl*> &Decls) override;
271
272   /// \brief Read the set of potentially unused typedefs known to the source.
273   ///
274   /// The external source should append its own potentially unused local
275   /// typedefs to the given vector of declarations. Note that this routine may
276   /// be invoked multiple times; the external source should take care not to
277   /// introduce the same declarations repeatedly.
278   void ReadUnusedLocalTypedefNameCandidates(
279       llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) override;
280
281   /// \brief Read the set of referenced selectors known to the
282   /// external Sema source.
283   ///
284   /// The external source should append its own referenced selectors to the 
285   /// given vector of selectors. Note that this routine 
286   /// may be invoked multiple times; the external source should take care not 
287   /// to introduce the same selectors repeatedly.
288   void ReadReferencedSelectors(SmallVectorImpl<std::pair<Selector,
289                                               SourceLocation> > &Sels) override;
290
291   /// \brief Read the set of weak, undeclared identifiers known to the
292   /// external Sema source.
293   ///
294   /// The external source should append its own weak, undeclared identifiers to
295   /// the given vector. Note that this routine may be invoked multiple times; 
296   /// the external source should take care not to introduce the same identifiers
297   /// repeatedly.
298   void ReadWeakUndeclaredIdentifiers(
299            SmallVectorImpl<std::pair<IdentifierInfo*, WeakInfo> > &WI) override;
300
301   /// \brief Read the set of used vtables known to the external Sema source.
302   ///
303   /// The external source should append its own used vtables to the given
304   /// vector. Note that this routine may be invoked multiple times; the external
305   /// source should take care not to introduce the same vtables repeatedly.
306   void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) override;
307
308   /// \brief Read the set of pending instantiations known to the external
309   /// Sema source.
310   ///
311   /// The external source should append its own pending instantiations to the
312   /// given vector. Note that this routine may be invoked multiple times; the
313   /// external source should take care not to introduce the same instantiations
314   /// repeatedly.
315   void ReadPendingInstantiations(
316      SmallVectorImpl<std::pair<ValueDecl*, SourceLocation> >& Pending) override;
317
318   /// \brief Read the set of late parsed template functions for this source.
319   ///
320   /// The external source should insert its own late parsed template functions
321   /// into the map. Note that this routine may be invoked multiple times; the
322   /// external source should take care not to introduce the same map entries
323   /// repeatedly.
324   void ReadLateParsedTemplates(
325       llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
326           &LPTMap) override;
327
328   /// \copydoc ExternalSemaSource::CorrectTypo
329   /// \note Returns the first nonempty correction.
330   TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo,
331                              int LookupKind, Scope *S, CXXScopeSpec *SS,
332                              CorrectionCandidateCallback &CCC,
333                              DeclContext *MemberContext,
334                              bool EnteringContext,
335                              const ObjCObjectPointerType *OPT) override;
336
337   /// \brief Produces a diagnostic note if one of the attached sources
338   /// contains a complete definition for \p T. Queries the sources in list
339   /// order until the first one claims that a diagnostic was produced.
340   ///
341   /// \param Loc the location at which a complete type was required but not
342   /// provided
343   ///
344   /// \param T the \c QualType that should have been complete at \p Loc
345   ///
346   /// \return true if a diagnostic was produced, false otherwise.
347   bool MaybeDiagnoseMissingCompleteType(SourceLocation Loc,
348                                         QualType T) override;
349
350   // isa/cast/dyn_cast support
351   static bool classof(const MultiplexExternalSemaSource*) { return true; }
352   //static bool classof(const ExternalSemaSource*) { return true; }
353 }; 
354
355 } // end namespace clang
356
357 #endif