Coverage Report

Created: 2019-07-24 05:18

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