]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/AST/ASTImporter.h
Merge ^vendor/binutils/dist@214082 into contrib/binutils.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / AST / ASTImporter.h
1 //===--- ASTImporter.h - Importing ASTs from other Contexts -----*- 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 ASTImporter class which imports AST nodes from one
11 //  context into another context.
12 //
13 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_ASTIMPORTER_H
15 #define LLVM_CLANG_AST_ASTIMPORTER_H
16
17 #include "clang/AST/DeclarationName.h"
18 #include "clang/AST/Type.h"
19 #include "clang/Basic/SourceLocation.h"
20 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/ADT/DenseSet.h"
22 #include "llvm/ADT/SmallVector.h"
23
24 namespace clang {
25   class ASTContext;
26   class Decl;
27   class DeclContext;
28   class Diagnostic;
29   class Expr;
30   class FileManager;
31   class IdentifierInfo;
32   class NestedNameSpecifier;
33   class Stmt;
34   class TypeSourceInfo;
35   
36   /// \brief Imports selected nodes from one AST context into another context,
37   /// merging AST nodes where appropriate.
38   class ASTImporter {
39   public:
40     typedef llvm::DenseSet<std::pair<Decl *, Decl *> > NonEquivalentDeclSet;
41     
42   private:
43     /// \brief The contexts we're importing to and from.
44     ASTContext &ToContext, &FromContext;
45     
46     /// \brief The file managers we're importing to and from.
47     FileManager &ToFileManager, &FromFileManager;
48     
49     /// \brief The diagnostics object that we should use to emit diagnostics.
50     Diagnostic &Diags;
51     
52     /// \brief Mapping from the already-imported types in the "from" context
53     /// to the corresponding types in the "to" context.
54     llvm::DenseMap<Type *, Type *> ImportedTypes;
55     
56     /// \brief Mapping from the already-imported declarations in the "from"
57     /// context to the corresponding declarations in the "to" context.
58     llvm::DenseMap<Decl *, Decl *> ImportedDecls;
59
60     /// \brief Mapping from the already-imported statements in the "from"
61     /// context to the corresponding statements in the "to" context.
62     llvm::DenseMap<Stmt *, Stmt *> ImportedStmts;
63
64     /// \brief Mapping from the already-imported FileIDs in the "from" source
65     /// manager to the corresponding FileIDs in the "to" source manager.
66     llvm::DenseMap<unsigned, FileID> ImportedFileIDs;
67     
68     /// \brief Imported, anonymous tag declarations that are missing their 
69     /// corresponding typedefs.
70     llvm::SmallVector<TagDecl *, 4> AnonTagsWithPendingTypedefs;
71     
72     /// \brief Declaration (from, to) pairs that are known not to be equivalent
73     /// (which we have already complained about).
74     NonEquivalentDeclSet NonEquivalentDecls;
75     
76   public:
77     ASTImporter(Diagnostic &Diags,
78                 ASTContext &ToContext, FileManager &ToFileManager,
79                 ASTContext &FromContext, FileManager &FromFileManager);
80     
81     virtual ~ASTImporter();
82     
83     /// \brief Import the given type from the "from" context into the "to"
84     /// context.
85     ///
86     /// \returns the equivalent type in the "to" context, or a NULL type if
87     /// an error occurred.
88     QualType Import(QualType FromT);
89
90     /// \brief Import the given type source information from the
91     /// "from" context into the "to" context.
92     ///
93     /// \returns the equivalent type source information in the "to"
94     /// context, or NULL if an error occurred.
95     TypeSourceInfo *Import(TypeSourceInfo *FromTSI);
96
97     /// \brief Import the given declaration from the "from" context into the 
98     /// "to" context.
99     ///
100     /// \returns the equivalent declaration in the "to" context, or a NULL type 
101     /// if an error occurred.
102     Decl *Import(Decl *FromD);
103
104     /// \brief Import the given declaration context from the "from"
105     /// AST context into the "to" AST context.
106     ///
107     /// \returns the equivalent declaration context in the "to"
108     /// context, or a NULL type if an error occurred.
109     DeclContext *ImportContext(DeclContext *FromDC);
110     
111     /// \brief Import the given expression from the "from" context into the
112     /// "to" context.
113     ///
114     /// \returns the equivalent expression in the "to" context, or NULL if
115     /// an error occurred.
116     Expr *Import(Expr *FromE);
117
118     /// \brief Import the given statement from the "from" context into the
119     /// "to" context.
120     ///
121     /// \returns the equivalent statement in the "to" context, or NULL if
122     /// an error occurred.
123     Stmt *Import(Stmt *FromS);
124
125     /// \brief Import the given nested-name-specifier from the "from"
126     /// context into the "to" context.
127     ///
128     /// \returns the equivalent nested-name-specifier in the "to"
129     /// context, or NULL if an error occurred.
130     NestedNameSpecifier *Import(NestedNameSpecifier *FromNNS);
131     
132     /// \brief Import the given source location from the "from" context into
133     /// the "to" context.
134     ///
135     /// \returns the equivalent source location in the "to" context, or an
136     /// invalid source location if an error occurred.
137     SourceLocation Import(SourceLocation FromLoc);
138
139     /// \brief Import the given source range from the "from" context into
140     /// the "to" context.
141     ///
142     /// \returns the equivalent source range in the "to" context, or an
143     /// invalid source location if an error occurred.
144     SourceRange Import(SourceRange FromRange);
145
146     /// \brief Import the given declaration name from the "from"
147     /// context into the "to" context.
148     ///
149     /// \returns the equivalent declaration name in the "to" context,
150     /// or an empty declaration name if an error occurred.
151     DeclarationName Import(DeclarationName FromName);
152
153     /// \brief Import the given identifier from the "from" context
154     /// into the "to" context.
155     ///
156     /// \returns the equivalent identifier in the "to" context.
157     IdentifierInfo *Import(IdentifierInfo *FromId);
158
159     /// \brief Import the given Objective-C selector from the "from"
160     /// context into the "to" context.
161     ///
162     /// \returns the equivalent selector in the "to" context.
163     Selector Import(Selector FromSel);
164
165     /// \brief Import the given file ID from the "from" context into the 
166     /// "to" context.
167     ///
168     /// \returns the equivalent file ID in the source manager of the "to"
169     /// context.
170     FileID Import(FileID);
171     
172     /// \brief Cope with a name conflict when importing a declaration into the
173     /// given context.
174     ///
175     /// This routine is invoked whenever there is a name conflict while 
176     /// importing a declaration. The returned name will become the name of the
177     /// imported declaration. By default, the returned name is the same as the
178     /// original name, leaving the conflict unresolve such that name lookup
179     /// for this name is likely to find an ambiguity later.
180     ///
181     /// Subclasses may override this routine to resolve the conflict, e.g., by
182     /// renaming the declaration being imported.
183     ///
184     /// \param Name the name of the declaration being imported, which conflicts
185     /// with other declarations.
186     ///
187     /// \param DC the declaration context (in the "to" AST context) in which 
188     /// the name is being imported.
189     ///
190     /// \param IDNS the identifier namespace in which the name will be found.
191     ///
192     /// \param Decls the set of declarations with the same name as the
193     /// declaration being imported.
194     ///
195     /// \param NumDecls the number of conflicting declarations in \p Decls.
196     ///
197     /// \returns the name that the newly-imported declaration should have.
198     virtual DeclarationName HandleNameConflict(DeclarationName Name,
199                                                DeclContext *DC,
200                                                unsigned IDNS,
201                                                NamedDecl **Decls,
202                                                unsigned NumDecls);
203     
204     /// \brief Retrieve the context that AST nodes are being imported into.
205     ASTContext &getToContext() const { return ToContext; }
206     
207     /// \brief Retrieve the context that AST nodes are being imported from.
208     ASTContext &getFromContext() const { return FromContext; }
209     
210     /// \brief Retrieve the file manager that AST nodes are being imported into.
211     FileManager &getToFileManager() const { return ToFileManager; }
212
213     /// \brief Retrieve the file manager that AST nodes are being imported from.
214     FileManager &getFromFileManager() const { return FromFileManager; }
215
216     /// \brief Retrieve the diagnostic formatter.
217     Diagnostic &getDiags() const { return Diags; }
218     
219     /// \brief Report a diagnostic in the "to" context.
220     DiagnosticBuilder ToDiag(SourceLocation Loc, unsigned DiagID);
221     
222     /// \brief Report a diagnostic in the "from" context.
223     DiagnosticBuilder FromDiag(SourceLocation Loc, unsigned DiagID);
224     
225     /// \brief Return the set of declarations that we know are not equivalent.
226     NonEquivalentDeclSet &getNonEquivalentDecls() { return NonEquivalentDecls; }
227     
228     /// \brief Note that we have imported the "from" declaration by mapping it
229     /// to the (potentially-newly-created) "to" declaration.
230     ///
231     /// \returns \p To
232     Decl *Imported(Decl *From, Decl *To);
233     
234     /// \brief Determine whether the given types are structurally
235     /// equivalent.
236     bool IsStructurallyEquivalent(QualType From, QualType To);
237   };
238 }
239
240 #endif // LLVM_CLANG_AST_ASTIMPORTER_H