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; 264967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar class CXXCtorInitializer; 271b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor class Decl; 281b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor class DeclContext; 29d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie class DiagnosticsEngine; 301b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor class Expr; 31885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor class FileManager; 321b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor class IdentifierInfo; 331b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor class NestedNameSpecifier; 341b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor class Stmt; 351b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor class TypeSourceInfo; 361b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor 371b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \brief Imports selected nodes from one AST context into another context, 381b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// merging AST nodes where appropriate. 391b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor class ASTImporter { 40ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor public: 41ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor typedef llvm::DenseSet<std::pair<Decl *, Decl *> > NonEquivalentDeclSet; 42ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor 43ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor private: 441b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \brief The contexts we're importing to and from. 451b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor ASTContext &ToContext, &FromContext; 461b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor 47885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor /// \brief The file managers we're importing to and from. 48885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor FileManager &ToFileManager, &FromFileManager; 49389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis 50d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor /// \brief Whether to perform a minimal import. 51d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor bool Minimal; 525b9268f26ac53a74d2c504279fe577d988d5615dRichard Smith 535b9268f26ac53a74d2c504279fe577d988d5615dRichard Smith /// \brief Whether the last diagnostic came from the "from" context. 545b9268f26ac53a74d2c504279fe577d988d5615dRichard Smith bool LastDiagFromFrom; 55d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor 56169fba50da76d71723cd1d91629cabb310f8bf9eDouglas Gregor /// \brief Mapping from the already-imported types in the "from" context 57169fba50da76d71723cd1d91629cabb310f8bf9eDouglas Gregor /// to the corresponding types in the "to" context. 58f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall llvm::DenseMap<const Type *, const Type *> ImportedTypes; 59169fba50da76d71723cd1d91629cabb310f8bf9eDouglas Gregor 60089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// \brief Mapping from the already-imported declarations in the "from" 61089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// context to the corresponding declarations in the "to" context. 62089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor llvm::DenseMap<Decl *, Decl *> ImportedDecls; 634800d95d28b20eca5d57c108ae3d2e6e312c1182Douglas Gregor 644800d95d28b20eca5d57c108ae3d2e6e312c1182Douglas Gregor /// \brief Mapping from the already-imported statements in the "from" 654800d95d28b20eca5d57c108ae3d2e6e312c1182Douglas Gregor /// context to the corresponding statements in the "to" context. 664800d95d28b20eca5d57c108ae3d2e6e312c1182Douglas Gregor llvm::DenseMap<Stmt *, Stmt *> ImportedStmts; 674800d95d28b20eca5d57c108ae3d2e6e312c1182Douglas Gregor 68885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor /// \brief Mapping from the already-imported FileIDs in the "from" source 69885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor /// manager to the corresponding FileIDs in the "to" source manager. 70535a3e20104461c136654d59fb833ae80644ae79Sebastian Redl llvm::DenseMap<FileID, FileID> ImportedFileIDs; 71885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor 72ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor /// \brief Imported, anonymous tag declarations that are missing their 73ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor /// corresponding typedefs. 74686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<TagDecl *, 4> AnonTagsWithPendingTypedefs; 75ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor 76ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor /// \brief Declaration (from, to) pairs that are known not to be equivalent 77ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor /// (which we have already complained about). 78ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor NonEquivalentDeclSet NonEquivalentDecls; 79ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor 801b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor public: 81d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor /// \brief Create a new AST importer. 82d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor /// 83d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor /// \param ToContext The context we'll be importing into. 84d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor /// 85d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor /// \param ToFileManager The file manager we'll be importing into. 86d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor /// 87d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor /// \param FromContext The context we'll be importing from. 88d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor /// 89d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor /// \param FromFileManager The file manager we'll be importing into. 90d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor /// 91d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor /// \param MinimalImport If true, the importer will attempt to import 92d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor /// as little as it can, e.g., by importing declarations as forward 93d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor /// declarations that can be completed at a later point. 9433e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, 95d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor ASTContext &FromContext, FileManager &FromFileManager, 96d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor bool MinimalImport); 971b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor 98089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor virtual ~ASTImporter(); 991b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor 100d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor /// \brief Whether the importer will perform a minimal import, creating 101d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor /// to-be-completed forward declarations when possible. 102d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor bool isMinimalImport() const { return Minimal; } 103d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor 1041b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \brief Import the given type from the "from" context into the "to" 1051b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// context. 1061b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// 1071b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \returns the equivalent type in the "to" context, or a NULL type if 1081b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// an error occurred. 1091b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor QualType Import(QualType FromT); 1101b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor 1111b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \brief Import the given type source information from the 1121b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// "from" context into the "to" context. 1131b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// 1141b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \returns the equivalent type source information in the "to" 1151b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// context, or NULL if an error occurred. 1161b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor TypeSourceInfo *Import(TypeSourceInfo *FromTSI); 1171b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor 1181b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \brief Import the given declaration from the "from" context into the 1191b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// "to" context. 1201b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// 1211b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \returns the equivalent declaration in the "to" context, or a NULL type 1221b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// if an error occurred. 1231b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor Decl *Import(Decl *FromD); 124b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar 125b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// \brief Return the copy of the given declaration in the "to" context if 126b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// it has already been imported from the "from" context. Otherwise return 127b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// NULL. 128b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar Decl *GetAlreadyImportedOrNull(Decl *FromD); 1291b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor 1301b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \brief Import the given declaration context from the "from" 1311b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// AST context into the "to" AST context. 1321b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// 1331b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \returns the equivalent declaration context in the "to" 1341b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// context, or a NULL type if an error occurred. 1351b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor DeclContext *ImportContext(DeclContext *FromDC); 1361b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor 1371b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \brief Import the given expression from the "from" context into the 1381b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// "to" context. 1391b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// 1401b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \returns the equivalent expression in the "to" context, or NULL if 1411b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// an error occurred. 1421b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor Expr *Import(Expr *FromE); 1431b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor 1441b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \brief Import the given statement from the "from" context into the 1451b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// "to" context. 1461b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// 1471b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \returns the equivalent statement in the "to" context, or NULL if 1481b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// an error occurred. 1491b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor Stmt *Import(Stmt *FromS); 1501b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor 1511b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \brief Import the given nested-name-specifier from the "from" 1521b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// context into the "to" context. 1531b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// 1541b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \returns the equivalent nested-name-specifier in the "to" 1551b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// context, or NULL if an error occurred. 1561b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor NestedNameSpecifier *Import(NestedNameSpecifier *FromNNS); 157c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 158c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// \brief Import the given nested-name-specifier from the "from" 159c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// context into the "to" context. 160c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// 161c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// \returns the equivalent nested-name-specifier in the "to" 162c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// context. 163c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifierLoc Import(NestedNameSpecifierLoc FromNNS); 164c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 165d5dc83a85c1b9aa32f8262126183df5d71c357aeDouglas Gregor /// \brief Import the goven template name from the "from" context into the 166d5dc83a85c1b9aa32f8262126183df5d71c357aeDouglas Gregor /// "to" context. 167d5dc83a85c1b9aa32f8262126183df5d71c357aeDouglas Gregor TemplateName Import(TemplateName From); 168d5dc83a85c1b9aa32f8262126183df5d71c357aeDouglas Gregor 1691b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \brief Import the given source location from the "from" context into 1701b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// the "to" context. 1711b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// 1721b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \returns the equivalent source location in the "to" context, or an 1731b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// invalid source location if an error occurred. 1741b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor SourceLocation Import(SourceLocation FromLoc); 1751b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor 1761b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \brief Import the given source range from the "from" context into 1771b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// the "to" context. 1781b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// 1791b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \returns the equivalent source range in the "to" context, or an 1801b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// invalid source location if an error occurred. 1811b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor SourceRange Import(SourceRange FromRange); 1821b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor 1831b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \brief Import the given declaration name from the "from" 1841b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// context into the "to" context. 1851b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// 1861b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \returns the equivalent declaration name in the "to" context, 1871b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// or an empty declaration name if an error occurred. 1881b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor DeclarationName Import(DeclarationName FromName); 1891b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor 1901b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \brief Import the given identifier from the "from" context 1911b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// into the "to" context. 1921b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// 1931b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \returns the equivalent identifier in the "to" context. 194d5dc83a85c1b9aa32f8262126183df5d71c357aeDouglas Gregor IdentifierInfo *Import(const IdentifierInfo *FromId); 1951b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor 196c3f2d2bb839593eed8861bce14228df0faf7b6c0Douglas Gregor /// \brief Import the given Objective-C selector from the "from" 197c3f2d2bb839593eed8861bce14228df0faf7b6c0Douglas Gregor /// context into the "to" context. 198c3f2d2bb839593eed8861bce14228df0faf7b6c0Douglas Gregor /// 199c3f2d2bb839593eed8861bce14228df0faf7b6c0Douglas Gregor /// \returns the equivalent selector in the "to" context. 200c3f2d2bb839593eed8861bce14228df0faf7b6c0Douglas Gregor Selector Import(Selector FromSel); 201c3f2d2bb839593eed8861bce14228df0faf7b6c0Douglas Gregor 202885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor /// \brief Import the given file ID from the "from" context into the 203885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor /// "to" context. 204885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor /// 205885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor /// \returns the equivalent file ID in the source manager of the "to" 206885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor /// context. 207885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor FileID Import(FileID); 2084967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 2094967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// \brief Import the given C++ constructor initializer from the "from" 2104967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// context into the "to" context. 2114967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// 2124967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// \returns the equivalent initializer in the "to" context. 2134967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CXXCtorInitializer *Import(CXXCtorInitializer *FromInit); 2144967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 2154967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 216885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor 217d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor /// \brief Import the definition of the given declaration, including all of 218d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor /// the declarations it contains. 219d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor /// 220d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor /// This routine is intended to be used 221d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor void ImportDefinition(Decl *From); 222d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor 223089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// \brief Cope with a name conflict when importing a declaration into the 224089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// given context. 225089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// 226089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// This routine is invoked whenever there is a name conflict while 227089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// importing a declaration. The returned name will become the name of the 228089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// imported declaration. By default, the returned name is the same as the 229089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// original name, leaving the conflict unresolve such that name lookup 230089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// for this name is likely to find an ambiguity later. 231089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// 232089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// Subclasses may override this routine to resolve the conflict, e.g., by 233089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// renaming the declaration being imported. 234089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// 235089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// \param Name the name of the declaration being imported, which conflicts 236089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// with other declarations. 237089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// 238089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// \param DC the declaration context (in the "to" AST context) in which 239089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// the name is being imported. 240089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// 241089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// \param IDNS the identifier namespace in which the name will be found. 242089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// 243089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// \param Decls the set of declarations with the same name as the 244089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// declaration being imported. 245089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// 246089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// \param NumDecls the number of conflicting declarations in \p Decls. 247089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// 248089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// \returns the name that the newly-imported declaration should have. 249089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor virtual DeclarationName HandleNameConflict(DeclarationName Name, 250089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor DeclContext *DC, 251089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor unsigned IDNS, 252089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor NamedDecl **Decls, 253089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor unsigned NumDecls); 254089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor 2551b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \brief Retrieve the context that AST nodes are being imported into. 2561b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor ASTContext &getToContext() const { return ToContext; } 2571b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor 2581b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor /// \brief Retrieve the context that AST nodes are being imported from. 2591b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor ASTContext &getFromContext() const { return FromContext; } 2601b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor 261885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor /// \brief Retrieve the file manager that AST nodes are being imported into. 262885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor FileManager &getToFileManager() const { return ToFileManager; } 263885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor 264885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor /// \brief Retrieve the file manager that AST nodes are being imported from. 265885237354fd902998c6ae9d7cc3dc8de96b123dcDouglas Gregor FileManager &getFromFileManager() const { return FromFileManager; } 26673dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor 267089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// \brief Report a diagnostic in the "to" context. 268089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor DiagnosticBuilder ToDiag(SourceLocation Loc, unsigned DiagID); 269089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor 270089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor /// \brief Report a diagnostic in the "from" context. 271089459a16bf7e9cd10617d1fac5ec0240a0a1ee6Douglas Gregor DiagnosticBuilder FromDiag(SourceLocation Loc, unsigned DiagID); 2725ce5dab3c30e4255b8f62b148b6a86f09a444aaaDouglas Gregor 273ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor /// \brief Return the set of declarations that we know are not equivalent. 274ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor NonEquivalentDeclSet &getNonEquivalentDecls() { return NonEquivalentDecls; } 275ac32ff9812e7d6bc31573b5499bfd005fc8b8f39Douglas Gregor 276ac32ff9812e7d6bc31573b5499bfd005fc8b8f39Douglas Gregor /// \brief Called for ObjCInterfaceDecl, ObjCProtocolDecl, and TagDecl. 277ac32ff9812e7d6bc31573b5499bfd005fc8b8f39Douglas Gregor /// Mark the Decl as complete, filling it in as much as possible. 278ac32ff9812e7d6bc31573b5499bfd005fc8b8f39Douglas Gregor /// 279ac32ff9812e7d6bc31573b5499bfd005fc8b8f39Douglas Gregor /// \param D A declaration in the "to" context. 280ac32ff9812e7d6bc31573b5499bfd005fc8b8f39Douglas Gregor virtual void CompleteDecl(Decl* D); 281ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor 2825ce5dab3c30e4255b8f62b148b6a86f09a444aaaDouglas Gregor /// \brief Note that we have imported the "from" declaration by mapping it 2835ce5dab3c30e4255b8f62b148b6a86f09a444aaaDouglas Gregor /// to the (potentially-newly-created) "to" declaration. 2845ce5dab3c30e4255b8f62b148b6a86f09a444aaaDouglas Gregor /// 285d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor /// Subclasses can override this function to observe all of the \c From -> 286d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor /// \c To declaration mappings as they are imported. 287d8868a634d4fd362243dc646e58c3cf956c81dcdDouglas Gregor virtual Decl *Imported(Decl *From, Decl *To); 2888f2cb42e1aa5dbdd6fa651a5da7ab8a3a0d4deceSean Callanan 2898f2cb42e1aa5dbdd6fa651a5da7ab8a3a0d4deceSean Callanan /// \brief Called by StructuralEquivalenceContext. If a RecordDecl is 2908f2cb42e1aa5dbdd6fa651a5da7ab8a3a0d4deceSean Callanan /// being compared to another RecordDecl as part of import, completing the 2918f2cb42e1aa5dbdd6fa651a5da7ab8a3a0d4deceSean Callanan /// other RecordDecl may trigger importation of the first RecordDecl. This 2928f2cb42e1aa5dbdd6fa651a5da7ab8a3a0d4deceSean Callanan /// happens especially for anonymous structs. If the original of the second 2938f2cb42e1aa5dbdd6fa651a5da7ab8a3a0d4deceSean Callanan /// RecordDecl can be found, we can complete it without the need for 2948f2cb42e1aa5dbdd6fa651a5da7ab8a3a0d4deceSean Callanan /// importation, eliminating this loop. 2956bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines virtual Decl *GetOriginalDecl(Decl *To) { return nullptr; } 296ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor 297ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor /// \brief Determine whether the given types are structurally 298ea35d11905f756ad33b87bd89cd3ac1e7ce57994Douglas Gregor /// equivalent. 29993ed7cf05f900b9150dcf59c0e0f37f3bd325f62Douglas Gregor bool IsStructurallyEquivalent(QualType From, QualType To, 30093ed7cf05f900b9150dcf59c0e0f37f3bd325f62Douglas Gregor bool Complain = true); 3011b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor }; 3021b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor} 3031b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor 3041b2949d27ec72894dec017c330c0548af4bb2476Douglas Gregor#endif // LLVM_CLANG_AST_ASTIMPORTER_H 305