ASTImporter.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- ASTImporter.h - Importing ASTs from other Contexts -------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines the ASTImporter class which imports AST nodes from one
  15. // context into another context.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_CLANG_AST_ASTIMPORTER_H
  19. #define LLVM_CLANG_AST_ASTIMPORTER_H
  20. #include "clang/AST/APValue.h"
  21. #include "clang/AST/DeclBase.h"
  22. #include "clang/AST/DeclarationName.h"
  23. #include "clang/AST/ExprCXX.h"
  24. #include "clang/AST/NestedNameSpecifier.h"
  25. #include "clang/AST/TemplateName.h"
  26. #include "clang/AST/Type.h"
  27. #include "clang/Basic/Diagnostic.h"
  28. #include "clang/Basic/IdentifierTable.h"
  29. #include "clang/Basic/LLVM.h"
  30. #include "clang/Basic/SourceLocation.h"
  31. #include "llvm/ADT/DenseMap.h"
  32. #include "llvm/ADT/DenseSet.h"
  33. #include "llvm/ADT/Optional.h"
  34. #include "llvm/ADT/SmallVector.h"
  35. #include "llvm/Support/Error.h"
  36. #include <utility>
  37. namespace clang {
  38. class ASTContext;
  39. class ASTImporterSharedState;
  40. class Attr;
  41. class CXXBaseSpecifier;
  42. class CXXCtorInitializer;
  43. class Decl;
  44. class DeclContext;
  45. class Expr;
  46. class FileManager;
  47. class NamedDecl;
  48. class Stmt;
  49. class TagDecl;
  50. class TranslationUnitDecl;
  51. class TypeSourceInfo;
  52. class ImportError : public llvm::ErrorInfo<ImportError> {
  53. public:
  54. /// \brief Kind of error when importing an AST component.
  55. enum ErrorKind {
  56. NameConflict, /// Naming ambiguity (likely ODR violation).
  57. UnsupportedConstruct, /// Not supported node or case.
  58. Unknown /// Other error.
  59. };
  60. ErrorKind Error;
  61. static char ID;
  62. ImportError() : Error(Unknown) {}
  63. ImportError(const ImportError &Other) : Error(Other.Error) {}
  64. ImportError &operator=(const ImportError &Other) {
  65. Error = Other.Error;
  66. return *this;
  67. }
  68. ImportError(ErrorKind Error) : Error(Error) { }
  69. std::string toString() const;
  70. void log(raw_ostream &OS) const override;
  71. std::error_code convertToErrorCode() const override;
  72. };
  73. // \brief Returns with a list of declarations started from the canonical decl
  74. // then followed by subsequent decls in the translation unit.
  75. // This gives a canonical list for each entry in the redecl chain.
  76. // `Decl::redecls()` gives a list of decls which always start from the
  77. // previous decl and the next item is actually the previous item in the order
  78. // of source locations. Thus, `Decl::redecls()` gives different lists for
  79. // the different entries in a given redecl chain.
  80. llvm::SmallVector<Decl*, 2> getCanonicalForwardRedeclChain(Decl* D);
  81. /// Imports selected nodes from one AST context into another context,
  82. /// merging AST nodes where appropriate.
  83. class ASTImporter {
  84. friend class ASTNodeImporter;
  85. public:
  86. using NonEquivalentDeclSet = llvm::DenseSet<std::pair<Decl *, Decl *>>;
  87. using ImportedCXXBaseSpecifierMap =
  88. llvm::DenseMap<const CXXBaseSpecifier *, CXXBaseSpecifier *>;
  89. enum class ODRHandlingType { Conservative, Liberal };
  90. // An ImportPath is the list of the AST nodes which we visit during an
  91. // Import call.
  92. // If node `A` depends on node `B` then the path contains an `A`->`B` edge.
  93. // From the call stack of the import functions we can read the very same
  94. // path.
  95. //
  96. // Now imagine the following AST, where the `->` represents dependency in
  97. // therms of the import.
  98. // ```
  99. // A->B->C->D
  100. // `->E
  101. // ```
  102. // We would like to import A.
  103. // The import behaves like a DFS, so we will visit the nodes in this order:
  104. // ABCDE.
  105. // During the visitation we will have the following ImportPaths:
  106. // ```
  107. // A
  108. // AB
  109. // ABC
  110. // ABCD
  111. // ABC
  112. // AB
  113. // ABE
  114. // AB
  115. // A
  116. // ```
  117. // If during the visit of E there is an error then we set an error for E,
  118. // then as the call stack shrinks for B, then for A:
  119. // ```
  120. // A
  121. // AB
  122. // ABC
  123. // ABCD
  124. // ABC
  125. // AB
  126. // ABE // Error! Set an error to E
  127. // AB // Set an error to B
  128. // A // Set an error to A
  129. // ```
  130. // However, during the import we could import C and D without any error and
  131. // they are independent from A,B and E.
  132. // We must not set up an error for C and D.
  133. // So, at the end of the import we have an entry in `ImportDeclErrors` for
  134. // A,B,E but not for C,D.
  135. //
  136. // Now what happens if there is a cycle in the import path?
  137. // Let's consider this AST:
  138. // ```
  139. // A->B->C->A
  140. // `->E
  141. // ```
  142. // During the visitation we will have the below ImportPaths and if during
  143. // the visit of E there is an error then we will set up an error for E,B,A.
  144. // But what's up with C?
  145. // ```
  146. // A
  147. // AB
  148. // ABC
  149. // ABCA
  150. // ABC
  151. // AB
  152. // ABE // Error! Set an error to E
  153. // AB // Set an error to B
  154. // A // Set an error to A
  155. // ```
  156. // This time we know that both B and C are dependent on A.
  157. // This means we must set up an error for C too.
  158. // As the call stack reverses back we get to A and we must set up an error
  159. // to all nodes which depend on A (this includes C).
  160. // But C is no longer on the import path, it just had been previously.
  161. // Such situation can happen only if during the visitation we had a cycle.
  162. // If we didn't have any cycle, then the normal way of passing an Error
  163. // object through the call stack could handle the situation.
  164. // This is why we must track cycles during the import process for each
  165. // visited declaration.
  166. class ImportPathTy {
  167. public:
  168. using VecTy = llvm::SmallVector<Decl *, 32>;
  169. void push(Decl *D) {
  170. Nodes.push_back(D);
  171. ++Aux[D];
  172. }
  173. void pop() {
  174. if (Nodes.empty())
  175. return;
  176. --Aux[Nodes.back()];
  177. Nodes.pop_back();
  178. }
  179. /// Returns true if the last element can be found earlier in the path.
  180. bool hasCycleAtBack() const {
  181. auto Pos = Aux.find(Nodes.back());
  182. return Pos != Aux.end() && Pos->second > 1;
  183. }
  184. using Cycle = llvm::iterator_range<VecTy::const_reverse_iterator>;
  185. Cycle getCycleAtBack() const {
  186. assert(Nodes.size() >= 2);
  187. return Cycle(Nodes.rbegin(),
  188. std::find(Nodes.rbegin() + 1, Nodes.rend(), Nodes.back()) +
  189. 1);
  190. }
  191. /// Returns the copy of the cycle.
  192. VecTy copyCycleAtBack() const {
  193. auto R = getCycleAtBack();
  194. return VecTy(R.begin(), R.end());
  195. }
  196. private:
  197. // All nodes of the path.
  198. VecTy Nodes;
  199. // Auxiliary container to be able to answer "Do we have a cycle ending
  200. // at last element?" as fast as possible.
  201. // We count each Decl's occurrence over the path.
  202. llvm::SmallDenseMap<Decl *, int, 32> Aux;
  203. };
  204. private:
  205. std::shared_ptr<ASTImporterSharedState> SharedState = nullptr;
  206. /// The path which we go through during the import of a given AST node.
  207. ImportPathTy ImportPath;
  208. /// Sometimes we have to save some part of an import path, so later we can
  209. /// set up properties to the saved nodes.
  210. /// We may have several of these import paths associated to one Decl.
  211. using SavedImportPathsForOneDecl =
  212. llvm::SmallVector<ImportPathTy::VecTy, 32>;
  213. using SavedImportPathsTy =
  214. llvm::SmallDenseMap<Decl *, SavedImportPathsForOneDecl, 32>;
  215. SavedImportPathsTy SavedImportPaths;
  216. /// The contexts we're importing to and from.
  217. ASTContext &ToContext, &FromContext;
  218. /// The file managers we're importing to and from.
  219. FileManager &ToFileManager, &FromFileManager;
  220. /// Whether to perform a minimal import.
  221. bool Minimal;
  222. ODRHandlingType ODRHandling;
  223. /// Whether the last diagnostic came from the "from" context.
  224. bool LastDiagFromFrom = false;
  225. /// Mapping from the already-imported types in the "from" context
  226. /// to the corresponding types in the "to" context.
  227. llvm::DenseMap<const Type *, const Type *> ImportedTypes;
  228. /// Mapping from the already-imported declarations in the "from"
  229. /// context to the corresponding declarations in the "to" context.
  230. llvm::DenseMap<Decl *, Decl *> ImportedDecls;
  231. /// Mapping from the already-imported declarations in the "from"
  232. /// context to the error status of the import of that declaration.
  233. /// This map contains only the declarations that were not correctly
  234. /// imported. The same declaration may or may not be included in
  235. /// ImportedDecls. This map is updated continuously during imports and never
  236. /// cleared (like ImportedDecls).
  237. llvm::DenseMap<Decl *, ImportError> ImportDeclErrors;
  238. /// Mapping from the already-imported declarations in the "to"
  239. /// context to the corresponding declarations in the "from" context.
  240. llvm::DenseMap<Decl *, Decl *> ImportedFromDecls;
  241. /// Mapping from the already-imported statements in the "from"
  242. /// context to the corresponding statements in the "to" context.
  243. llvm::DenseMap<Stmt *, Stmt *> ImportedStmts;
  244. /// Mapping from the already-imported FileIDs in the "from" source
  245. /// manager to the corresponding FileIDs in the "to" source manager.
  246. llvm::DenseMap<FileID, FileID> ImportedFileIDs;
  247. /// Mapping from the already-imported CXXBasesSpecifier in
  248. /// the "from" source manager to the corresponding CXXBasesSpecifier
  249. /// in the "to" source manager.
  250. ImportedCXXBaseSpecifierMap ImportedCXXBaseSpecifiers;
  251. /// Declaration (from, to) pairs that are known not to be equivalent
  252. /// (which we have already complained about).
  253. NonEquivalentDeclSet NonEquivalentDecls;
  254. using FoundDeclsTy = SmallVector<NamedDecl *, 2>;
  255. FoundDeclsTy findDeclsInToCtx(DeclContext *DC, DeclarationName Name);
  256. void AddToLookupTable(Decl *ToD);
  257. protected:
  258. /// Can be overwritten by subclasses to implement their own import logic.
  259. /// The overwritten method should call this method if it didn't import the
  260. /// decl on its own.
  261. virtual Expected<Decl *> ImportImpl(Decl *From);
  262. /// Used only in unittests to verify the behaviour of the error handling.
  263. virtual bool returnWithErrorInTest() { return false; };
  264. public:
  265. /// \param ToContext The context we'll be importing into.
  266. ///
  267. /// \param ToFileManager The file manager we'll be importing into.
  268. ///
  269. /// \param FromContext The context we'll be importing from.
  270. ///
  271. /// \param FromFileManager The file manager we'll be importing into.
  272. ///
  273. /// \param MinimalImport If true, the importer will attempt to import
  274. /// as little as it can, e.g., by importing declarations as forward
  275. /// declarations that can be completed at a later point.
  276. ///
  277. /// \param SharedState The importer specific lookup table which may be
  278. /// shared amongst several ASTImporter objects.
  279. /// If not set then the original C/C++ lookup is used.
  280. ASTImporter(ASTContext &ToContext, FileManager &ToFileManager,
  281. ASTContext &FromContext, FileManager &FromFileManager,
  282. bool MinimalImport,
  283. std::shared_ptr<ASTImporterSharedState> SharedState = nullptr);
  284. virtual ~ASTImporter();
  285. /// Whether the importer will perform a minimal import, creating
  286. /// to-be-completed forward declarations when possible.
  287. bool isMinimalImport() const { return Minimal; }
  288. void setODRHandling(ODRHandlingType T) { ODRHandling = T; }
  289. /// \brief Import the given object, returns the result.
  290. ///
  291. /// \param To Import the object into this variable.
  292. /// \param From Object to import.
  293. /// \return Error information (success or error).
  294. template <typename ImportT>
  295. LLVM_NODISCARD llvm::Error importInto(ImportT &To, const ImportT &From) {
  296. auto ToOrErr = Import(From);
  297. if (ToOrErr)
  298. To = *ToOrErr;
  299. return ToOrErr.takeError();
  300. }
  301. /// Import cleanup objects owned by ExprWithCleanup.
  302. llvm::Expected<ExprWithCleanups::CleanupObject>
  303. Import(ExprWithCleanups::CleanupObject From);
  304. /// Import the given type from the "from" context into the "to"
  305. /// context.
  306. ///
  307. /// \returns The equivalent type in the "to" context, or the import error.
  308. llvm::Expected<const Type *> Import(const Type *FromT);
  309. /// Import the given qualified type from the "from" context into the "to"
  310. /// context. A null type is imported as a null type (no error).
  311. ///
  312. /// \returns The equivalent type in the "to" context, or the import error.
  313. llvm::Expected<QualType> Import(QualType FromT);
  314. /// Import the given type source information from the
  315. /// "from" context into the "to" context.
  316. ///
  317. /// \returns The equivalent type source information in the "to"
  318. /// context, or the import error.
  319. llvm::Expected<TypeSourceInfo *> Import(TypeSourceInfo *FromTSI);
  320. /// Import the given attribute from the "from" context into the
  321. /// "to" context.
  322. ///
  323. /// \returns The equivalent attribute in the "to" context, or the import
  324. /// error.
  325. llvm::Expected<Attr *> Import(const Attr *FromAttr);
  326. /// Import the given declaration from the "from" context into the
  327. /// "to" context.
  328. ///
  329. /// \returns The equivalent declaration in the "to" context, or the import
  330. /// error.
  331. llvm::Expected<Decl *> Import(Decl *FromD);
  332. llvm::Expected<const Decl *> Import(const Decl *FromD) {
  333. return Import(const_cast<Decl *>(FromD));
  334. }
  335. llvm::Expected<InheritedConstructor>
  336. Import(const InheritedConstructor &From);
  337. /// Return the copy of the given declaration in the "to" context if
  338. /// it has already been imported from the "from" context. Otherwise return
  339. /// nullptr.
  340. Decl *GetAlreadyImportedOrNull(const Decl *FromD) const;
  341. /// Return the translation unit from where the declaration was
  342. /// imported. If it does not exist nullptr is returned.
  343. TranslationUnitDecl *GetFromTU(Decl *ToD);
  344. /// Return the declaration in the "from" context from which the declaration
  345. /// in the "to" context was imported. If it was not imported or of the wrong
  346. /// type a null value is returned.
  347. template <typename DeclT>
  348. llvm::Optional<DeclT *> getImportedFromDecl(const DeclT *ToD) const {
  349. auto FromI = ImportedFromDecls.find(ToD);
  350. if (FromI == ImportedFromDecls.end())
  351. return {};
  352. auto *FromD = dyn_cast<DeclT>(FromI->second);
  353. if (!FromD)
  354. return {};
  355. return FromD;
  356. }
  357. /// Import the given declaration context from the "from"
  358. /// AST context into the "to" AST context.
  359. ///
  360. /// \returns the equivalent declaration context in the "to"
  361. /// context, or error value.
  362. llvm::Expected<DeclContext *> ImportContext(DeclContext *FromDC);
  363. /// Import the given expression from the "from" context into the
  364. /// "to" context.
  365. ///
  366. /// \returns The equivalent expression in the "to" context, or the import
  367. /// error.
  368. llvm::Expected<Expr *> Import(Expr *FromE);
  369. /// Import the given statement from the "from" context into the
  370. /// "to" context.
  371. ///
  372. /// \returns The equivalent statement in the "to" context, or the import
  373. /// error.
  374. llvm::Expected<Stmt *> Import(Stmt *FromS);
  375. /// Import the given nested-name-specifier from the "from"
  376. /// context into the "to" context.
  377. ///
  378. /// \returns The equivalent nested-name-specifier in the "to"
  379. /// context, or the import error.
  380. llvm::Expected<NestedNameSpecifier *> Import(NestedNameSpecifier *FromNNS);
  381. /// Import the given nested-name-specifier-loc from the "from"
  382. /// context into the "to" context.
  383. ///
  384. /// \returns The equivalent nested-name-specifier-loc in the "to"
  385. /// context, or the import error.
  386. llvm::Expected<NestedNameSpecifierLoc>
  387. Import(NestedNameSpecifierLoc FromNNS);
  388. /// Import the given template name from the "from" context into the
  389. /// "to" context, or the import error.
  390. llvm::Expected<TemplateName> Import(TemplateName From);
  391. /// Import the given source location from the "from" context into
  392. /// the "to" context.
  393. ///
  394. /// \returns The equivalent source location in the "to" context, or the
  395. /// import error.
  396. llvm::Expected<SourceLocation> Import(SourceLocation FromLoc);
  397. /// Import the given source range from the "from" context into
  398. /// the "to" context.
  399. ///
  400. /// \returns The equivalent source range in the "to" context, or the import
  401. /// error.
  402. llvm::Expected<SourceRange> Import(SourceRange FromRange);
  403. /// Import the given declaration name from the "from"
  404. /// context into the "to" context.
  405. ///
  406. /// \returns The equivalent declaration name in the "to" context, or the
  407. /// import error.
  408. llvm::Expected<DeclarationName> Import(DeclarationName FromName);
  409. /// Import the given identifier from the "from" context
  410. /// into the "to" context.
  411. ///
  412. /// \returns The equivalent identifier in the "to" context. Note: It
  413. /// returns nullptr only if the FromId was nullptr.
  414. IdentifierInfo *Import(const IdentifierInfo *FromId);
  415. /// Import the given Objective-C selector from the "from"
  416. /// context into the "to" context.
  417. ///
  418. /// \returns The equivalent selector in the "to" context, or the import
  419. /// error.
  420. llvm::Expected<Selector> Import(Selector FromSel);
  421. /// Import the given file ID from the "from" context into the
  422. /// "to" context.
  423. ///
  424. /// \returns The equivalent file ID in the source manager of the "to"
  425. /// context, or the import error.
  426. llvm::Expected<FileID> Import(FileID, bool IsBuiltin = false);
  427. /// Import the given C++ constructor initializer from the "from"
  428. /// context into the "to" context.
  429. ///
  430. /// \returns The equivalent initializer in the "to" context, or the import
  431. /// error.
  432. llvm::Expected<CXXCtorInitializer *> Import(CXXCtorInitializer *FromInit);
  433. /// Import the given CXXBaseSpecifier from the "from" context into
  434. /// the "to" context.
  435. ///
  436. /// \returns The equivalent CXXBaseSpecifier in the source manager of the
  437. /// "to" context, or the import error.
  438. llvm::Expected<CXXBaseSpecifier *> Import(const CXXBaseSpecifier *FromSpec);
  439. /// Import the given APValue from the "from" context into
  440. /// the "to" context.
  441. ///
  442. /// \return the equivalent APValue in the "to" context or the import
  443. /// error.
  444. llvm::Expected<APValue> Import(const APValue &FromValue);
  445. /// Import the definition of the given declaration, including all of
  446. /// the declarations it contains.
  447. LLVM_NODISCARD llvm::Error ImportDefinition(Decl *From);
  448. /// Cope with a name conflict when importing a declaration into the
  449. /// given context.
  450. ///
  451. /// This routine is invoked whenever there is a name conflict while
  452. /// importing a declaration. The returned name will become the name of the
  453. /// imported declaration. By default, the returned name is the same as the
  454. /// original name, leaving the conflict unresolve such that name lookup
  455. /// for this name is likely to find an ambiguity later.
  456. ///
  457. /// Subclasses may override this routine to resolve the conflict, e.g., by
  458. /// renaming the declaration being imported.
  459. ///
  460. /// \param Name the name of the declaration being imported, which conflicts
  461. /// with other declarations.
  462. ///
  463. /// \param DC the declaration context (in the "to" AST context) in which
  464. /// the name is being imported.
  465. ///
  466. /// \param IDNS the identifier namespace in which the name will be found.
  467. ///
  468. /// \param Decls the set of declarations with the same name as the
  469. /// declaration being imported.
  470. ///
  471. /// \param NumDecls the number of conflicting declarations in \p Decls.
  472. ///
  473. /// \returns the name that the newly-imported declaration should have. Or
  474. /// an error if we can't handle the name conflict.
  475. virtual Expected<DeclarationName>
  476. HandleNameConflict(DeclarationName Name, DeclContext *DC, unsigned IDNS,
  477. NamedDecl **Decls, unsigned NumDecls);
  478. /// Retrieve the context that AST nodes are being imported into.
  479. ASTContext &getToContext() const { return ToContext; }
  480. /// Retrieve the context that AST nodes are being imported from.
  481. ASTContext &getFromContext() const { return FromContext; }
  482. /// Retrieve the file manager that AST nodes are being imported into.
  483. FileManager &getToFileManager() const { return ToFileManager; }
  484. /// Retrieve the file manager that AST nodes are being imported from.
  485. FileManager &getFromFileManager() const { return FromFileManager; }
  486. /// Report a diagnostic in the "to" context.
  487. DiagnosticBuilder ToDiag(SourceLocation Loc, unsigned DiagID);
  488. /// Report a diagnostic in the "from" context.
  489. DiagnosticBuilder FromDiag(SourceLocation Loc, unsigned DiagID);
  490. /// Return the set of declarations that we know are not equivalent.
  491. NonEquivalentDeclSet &getNonEquivalentDecls() { return NonEquivalentDecls; }
  492. /// Called for ObjCInterfaceDecl, ObjCProtocolDecl, and TagDecl.
  493. /// Mark the Decl as complete, filling it in as much as possible.
  494. ///
  495. /// \param D A declaration in the "to" context.
  496. virtual void CompleteDecl(Decl* D);
  497. /// Subclasses can override this function to observe all of the \c From ->
  498. /// \c To declaration mappings as they are imported.
  499. virtual void Imported(Decl *From, Decl *To) {}
  500. void RegisterImportedDecl(Decl *FromD, Decl *ToD);
  501. /// Store and assign the imported declaration to its counterpart.
  502. /// It may happen that several decls from the 'from' context are mapped to
  503. /// the same decl in the 'to' context.
  504. Decl *MapImported(Decl *From, Decl *To);
  505. /// Called by StructuralEquivalenceContext. If a RecordDecl is
  506. /// being compared to another RecordDecl as part of import, completing the
  507. /// other RecordDecl may trigger importation of the first RecordDecl. This
  508. /// happens especially for anonymous structs. If the original of the second
  509. /// RecordDecl can be found, we can complete it without the need for
  510. /// importation, eliminating this loop.
  511. virtual Decl *GetOriginalDecl(Decl *To) { return nullptr; }
  512. /// Return if import of the given declaration has failed and if yes
  513. /// the kind of the problem. This gives the first error encountered with
  514. /// the node.
  515. llvm::Optional<ImportError> getImportDeclErrorIfAny(Decl *FromD) const;
  516. /// Mark (newly) imported declaration with error.
  517. void setImportDeclError(Decl *From, ImportError Error);
  518. /// Determine whether the given types are structurally
  519. /// equivalent.
  520. bool IsStructurallyEquivalent(QualType From, QualType To,
  521. bool Complain = true);
  522. /// Determine the index of a field in its parent record.
  523. /// F should be a field (or indirect field) declaration.
  524. /// \returns The index of the field in its parent context (starting from 0).
  525. /// On error `None` is returned (parent context is non-record).
  526. static llvm::Optional<unsigned> getFieldIndex(Decl *F);
  527. };
  528. } // namespace clang
  529. #endif // LLVM_CLANG_AST_ASTIMPORTER_H
  530. #ifdef __GNUC__
  531. #pragma GCC diagnostic pop
  532. #endif