11b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor//===--- ASTImporter.h - Importing ASTs from other Contexts -----*- C++ -*-===//
21b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor//
31b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor//                     The LLVM Compiler Infrastructure
41b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor//
51b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor// This file is distributed under the University of Illinois Open Source
61b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor// License. See LICENSE.TXT for details.
71b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor//
81b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor//===----------------------------------------------------------------------===//
91b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor//
101b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor//  This file defines the ASTImporter class which imports AST nodes from one
111b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor//  context into another context.
121b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor//
131b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor//===----------------------------------------------------------------------===//
144794081837ba088965a71652a46494ef4c6b2590Douglas Gregor#ifndef LLVM_CLANG_AST_ASTIMPORTER_H
151b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor#define LLVM_CLANG_AST_ASTIMPORTER_H
161b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor
171b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor#include "clang/AST/DeclarationName.h"
185818f2280c145696cdb87afe7754c4ac9e4fb821Nick Lewycky#include "clang/AST/Type.h"
191b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor#include "clang/Basic/SourceLocation.h"
20169fba50da76d71723cd1d91629cabb310f8bf9eDouglas Gregor#include "llvm/ADT/DenseMap.h"
21ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor#include "llvm/ADT/DenseSet.h"
22ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor#include "llvm/ADT/SmallVector.h"
231b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor
241b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregornamespace clang {
251b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor  class ASTContext;
261b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor  class Decl;
271b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor  class DeclContext;
28d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  class DiagnosticsEngine;
291b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor  class Expr;
30885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor  class FileManager;
311b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor  class IdentifierInfo;
321b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor  class NestedNameSpecifier;
331b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor  class Stmt;
341b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor  class TypeSourceInfo;
351b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor
361b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor  /// \brief Imports selected nodes from one AST context into another context,
371b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor  /// merging AST nodes where appropriate.
381b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor  class ASTImporter {
39ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor  public:
40ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor    typedef llvm::DenseSet<std::pair<Decl *, Decl *> > NonEquivalentDeclSet;
41ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor
42ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor  private:
431b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// \brief The contexts we're importing to and from.
441b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    ASTContext &ToContext, &FromContext;
451b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor
46885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor    /// \brief The file managers we're importing to and from.
47885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor    FileManager &ToFileManager, &FromFileManager;
48389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis
49d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    /// \brief Whether to perform a minimal import.
50d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    bool Minimal;
515b9268f26ac53a74d2c504279fe577d988d5615dRichard Smith
525b9268f26ac53a74d2c504279fe577d988d5615dRichard Smith    /// \brief Whether the last diagnostic came from the "from" context.
535b9268f26ac53a74d2c504279fe577d988d5615dRichard Smith    bool LastDiagFromFrom;
54d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor
55169fba50da76d71723cd1d91629cabb310f8bf9eDouglas Gregor    /// \brief Mapping from the already-imported types in the "from" context
56169fba50da76d71723cd1d91629cabb310f8bf9eDouglas Gregor    /// to the corresponding types in the "to" context.
57f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall    llvm::DenseMap<const Type *, const Type *> ImportedTypes;
58169fba50da76d71723cd1d91629cabb310f8bf9eDouglas Gregor
59089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    /// \brief Mapping from the already-imported declarations in the "from"
60089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    /// context to the corresponding declarations in the "to" context.
61089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    llvm::DenseMap<Decl *, Decl *> ImportedDecls;
624800d95d28b20eca5d57c108ae3d2e6e312c1182Douglas Gregor
634800d95d28b20eca5d57c108ae3d2e6e312c1182Douglas Gregor    /// \brief Mapping from the already-imported statements in the "from"
644800d95d28b20eca5d57c108ae3d2e6e312c1182Douglas Gregor    /// context to the corresponding statements in the "to" context.
654800d95d28b20eca5d57c108ae3d2e6e312c1182Douglas Gregor    llvm::DenseMap<Stmt *, Stmt *> ImportedStmts;
664800d95d28b20eca5d57c108ae3d2e6e312c1182Douglas Gregor
67885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor    /// \brief Mapping from the already-imported FileIDs in the "from" source
68885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor    /// manager to the corresponding FileIDs in the "to" source manager.
69535a3e20104461c136654d59fb833ae80644ae79Sebastian Redl    llvm::DenseMap<FileID, FileID> ImportedFileIDs;
70885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor
71ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor    /// \brief Imported, anonymous tag declarations that are missing their
72ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor    /// corresponding typedefs.
73686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    SmallVector<TagDecl *, 4> AnonTagsWithPendingTypedefs;
74ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor
75ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor    /// \brief Declaration (from, to) pairs that are known not to be equivalent
76ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor    /// (which we have already complained about).
77ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor    NonEquivalentDeclSet NonEquivalentDecls;
78ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor
791b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor  public:
80d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    /// \brief Create a new AST importer.
81d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    ///
82d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    /// \param ToContext The context we'll be importing into.
83d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    ///
84d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    /// \param ToFileManager The file manager we'll be importing into.
85d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    ///
86d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    /// \param FromContext The context we'll be importing from.
87d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    ///
88d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    /// \param FromFileManager The file manager we'll be importing into.
89d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    ///
90d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    /// \param MinimalImport If true, the importer will attempt to import
91d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    /// as little as it can, e.g., by importing declarations as forward
92d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    /// declarations that can be completed at a later point.
9333e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis    ASTImporter(ASTContext &ToContext, FileManager &ToFileManager,
94d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor                ASTContext &FromContext, FileManager &FromFileManager,
95d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor                bool MinimalImport);
961b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor
97089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    virtual ~ASTImporter();
981b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor
99d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    /// \brief Whether the importer will perform a minimal import, creating
100d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    /// to-be-completed forward declarations when possible.
101d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    bool isMinimalImport() const { return Minimal; }
102d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor
1031b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// \brief Import the given type from the "from" context into the "to"
1041b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// context.
1051b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    ///
1061b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// \returns the equivalent type in the "to" context, or a NULL type if
1071b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// an error occurred.
1081b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    QualType Import(QualType FromT);
1091b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor
1101b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// \brief Import the given type source information from the
1111b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// "from" context into the "to" context.
1121b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    ///
1131b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// \returns the equivalent type source information in the "to"
1141b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// context, or NULL if an error occurred.
1151b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    TypeSourceInfo *Import(TypeSourceInfo *FromTSI);
1161b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor
1171b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// \brief Import the given declaration from the "from" context into the
1181b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// "to" context.
1191b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    ///
1201b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// \returns the equivalent declaration in the "to" context, or a NULL type
1211b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// if an error occurred.
1221b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    Decl *Import(Decl *FromD);
1231b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor
1241b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// \brief Import the given declaration context from the "from"
1251b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// AST context into the "to" AST context.
1261b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    ///
1271b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// \returns the equivalent declaration context in the "to"
1281b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// context, or a NULL type if an error occurred.
1291b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    DeclContext *ImportContext(DeclContext *FromDC);
1301b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor
1311b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// \brief Import the given expression from the "from" context into the
1321b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// "to" context.
1331b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    ///
1341b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// \returns the equivalent expression in the "to" context, or NULL if
1351b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// an error occurred.
1361b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    Expr *Import(Expr *FromE);
1371b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor
1381b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// \brief Import the given statement from the "from" context into the
1391b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// "to" context.
1401b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    ///
1411b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// \returns the equivalent statement in the "to" context, or NULL if
1421b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// an error occurred.
1431b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    Stmt *Import(Stmt *FromS);
1441b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor
1451b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// \brief Import the given nested-name-specifier from the "from"
1461b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// context into the "to" context.
1471b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    ///
1481b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// \returns the equivalent nested-name-specifier in the "to"
1491b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// context, or NULL if an error occurred.
1501b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    NestedNameSpecifier *Import(NestedNameSpecifier *FromNNS);
151c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
152c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    /// \brief Import the given nested-name-specifier from the "from"
153c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    /// context into the "to" context.
154c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    ///
155c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    /// \returns the equivalent nested-name-specifier in the "to"
156c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    /// context.
157c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    NestedNameSpecifierLoc Import(NestedNameSpecifierLoc FromNNS);
158c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
159d5dc83a85c1b9aa32f8262126183df5d71c357aeDouglas Gregor    /// \brief Import the goven template name from the "from" context into the
160d5dc83a85c1b9aa32f8262126183df5d71c357aeDouglas Gregor    /// "to" context.
161d5dc83a85c1b9aa32f8262126183df5d71c357aeDouglas Gregor    TemplateName Import(TemplateName From);
162d5dc83a85c1b9aa32f8262126183df5d71c357aeDouglas Gregor
1631b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// \brief Import the given source location from the "from" context into
1641b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// the "to" context.
1651b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    ///
1661b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// \returns the equivalent source location in the "to" context, or an
1671b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// invalid source location if an error occurred.
1681b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    SourceLocation Import(SourceLocation FromLoc);
1691b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor
1701b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// \brief Import the given source range from the "from" context into
1711b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// the "to" context.
1721b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    ///
1731b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// \returns the equivalent source range in the "to" context, or an
1741b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// invalid source location if an error occurred.
1751b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    SourceRange Import(SourceRange FromRange);
1761b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor
1771b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// \brief Import the given declaration name from the "from"
1781b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// context into the "to" context.
1791b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    ///
1801b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// \returns the equivalent declaration name in the "to" context,
1811b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// or an empty declaration name if an error occurred.
1821b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    DeclarationName Import(DeclarationName FromName);
1831b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor
1841b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// \brief Import the given identifier from the "from" context
1851b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// into the "to" context.
1861b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    ///
1871b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// \returns the equivalent identifier in the "to" context.
188d5dc83a85c1b9aa32f8262126183df5d71c357aeDouglas Gregor    IdentifierInfo *Import(const IdentifierInfo *FromId);
1891b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor
190c3f2d2bb839593eed8861bce14228df0faf7b6c0Douglas Gregor    /// \brief Import the given Objective-C selector from the "from"
191c3f2d2bb839593eed8861bce14228df0faf7b6c0Douglas Gregor    /// context into the "to" context.
192c3f2d2bb839593eed8861bce14228df0faf7b6c0Douglas Gregor    ///
193c3f2d2bb839593eed8861bce14228df0faf7b6c0Douglas Gregor    /// \returns the equivalent selector in the "to" context.
194c3f2d2bb839593eed8861bce14228df0faf7b6c0Douglas Gregor    Selector Import(Selector FromSel);
195c3f2d2bb839593eed8861bce14228df0faf7b6c0Douglas Gregor
196885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor    /// \brief Import the given file ID from the "from" context into the
197885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor    /// "to" context.
198885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor    ///
199885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor    /// \returns the equivalent file ID in the source manager of the "to"
200885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor    /// context.
201885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor    FileID Import(FileID);
202885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor
203d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    /// \brief Import the definition of the given declaration, including all of
204d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    /// the declarations it contains.
205d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    ///
206d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    /// This routine is intended to be used
207d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    void ImportDefinition(Decl *From);
208d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor
209089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    /// \brief Cope with a name conflict when importing a declaration into the
210089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    /// given context.
211089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    ///
212089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    /// This routine is invoked whenever there is a name conflict while
213089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    /// importing a declaration. The returned name will become the name of the
214089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    /// imported declaration. By default, the returned name is the same as the
215089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    /// original name, leaving the conflict unresolve such that name lookup
216089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    /// for this name is likely to find an ambiguity later.
217089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    ///
218089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    /// Subclasses may override this routine to resolve the conflict, e.g., by
219089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    /// renaming the declaration being imported.
220089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    ///
221089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    /// \param Name the name of the declaration being imported, which conflicts
222089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    /// with other declarations.
223089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    ///
224089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    /// \param DC the declaration context (in the "to" AST context) in which
225089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    /// the name is being imported.
226089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    ///
227089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    /// \param IDNS the identifier namespace in which the name will be found.
228089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    ///
229089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    /// \param Decls the set of declarations with the same name as the
230089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    /// declaration being imported.
231089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    ///
232089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    /// \param NumDecls the number of conflicting declarations in \p Decls.
233089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    ///
234089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    /// \returns the name that the newly-imported declaration should have.
235089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    virtual DeclarationName HandleNameConflict(DeclarationName Name,
236089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor                                               DeclContext *DC,
237089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor                                               unsigned IDNS,
238089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor                                               NamedDecl **Decls,
239089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor                                               unsigned NumDecls);
240089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor
2411b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// \brief Retrieve the context that AST nodes are being imported into.
2421b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    ASTContext &getToContext() const { return ToContext; }
2431b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor
2441b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    /// \brief Retrieve the context that AST nodes are being imported from.
2451b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor    ASTContext &getFromContext() const { return FromContext; }
2461b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor
247885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor    /// \brief Retrieve the file manager that AST nodes are being imported into.
248885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor    FileManager &getToFileManager() const { return ToFileManager; }
249885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor
250885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor    /// \brief Retrieve the file manager that AST nodes are being imported from.
251885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor    FileManager &getFromFileManager() const { return FromFileManager; }
25273dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor
253089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    /// \brief Report a diagnostic in the "to" context.
254089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    DiagnosticBuilder ToDiag(SourceLocation Loc, unsigned DiagID);
255089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor
256089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    /// \brief Report a diagnostic in the "from" context.
257089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor    DiagnosticBuilder FromDiag(SourceLocation Loc, unsigned DiagID);
2585ce5dab3c30e4255b8f62b148b6a86f09a444aaaDouglas Gregor
259ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor    /// \brief Return the set of declarations that we know are not equivalent.
260ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor    NonEquivalentDeclSet &getNonEquivalentDecls() { return NonEquivalentDecls; }
261ac32ff9812e7d6bc31573b5499bfd005fc8b8f39Douglas Gregor
262ac32ff9812e7d6bc31573b5499bfd005fc8b8f39Douglas Gregor    /// \brief Called for ObjCInterfaceDecl, ObjCProtocolDecl, and TagDecl.
263ac32ff9812e7d6bc31573b5499bfd005fc8b8f39Douglas Gregor    /// Mark the Decl as complete, filling it in as much as possible.
264ac32ff9812e7d6bc31573b5499bfd005fc8b8f39Douglas Gregor    ///
265ac32ff9812e7d6bc31573b5499bfd005fc8b8f39Douglas Gregor    /// \param D A declaration in the "to" context.
266ac32ff9812e7d6bc31573b5499bfd005fc8b8f39Douglas Gregor    virtual void CompleteDecl(Decl* D);
267ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor
2685ce5dab3c30e4255b8f62b148b6a86f09a444aaaDouglas Gregor    /// \brief Note that we have imported the "from" declaration by mapping it
2695ce5dab3c30e4255b8f62b148b6a86f09a444aaaDouglas Gregor    /// to the (potentially-newly-created) "to" declaration.
2705ce5dab3c30e4255b8f62b148b6a86f09a444aaaDouglas Gregor    ///
271d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    /// Subclasses can override this function to observe all of the \c From ->
272d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    /// \c To declaration mappings as they are imported.
273d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor    virtual Decl *Imported(Decl *From, Decl *To);
2748f2cb42e1aa5dbdd6fa651a5da7ab8a3a0d4deceSean Callanan
2758f2cb42e1aa5dbdd6fa651a5da7ab8a3a0d4deceSean Callanan    /// \brief Called by StructuralEquivalenceContext.  If a RecordDecl is
2768f2cb42e1aa5dbdd6fa651a5da7ab8a3a0d4deceSean Callanan    /// being compared to another RecordDecl as part of import, completing the
2778f2cb42e1aa5dbdd6fa651a5da7ab8a3a0d4deceSean Callanan    /// other RecordDecl may trigger importation of the first RecordDecl. This
2788f2cb42e1aa5dbdd6fa651a5da7ab8a3a0d4deceSean Callanan    /// happens especially for anonymous structs.  If the original of the second
2798f2cb42e1aa5dbdd6fa651a5da7ab8a3a0d4deceSean Callanan    /// RecordDecl can be found, we can complete it without the need for
2808f2cb42e1aa5dbdd6fa651a5da7ab8a3a0d4deceSean Callanan    /// importation, eliminating this loop.
2816bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    virtual Decl *GetOriginalDecl(Decl *To) { return nullptr; }
282ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor
283ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor    /// \brief Determine whether the given types are structurally
284ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor    /// equivalent.
28593ed7cf05f900b9150dcf59c0e0f37f3bd325f62Douglas Gregor    bool IsStructurallyEquivalent(QualType From, QualType To,
28693ed7cf05f900b9150dcf59c0e0f37f3bd325f62Douglas Gregor                                  bool Complain = true);
2871b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor  };
2881b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor}
2891b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor
2901b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor#endif // LLVM_CLANG_AST_ASTIMPORTER_H
291