ExternalSemaSource.h revision 31e37b2d7b4815fdea6a35d49f33005562f0d494
1//===--- ExternalSemaSource.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 the ExternalSemaSource interface.
11//
12//===----------------------------------------------------------------------===//
13#ifndef LLVM_CLANG_SEMA_EXTERNAL_SEMA_SOURCE_H
14#define LLVM_CLANG_SEMA_EXTERNAL_SEMA_SOURCE_H
15
16#include "clang/AST/ExternalASTSource.h"
17#include "clang/Sema/Weak.h"
18#include <utility>
19
20namespace clang {
21
22class CXXConstructorDecl;
23class CXXRecordDecl;
24class DeclaratorDecl;
25class LookupResult;
26struct ObjCMethodList;
27class Scope;
28class Sema;
29class TypedefNameDecl;
30class VarDecl;
31
32/// \brief An abstract interface that should be implemented by
33/// external AST sources that also provide information for semantic
34/// analysis.
35class ExternalSemaSource : public ExternalASTSource {
36public:
37  ExternalSemaSource() {
38    ExternalASTSource::SemaSource = true;
39  }
40
41  ~ExternalSemaSource();
42
43  /// \brief Initialize the semantic source with the Sema instance
44  /// being used to perform semantic analysis on the abstract syntax
45  /// tree.
46  virtual void InitializeSema(Sema &S) {}
47
48  /// \brief Inform the semantic consumer that Sema is no longer available.
49  virtual void ForgetSema() {}
50
51  /// \brief Load the contents of the global method pool for a given
52  /// selector.
53  ///
54  /// \returns a pair of Objective-C methods lists containing the
55  /// instance and factory methods, respectively, with this selector.
56  virtual std::pair<ObjCMethodList,ObjCMethodList> ReadMethodPool(Selector Sel);
57
58  /// \brief Load the set of namespaces that are known to the external source,
59  /// which will be used during typo correction.
60  virtual void ReadKnownNamespaces(
61                           SmallVectorImpl<NamespaceDecl *> &Namespaces);
62
63  /// \brief Do last resort, unqualified lookup on a LookupResult that
64  /// Sema cannot find.
65  ///
66  /// \param R a LookupResult that is being recovered.
67  ///
68  /// \param S the Scope of the identifier occurrence.
69  ///
70  /// \return true to tell Sema to recover using the LookupResult.
71  virtual bool LookupUnqualified(LookupResult &R, Scope *S) { return false; }
72
73  /// \brief Read the set of tentative definitions known to the external Sema
74  /// source.
75  ///
76  /// The external source should append its own tentative definitions to the
77  /// given vector of tentative definitions. Note that this routine may be
78  /// invoked multiple times; the external source should take care not to
79  /// introduce the same declarations repeatedly.
80  virtual void ReadTentativeDefinitions(
81                                  SmallVectorImpl<VarDecl *> &TentativeDefs) {}
82
83  /// \brief Read the set of unused file-scope declarations known to the
84  /// external Sema source.
85  ///
86  /// The external source should append its own unused, filed-scope to the
87  /// given vector of declarations. Note that this routine may be
88  /// invoked multiple times; the external source should take care not to
89  /// introduce the same declarations repeatedly.
90  virtual void ReadUnusedFileScopedDecls(
91                 SmallVectorImpl<const DeclaratorDecl *> &Decls) {}
92
93  /// \brief Read the set of delegating constructors known to the
94  /// external Sema source.
95  ///
96  /// The external source should append its own delegating constructors to the
97  /// given vector of declarations. Note that this routine may be
98  /// invoked multiple times; the external source should take care not to
99  /// introduce the same declarations repeatedly.
100  virtual void ReadDelegatingConstructors(
101                 SmallVectorImpl<CXXConstructorDecl *> &Decls) {}
102
103  /// \brief Read the set of ext_vector type declarations known to the
104  /// external Sema source.
105  ///
106  /// The external source should append its own ext_vector type declarations to
107  /// the given vector of declarations. Note that this routine may be
108  /// invoked multiple times; the external source should take care not to
109  /// introduce the same declarations repeatedly.
110  virtual void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) {}
111
112  /// \brief Read the set of dynamic classes known to the external Sema source.
113  ///
114  /// The external source should append its own dynamic classes to
115  /// the given vector of declarations. Note that this routine may be
116  /// invoked multiple times; the external source should take care not to
117  /// introduce the same declarations repeatedly.
118  virtual void ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls) {}
119
120  /// \brief Read the set of locally-scoped external declarations known to the
121  /// external Sema source.
122  ///
123  /// The external source should append its own locally-scoped external
124  /// declarations to the given vector of declarations. Note that this routine
125  /// may be invoked multiple times; the external source should take care not
126  /// to introduce the same declarations repeatedly.
127  virtual void ReadLocallyScopedExternalDecls(
128                 SmallVectorImpl<NamedDecl *> &Decls) {}
129
130  /// \brief Read the set of referenced selectors known to the
131  /// external Sema source.
132  ///
133  /// The external source should append its own referenced selectors to the
134  /// given vector of selectors. Note that this routine
135  /// may be invoked multiple times; the external source should take care not
136  /// to introduce the same selectors repeatedly.
137  virtual void ReadReferencedSelectors(
138                 SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) {}
139
140  /// \brief Read the set of weak, undeclared identifiers known to the
141  /// external Sema source.
142  ///
143  /// The external source should append its own weak, undeclared identifiers to
144  /// the given vector. Note that this routine may be invoked multiple times;
145  /// the external source should take care not to introduce the same identifiers
146  /// repeatedly.
147  virtual void ReadWeakUndeclaredIdentifiers(
148                 SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI) {}
149
150  // isa/cast/dyn_cast support
151  static bool classof(const ExternalASTSource *Source) {
152    return Source->SemaSource;
153  }
154  static bool classof(const ExternalSemaSource *) { return true; }
155};
156
157} // end namespace clang
158
159#endif
160