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