| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1 | //===- ASTImporter.cpp - Importing ASTs from other Contexts ---------------===// | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 2 | // | 
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | 
|  | 4 | // See https://llvm.org/LICENSE.txt for license information. | 
|  | 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6 | // | 
|  | 7 | //===----------------------------------------------------------------------===// | 
|  | 8 | // | 
|  | 9 | //  This file defines the ASTImporter class which imports AST nodes from one | 
|  | 10 | //  context into another context. | 
|  | 11 | // | 
|  | 12 | //===----------------------------------------------------------------------===// | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 13 |  | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 14 | #include "clang/AST/ASTImporter.h" | 
| Ilya Biryukov | abc744d | 2019-07-18 15:43:26 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTImporterSharedState.h" | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTDiagnostic.h" | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 18 | #include "clang/AST/ASTStructuralEquivalence.h" | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 19 | #include "clang/AST/Attr.h" | 
|  | 20 | #include "clang/AST/Decl.h" | 
|  | 21 | #include "clang/AST/DeclAccessPair.h" | 
|  | 22 | #include "clang/AST/DeclBase.h" | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclCXX.h" | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 24 | #include "clang/AST/DeclFriend.h" | 
|  | 25 | #include "clang/AST/DeclGroup.h" | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 26 | #include "clang/AST/DeclObjC.h" | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 27 | #include "clang/AST/DeclTemplate.h" | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 28 | #include "clang/AST/DeclVisitor.h" | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 29 | #include "clang/AST/DeclarationName.h" | 
|  | 30 | #include "clang/AST/Expr.h" | 
|  | 31 | #include "clang/AST/ExprCXX.h" | 
|  | 32 | #include "clang/AST/ExprObjC.h" | 
|  | 33 | #include "clang/AST/ExternalASTSource.h" | 
|  | 34 | #include "clang/AST/LambdaCapture.h" | 
|  | 35 | #include "clang/AST/NestedNameSpecifier.h" | 
|  | 36 | #include "clang/AST/OperationKinds.h" | 
|  | 37 | #include "clang/AST/Stmt.h" | 
|  | 38 | #include "clang/AST/StmtCXX.h" | 
|  | 39 | #include "clang/AST/StmtObjC.h" | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 40 | #include "clang/AST/StmtVisitor.h" | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 41 | #include "clang/AST/TemplateBase.h" | 
|  | 42 | #include "clang/AST/TemplateName.h" | 
|  | 43 | #include "clang/AST/Type.h" | 
|  | 44 | #include "clang/AST/TypeLoc.h" | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 45 | #include "clang/AST/TypeVisitor.h" | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 46 | #include "clang/AST/UnresolvedSet.h" | 
| Raphael Isemann | ba7bde6 | 2019-10-30 14:50:35 +0100 | [diff] [blame] | 47 | #include "clang/Basic/Builtins.h" | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 48 | #include "clang/Basic/ExceptionSpecificationType.h" | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 49 | #include "clang/Basic/FileManager.h" | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 50 | #include "clang/Basic/IdentifierTable.h" | 
|  | 51 | #include "clang/Basic/LLVM.h" | 
|  | 52 | #include "clang/Basic/LangOptions.h" | 
|  | 53 | #include "clang/Basic/SourceLocation.h" | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 54 | #include "clang/Basic/SourceManager.h" | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 55 | #include "clang/Basic/Specifiers.h" | 
|  | 56 | #include "llvm/ADT/APSInt.h" | 
|  | 57 | #include "llvm/ADT/ArrayRef.h" | 
|  | 58 | #include "llvm/ADT/DenseMap.h" | 
|  | 59 | #include "llvm/ADT/None.h" | 
|  | 60 | #include "llvm/ADT/Optional.h" | 
| Balazs Keri | d2c5761 | 2019-07-18 15:23:10 +0000 | [diff] [blame] | 61 | #include "llvm/ADT/ScopeExit.h" | 
| Ilya Biryukov | abc744d | 2019-07-18 15:43:26 +0000 | [diff] [blame] | 62 | #include "llvm/ADT/STLExtras.h" | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 63 | #include "llvm/ADT/SmallVector.h" | 
|  | 64 | #include "llvm/Support/Casting.h" | 
|  | 65 | #include "llvm/Support/ErrorHandling.h" | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 66 | #include "llvm/Support/MemoryBuffer.h" | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 67 | #include <algorithm> | 
|  | 68 | #include <cassert> | 
|  | 69 | #include <cstddef> | 
|  | 70 | #include <memory> | 
|  | 71 | #include <type_traits> | 
|  | 72 | #include <utility> | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 73 |  | 
| Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 74 | namespace clang { | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 75 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 76 | using llvm::make_error; | 
|  | 77 | using llvm::Error; | 
|  | 78 | using llvm::Expected; | 
|  | 79 | using ExpectedType = llvm::Expected<QualType>; | 
|  | 80 | using ExpectedStmt = llvm::Expected<Stmt *>; | 
|  | 81 | using ExpectedExpr = llvm::Expected<Expr *>; | 
|  | 82 | using ExpectedDecl = llvm::Expected<Decl *>; | 
|  | 83 | using ExpectedSLoc = llvm::Expected<SourceLocation>; | 
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 84 | using ExpectedName = llvm::Expected<DeclarationName>; | 
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 85 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 86 | std::string ImportError::toString() const { | 
|  | 87 | // FIXME: Improve error texts. | 
|  | 88 | switch (Error) { | 
|  | 89 | case NameConflict: | 
|  | 90 | return "NameConflict"; | 
|  | 91 | case UnsupportedConstruct: | 
|  | 92 | return "UnsupportedConstruct"; | 
|  | 93 | case Unknown: | 
|  | 94 | return "Unknown error"; | 
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 95 | } | 
| Balazs Keri | 2a13d66 | 2018-10-19 15:16:51 +0000 | [diff] [blame] | 96 | llvm_unreachable("Invalid error code."); | 
|  | 97 | return "Invalid error code."; | 
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 98 | } | 
|  | 99 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 100 | void ImportError::log(raw_ostream &OS) const { | 
|  | 101 | OS << toString(); | 
|  | 102 | } | 
|  | 103 |  | 
|  | 104 | std::error_code ImportError::convertToErrorCode() const { | 
|  | 105 | llvm_unreachable("Function not implemented."); | 
|  | 106 | } | 
|  | 107 |  | 
|  | 108 | char ImportError::ID; | 
|  | 109 |  | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 110 | template <class T> | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 111 | SmallVector<Decl *, 2> | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 112 | getCanonicalForwardRedeclChain(Redeclarable<T>* D) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 113 | SmallVector<Decl *, 2> Redecls; | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 114 | for (auto *R : D->getFirstDecl()->redecls()) { | 
|  | 115 | if (R != D->getFirstDecl()) | 
|  | 116 | Redecls.push_back(R); | 
|  | 117 | } | 
|  | 118 | Redecls.push_back(D->getFirstDecl()); | 
|  | 119 | std::reverse(Redecls.begin(), Redecls.end()); | 
|  | 120 | return Redecls; | 
|  | 121 | } | 
|  | 122 |  | 
|  | 123 | SmallVector<Decl*, 2> getCanonicalForwardRedeclChain(Decl* D) { | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 124 | if (auto *FD = dyn_cast<FunctionDecl>(D)) | 
|  | 125 | return getCanonicalForwardRedeclChain<FunctionDecl>(FD); | 
|  | 126 | if (auto *VD = dyn_cast<VarDecl>(D)) | 
|  | 127 | return getCanonicalForwardRedeclChain<VarDecl>(VD); | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 128 | if (auto *TD = dyn_cast<TagDecl>(D)) | 
|  | 129 | return getCanonicalForwardRedeclChain<TagDecl>(TD); | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 130 | llvm_unreachable("Bad declaration kind"); | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 131 | } | 
|  | 132 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 133 | void updateFlags(const Decl *From, Decl *To) { | 
|  | 134 | // Check if some flags or attrs are new in 'From' and copy into 'To'. | 
|  | 135 | // FIXME: Other flags or attrs? | 
|  | 136 | if (From->isUsed(false) && !To->isUsed(false)) | 
|  | 137 | To->setIsUsed(); | 
|  | 138 | } | 
|  | 139 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 140 | class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>, | 
|  | 141 | public DeclVisitor<ASTNodeImporter, ExpectedDecl>, | 
|  | 142 | public StmtVisitor<ASTNodeImporter, ExpectedStmt> { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 143 | ASTImporter &Importer; | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 144 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 145 | // Use this instead of Importer.importInto . | 
|  | 146 | template <typename ImportT> | 
|  | 147 | LLVM_NODISCARD Error importInto(ImportT &To, const ImportT &From) { | 
|  | 148 | return Importer.importInto(To, From); | 
|  | 149 | } | 
|  | 150 |  | 
|  | 151 | // Use this to import pointers of specific type. | 
|  | 152 | template <typename ImportT> | 
|  | 153 | LLVM_NODISCARD Error importInto(ImportT *&To, ImportT *From) { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 154 | auto ToOrErr = Importer.Import(From); | 
| Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 155 | if (ToOrErr) | 
|  | 156 | To = cast_or_null<ImportT>(*ToOrErr); | 
|  | 157 | return ToOrErr.takeError(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 158 | } | 
|  | 159 |  | 
|  | 160 | // Call the import function of ASTImporter for a baseclass of type `T` and | 
|  | 161 | // cast the return value to `T`. | 
|  | 162 | template <typename T> | 
|  | 163 | Expected<T *> import(T *From) { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 164 | auto ToOrErr = Importer.Import(From); | 
| Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 165 | if (!ToOrErr) | 
|  | 166 | return ToOrErr.takeError(); | 
|  | 167 | return cast_or_null<T>(*ToOrErr); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 168 | } | 
|  | 169 |  | 
|  | 170 | template <typename T> | 
|  | 171 | Expected<T *> import(const T *From) { | 
|  | 172 | return import(const_cast<T *>(From)); | 
|  | 173 | } | 
|  | 174 |  | 
|  | 175 | // Call the import function of ASTImporter for type `T`. | 
|  | 176 | template <typename T> | 
|  | 177 | Expected<T> import(const T &From) { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 178 | return Importer.Import(From); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 179 | } | 
|  | 180 |  | 
| Richard Smith | b9fb121 | 2019-05-06 03:47:15 +0000 | [diff] [blame] | 181 | // Import an Optional<T> by importing the contained T, if any. | 
|  | 182 | template<typename T> | 
|  | 183 | Expected<Optional<T>> import(Optional<T> From) { | 
|  | 184 | if (!From) | 
|  | 185 | return Optional<T>(); | 
|  | 186 | return import(*From); | 
|  | 187 | } | 
|  | 188 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 189 | template <class T> | 
|  | 190 | Expected<std::tuple<T>> | 
|  | 191 | importSeq(const T &From) { | 
|  | 192 | Expected<T> ToOrErr = import(From); | 
|  | 193 | if (!ToOrErr) | 
|  | 194 | return ToOrErr.takeError(); | 
|  | 195 | return std::make_tuple<T>(std::move(*ToOrErr)); | 
|  | 196 | } | 
|  | 197 |  | 
|  | 198 | // Import multiple objects with a single function call. | 
|  | 199 | // This should work for every type for which a variant of `import` exists. | 
|  | 200 | // The arguments are processed from left to right and import is stopped on | 
|  | 201 | // first error. | 
|  | 202 | template <class THead, class... TTail> | 
|  | 203 | Expected<std::tuple<THead, TTail...>> | 
|  | 204 | importSeq(const THead &FromHead, const TTail &...FromTail) { | 
|  | 205 | Expected<std::tuple<THead>> ToHeadOrErr = importSeq(FromHead); | 
|  | 206 | if (!ToHeadOrErr) | 
|  | 207 | return ToHeadOrErr.takeError(); | 
|  | 208 | Expected<std::tuple<TTail...>> ToTailOrErr = importSeq(FromTail...); | 
|  | 209 | if (!ToTailOrErr) | 
|  | 210 | return ToTailOrErr.takeError(); | 
|  | 211 | return std::tuple_cat(*ToHeadOrErr, *ToTailOrErr); | 
|  | 212 | } | 
|  | 213 |  | 
|  | 214 | // Wrapper for an overload set. | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 215 | template <typename ToDeclT> struct CallOverloadedCreateFun { | 
|  | 216 | template <typename... Args> | 
|  | 217 | auto operator()(Args &&... args) | 
|  | 218 | -> decltype(ToDeclT::Create(std::forward<Args>(args)...)) { | 
|  | 219 | return ToDeclT::Create(std::forward<Args>(args)...); | 
|  | 220 | } | 
|  | 221 | }; | 
|  | 222 |  | 
|  | 223 | // Always use these functions to create a Decl during import. There are | 
|  | 224 | // certain tasks which must be done after the Decl was created, e.g. we | 
|  | 225 | // must immediately register that as an imported Decl.  The parameter `ToD` | 
|  | 226 | // will be set to the newly created Decl or if had been imported before | 
|  | 227 | // then to the already imported Decl.  Returns a bool value set to true if | 
|  | 228 | // the `FromD` had been imported before. | 
|  | 229 | template <typename ToDeclT, typename FromDeclT, typename... Args> | 
|  | 230 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, | 
|  | 231 | Args &&... args) { | 
|  | 232 | // There may be several overloads of ToDeclT::Create. We must make sure | 
|  | 233 | // to call the one which would be chosen by the arguments, thus we use a | 
|  | 234 | // wrapper for the overload set. | 
|  | 235 | CallOverloadedCreateFun<ToDeclT> OC; | 
|  | 236 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, | 
|  | 237 | std::forward<Args>(args)...); | 
|  | 238 | } | 
|  | 239 | // Use this overload if a special Type is needed to be created.  E.g if we | 
|  | 240 | // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl` | 
|  | 241 | // then: | 
|  | 242 | // TypedefNameDecl *ToTypedef; | 
|  | 243 | // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...); | 
|  | 244 | template <typename NewDeclT, typename ToDeclT, typename FromDeclT, | 
|  | 245 | typename... Args> | 
|  | 246 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, | 
|  | 247 | Args &&... args) { | 
|  | 248 | CallOverloadedCreateFun<NewDeclT> OC; | 
|  | 249 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, | 
|  | 250 | std::forward<Args>(args)...); | 
|  | 251 | } | 
|  | 252 | // Use this version if a special create function must be | 
|  | 253 | // used, e.g. CXXRecordDecl::CreateLambda . | 
|  | 254 | template <typename ToDeclT, typename CreateFunT, typename FromDeclT, | 
|  | 255 | typename... Args> | 
|  | 256 | LLVM_NODISCARD bool | 
|  | 257 | GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun, | 
|  | 258 | FromDeclT *FromD, Args &&... args) { | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 259 | if (Importer.getImportDeclErrorIfAny(FromD)) { | 
|  | 260 | ToD = nullptr; | 
|  | 261 | return true; // Already imported but with error. | 
|  | 262 | } | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 263 | ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD)); | 
|  | 264 | if (ToD) | 
|  | 265 | return true; // Already imported. | 
|  | 266 | ToD = CreateFun(std::forward<Args>(args)...); | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 267 | // Keep track of imported Decls. | 
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 268 | Importer.RegisterImportedDecl(FromD, ToD); | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 269 | InitializeImportedDecl(FromD, ToD); | 
|  | 270 | return false; // A new Decl is created. | 
|  | 271 | } | 
|  | 272 |  | 
|  | 273 | void InitializeImportedDecl(Decl *FromD, Decl *ToD) { | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 274 | ToD->IdentifierNamespace = FromD->IdentifierNamespace; | 
|  | 275 | if (FromD->hasAttrs()) | 
| Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 276 | for (const Attr *FromAttr : FromD->getAttrs()) { | 
|  | 277 | // FIXME: Return of the error here is not possible until store of | 
|  | 278 | // import errors is implemented. | 
|  | 279 | auto ToAttrOrErr = import(FromAttr); | 
|  | 280 | if (ToAttrOrErr) | 
|  | 281 | ToD->addAttr(*ToAttrOrErr); | 
|  | 282 | else | 
|  | 283 | llvm::consumeError(ToAttrOrErr.takeError()); | 
|  | 284 | } | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 285 | if (FromD->isUsed()) | 
|  | 286 | ToD->setIsUsed(); | 
|  | 287 | if (FromD->isImplicit()) | 
|  | 288 | ToD->setImplicit(); | 
|  | 289 | } | 
|  | 290 |  | 
| Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 291 | // Check if we have found an existing definition.  Returns with that | 
|  | 292 | // definition if yes, otherwise returns null. | 
|  | 293 | Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) { | 
|  | 294 | const FunctionDecl *Definition = nullptr; | 
|  | 295 | if (D->doesThisDeclarationHaveABody() && | 
|  | 296 | FoundFunction->hasBody(Definition)) | 
|  | 297 | return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition)); | 
|  | 298 | return nullptr; | 
|  | 299 | } | 
|  | 300 |  | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 301 | public: | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 302 | explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {} | 
| Gabor Marton | 344b099 | 2018-05-16 11:48:11 +0000 | [diff] [blame] | 303 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 304 | using TypeVisitor<ASTNodeImporter, ExpectedType>::Visit; | 
|  | 305 | using DeclVisitor<ASTNodeImporter, ExpectedDecl>::Visit; | 
|  | 306 | using StmtVisitor<ASTNodeImporter, ExpectedStmt>::Visit; | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 307 |  | 
|  | 308 | // Importing types | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 309 | ExpectedType VisitType(const Type *T); | 
|  | 310 | ExpectedType VisitAtomicType(const AtomicType *T); | 
|  | 311 | ExpectedType VisitBuiltinType(const BuiltinType *T); | 
|  | 312 | ExpectedType VisitDecayedType(const DecayedType *T); | 
|  | 313 | ExpectedType VisitComplexType(const ComplexType *T); | 
|  | 314 | ExpectedType VisitPointerType(const PointerType *T); | 
|  | 315 | ExpectedType VisitBlockPointerType(const BlockPointerType *T); | 
|  | 316 | ExpectedType VisitLValueReferenceType(const LValueReferenceType *T); | 
|  | 317 | ExpectedType VisitRValueReferenceType(const RValueReferenceType *T); | 
|  | 318 | ExpectedType VisitMemberPointerType(const MemberPointerType *T); | 
|  | 319 | ExpectedType VisitConstantArrayType(const ConstantArrayType *T); | 
|  | 320 | ExpectedType VisitIncompleteArrayType(const IncompleteArrayType *T); | 
|  | 321 | ExpectedType VisitVariableArrayType(const VariableArrayType *T); | 
|  | 322 | ExpectedType VisitDependentSizedArrayType(const DependentSizedArrayType *T); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 323 | // FIXME: DependentSizedExtVectorType | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 324 | ExpectedType VisitVectorType(const VectorType *T); | 
|  | 325 | ExpectedType VisitExtVectorType(const ExtVectorType *T); | 
|  | 326 | ExpectedType VisitFunctionNoProtoType(const FunctionNoProtoType *T); | 
|  | 327 | ExpectedType VisitFunctionProtoType(const FunctionProtoType *T); | 
|  | 328 | ExpectedType VisitUnresolvedUsingType(const UnresolvedUsingType *T); | 
|  | 329 | ExpectedType VisitParenType(const ParenType *T); | 
|  | 330 | ExpectedType VisitTypedefType(const TypedefType *T); | 
|  | 331 | ExpectedType VisitTypeOfExprType(const TypeOfExprType *T); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 332 | // FIXME: DependentTypeOfExprType | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 333 | ExpectedType VisitTypeOfType(const TypeOfType *T); | 
|  | 334 | ExpectedType VisitDecltypeType(const DecltypeType *T); | 
|  | 335 | ExpectedType VisitUnaryTransformType(const UnaryTransformType *T); | 
|  | 336 | ExpectedType VisitAutoType(const AutoType *T); | 
|  | 337 | ExpectedType VisitInjectedClassNameType(const InjectedClassNameType *T); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 338 | // FIXME: DependentDecltypeType | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 339 | ExpectedType VisitRecordType(const RecordType *T); | 
|  | 340 | ExpectedType VisitEnumType(const EnumType *T); | 
|  | 341 | ExpectedType VisitAttributedType(const AttributedType *T); | 
|  | 342 | ExpectedType VisitTemplateTypeParmType(const TemplateTypeParmType *T); | 
|  | 343 | ExpectedType VisitSubstTemplateTypeParmType( | 
|  | 344 | const SubstTemplateTypeParmType *T); | 
|  | 345 | ExpectedType VisitTemplateSpecializationType( | 
|  | 346 | const TemplateSpecializationType *T); | 
|  | 347 | ExpectedType VisitElaboratedType(const ElaboratedType *T); | 
|  | 348 | ExpectedType VisitDependentNameType(const DependentNameType *T); | 
|  | 349 | ExpectedType VisitPackExpansionType(const PackExpansionType *T); | 
|  | 350 | ExpectedType VisitDependentTemplateSpecializationType( | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 351 | const DependentTemplateSpecializationType *T); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 352 | ExpectedType VisitObjCInterfaceType(const ObjCInterfaceType *T); | 
|  | 353 | ExpectedType VisitObjCObjectType(const ObjCObjectType *T); | 
|  | 354 | ExpectedType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); | 
| Rafael Stahl | df55620 | 2018-05-29 08:12:15 +0000 | [diff] [blame] | 355 |  | 
|  | 356 | // Importing declarations | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 357 | Error ImportDeclParts( | 
|  | 358 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, | 
|  | 359 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc); | 
|  | 360 | Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr); | 
|  | 361 | Error ImportDeclarationNameLoc( | 
|  | 362 | const DeclarationNameInfo &From, DeclarationNameInfo &To); | 
|  | 363 | Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); | 
|  | 364 | Error ImportDeclContext( | 
|  | 365 | Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC); | 
|  | 366 | Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 367 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 368 | Expected<CXXCastPath> ImportCastPath(CastExpr *E); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 369 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 370 | using Designator = DesignatedInitExpr::Designator; | 
|  | 371 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 372 | /// What we should import from the definition. | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 373 | enum ImportDefinitionKind { | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 374 | /// Import the default subset of the definition, which might be | 
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 375 | /// nothing (if minimal import is set) or might be everything (if minimal | 
|  | 376 | /// import is not set). | 
|  | 377 | IDK_Default, | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 378 | /// Import everything. | 
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 379 | IDK_Everything, | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 380 | /// Import only the bare bones needed to establish a valid | 
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 381 | /// DeclContext. | 
|  | 382 | IDK_Basic | 
|  | 383 | }; | 
|  | 384 |  | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 385 | bool shouldForceImportDeclContext(ImportDefinitionKind IDK) { | 
|  | 386 | return IDK == IDK_Everything || | 
|  | 387 | (IDK == IDK_Default && !Importer.isMinimalImport()); | 
|  | 388 | } | 
|  | 389 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 390 | Error ImportInitializer(VarDecl *From, VarDecl *To); | 
|  | 391 | Error ImportDefinition( | 
|  | 392 | RecordDecl *From, RecordDecl *To, | 
|  | 393 | ImportDefinitionKind Kind = IDK_Default); | 
|  | 394 | Error ImportDefinition( | 
|  | 395 | EnumDecl *From, EnumDecl *To, | 
|  | 396 | ImportDefinitionKind Kind = IDK_Default); | 
|  | 397 | Error ImportDefinition( | 
|  | 398 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, | 
|  | 399 | ImportDefinitionKind Kind = IDK_Default); | 
|  | 400 | Error ImportDefinition( | 
|  | 401 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, | 
|  | 402 | ImportDefinitionKind Kind = IDK_Default); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 403 | Error ImportTemplateArguments( | 
|  | 404 | const TemplateArgument *FromArgs, unsigned NumFromArgs, | 
|  | 405 | SmallVectorImpl<TemplateArgument> &ToArgs); | 
|  | 406 | Expected<TemplateArgument> | 
|  | 407 | ImportTemplateArgument(const TemplateArgument &From); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 408 |  | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 409 | template <typename InContainerTy> | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 410 | Error ImportTemplateArgumentListInfo( | 
|  | 411 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 412 |  | 
|  | 413 | template<typename InContainerTy> | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 414 | Error ImportTemplateArgumentListInfo( | 
|  | 415 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, | 
|  | 416 | const InContainerTy &Container, TemplateArgumentListInfo &Result); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 417 |  | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 418 | using TemplateArgsTy = SmallVector<TemplateArgument, 8>; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 419 | using FunctionTemplateAndArgsTy = | 
|  | 420 | std::tuple<FunctionTemplateDecl *, TemplateArgsTy>; | 
|  | 421 | Expected<FunctionTemplateAndArgsTy> | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 422 | ImportFunctionTemplateWithTemplateArgsFromSpecialization( | 
|  | 423 | FunctionDecl *FromFD); | 
| Balazs Keri | 1efc974 | 2019-05-07 10:55:11 +0000 | [diff] [blame] | 424 | Error ImportTemplateParameterLists(const DeclaratorDecl *FromD, | 
|  | 425 | DeclaratorDecl *ToD); | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 426 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 427 | Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 428 |  | 
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 429 | Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD); | 
|  | 430 |  | 
| Balazs Keri | c509594 | 2019-08-14 09:41:39 +0000 | [diff] [blame] | 431 | Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam, | 
|  | 432 | ParmVarDecl *ToParam); | 
|  | 433 |  | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 434 | template <typename T> | 
|  | 435 | bool hasSameVisibilityContext(T *Found, T *From); | 
|  | 436 |  | 
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 437 | bool IsStructuralMatch(Decl *From, Decl *To, bool Complain); | 
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 438 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, | 
|  | 439 | bool Complain = true); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 440 | bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, | 
|  | 441 | bool Complain = true); | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 442 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); | 
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 443 | bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 444 | bool IsStructuralMatch(FunctionTemplateDecl *From, | 
|  | 445 | FunctionTemplateDecl *To); | 
| Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 446 | bool IsStructuralMatch(FunctionDecl *From, FunctionDecl *To); | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 447 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 448 | bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 449 | ExpectedDecl VisitDecl(Decl *D); | 
|  | 450 | ExpectedDecl VisitImportDecl(ImportDecl *D); | 
|  | 451 | ExpectedDecl VisitEmptyDecl(EmptyDecl *D); | 
|  | 452 | ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D); | 
|  | 453 | ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D); | 
|  | 454 | ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D); | 
|  | 455 | ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D); | 
|  | 456 | ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D); | 
|  | 457 | ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); | 
|  | 458 | ExpectedDecl VisitTypedefDecl(TypedefDecl *D); | 
|  | 459 | ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D); | 
|  | 460 | ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); | 
|  | 461 | ExpectedDecl VisitLabelDecl(LabelDecl *D); | 
|  | 462 | ExpectedDecl VisitEnumDecl(EnumDecl *D); | 
|  | 463 | ExpectedDecl VisitRecordDecl(RecordDecl *D); | 
|  | 464 | ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D); | 
|  | 465 | ExpectedDecl VisitFunctionDecl(FunctionDecl *D); | 
|  | 466 | ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D); | 
|  | 467 | ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D); | 
|  | 468 | ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D); | 
|  | 469 | ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D); | 
|  | 470 | ExpectedDecl VisitFieldDecl(FieldDecl *D); | 
|  | 471 | ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D); | 
|  | 472 | ExpectedDecl VisitFriendDecl(FriendDecl *D); | 
|  | 473 | ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D); | 
|  | 474 | ExpectedDecl VisitVarDecl(VarDecl *D); | 
|  | 475 | ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D); | 
|  | 476 | ExpectedDecl VisitParmVarDecl(ParmVarDecl *D); | 
|  | 477 | ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D); | 
|  | 478 | ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); | 
|  | 479 | ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D); | 
|  | 480 | ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D); | 
|  | 481 | ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D); | 
|  | 482 | ExpectedDecl VisitUsingDecl(UsingDecl *D); | 
|  | 483 | ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D); | 
|  | 484 | ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D); | 
|  | 485 | ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); | 
|  | 486 | ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); | 
| Raphael Isemann | ba7bde6 | 2019-10-30 14:50:35 +0100 | [diff] [blame] | 487 | ExpectedDecl VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 488 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 489 | Expected<ObjCTypeParamList *> | 
|  | 490 | ImportObjCTypeParamList(ObjCTypeParamList *list); | 
|  | 491 |  | 
|  | 492 | ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); | 
|  | 493 | ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); | 
|  | 494 | ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D); | 
|  | 495 | ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D); | 
|  | 496 | ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); | 
|  | 497 | ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); | 
|  | 498 | ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); | 
|  | 499 | ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); | 
|  | 500 | ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D); | 
|  | 501 | ExpectedDecl VisitClassTemplateSpecializationDecl( | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 502 | ClassTemplateSpecializationDecl *D); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 503 | ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D); | 
|  | 504 | ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); | 
|  | 505 | ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 506 |  | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 507 | // Importing statements | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 508 | ExpectedStmt VisitStmt(Stmt *S); | 
|  | 509 | ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S); | 
|  | 510 | ExpectedStmt VisitDeclStmt(DeclStmt *S); | 
|  | 511 | ExpectedStmt VisitNullStmt(NullStmt *S); | 
|  | 512 | ExpectedStmt VisitCompoundStmt(CompoundStmt *S); | 
|  | 513 | ExpectedStmt VisitCaseStmt(CaseStmt *S); | 
|  | 514 | ExpectedStmt VisitDefaultStmt(DefaultStmt *S); | 
|  | 515 | ExpectedStmt VisitLabelStmt(LabelStmt *S); | 
|  | 516 | ExpectedStmt VisitAttributedStmt(AttributedStmt *S); | 
|  | 517 | ExpectedStmt VisitIfStmt(IfStmt *S); | 
|  | 518 | ExpectedStmt VisitSwitchStmt(SwitchStmt *S); | 
|  | 519 | ExpectedStmt VisitWhileStmt(WhileStmt *S); | 
|  | 520 | ExpectedStmt VisitDoStmt(DoStmt *S); | 
|  | 521 | ExpectedStmt VisitForStmt(ForStmt *S); | 
|  | 522 | ExpectedStmt VisitGotoStmt(GotoStmt *S); | 
|  | 523 | ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S); | 
|  | 524 | ExpectedStmt VisitContinueStmt(ContinueStmt *S); | 
|  | 525 | ExpectedStmt VisitBreakStmt(BreakStmt *S); | 
|  | 526 | ExpectedStmt VisitReturnStmt(ReturnStmt *S); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 527 | // FIXME: MSAsmStmt | 
|  | 528 | // FIXME: SEHExceptStmt | 
|  | 529 | // FIXME: SEHFinallyStmt | 
|  | 530 | // FIXME: SEHTryStmt | 
|  | 531 | // FIXME: SEHLeaveStmt | 
|  | 532 | // FIXME: CapturedStmt | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 533 | ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S); | 
|  | 534 | ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S); | 
|  | 535 | ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 536 | // FIXME: MSDependentExistsStmt | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 537 | ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); | 
|  | 538 | ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); | 
|  | 539 | ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); | 
|  | 540 | ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S); | 
|  | 541 | ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); | 
|  | 542 | ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); | 
|  | 543 | ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 544 |  | 
|  | 545 | // Importing expressions | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 546 | ExpectedStmt VisitExpr(Expr *E); | 
|  | 547 | ExpectedStmt VisitVAArgExpr(VAArgExpr *E); | 
| Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 548 | ExpectedStmt VisitChooseExpr(ChooseExpr *E); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 549 | ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E); | 
|  | 550 | ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E); | 
|  | 551 | ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E); | 
|  | 552 | ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E); | 
|  | 553 | ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E); | 
|  | 554 | ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); | 
|  | 555 | ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E); | 
|  | 556 | ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E); | 
|  | 557 | ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E); | 
|  | 558 | ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E); | 
|  | 559 | ExpectedStmt VisitStringLiteral(StringLiteral *E); | 
|  | 560 | ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E); | 
|  | 561 | ExpectedStmt VisitAtomicExpr(AtomicExpr *E); | 
|  | 562 | ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E); | 
| Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 563 | ExpectedStmt VisitConstantExpr(ConstantExpr *E); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 564 | ExpectedStmt VisitParenExpr(ParenExpr *E); | 
|  | 565 | ExpectedStmt VisitParenListExpr(ParenListExpr *E); | 
|  | 566 | ExpectedStmt VisitStmtExpr(StmtExpr *E); | 
|  | 567 | ExpectedStmt VisitUnaryOperator(UnaryOperator *E); | 
|  | 568 | ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); | 
|  | 569 | ExpectedStmt VisitBinaryOperator(BinaryOperator *E); | 
|  | 570 | ExpectedStmt VisitConditionalOperator(ConditionalOperator *E); | 
|  | 571 | ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E); | 
|  | 572 | ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E); | 
|  | 573 | ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); | 
|  | 574 | ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E); | 
|  | 575 | ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E); | 
|  | 576 | ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E); | 
|  | 577 | ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E); | 
|  | 578 | ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E); | 
|  | 579 | ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE); | 
|  | 580 | ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E); | 
|  | 581 | ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E); | 
|  | 582 | ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); | 
|  | 583 | ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); | 
|  | 584 | ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); | 
|  | 585 | ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E); | 
|  | 586 | ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); | 
|  | 587 | ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E); | 
|  | 588 | ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E); | 
|  | 589 | ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E); | 
|  | 590 | ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E); | 
|  | 591 | ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E); | 
|  | 592 | ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E); | 
|  | 593 | ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); | 
|  | 594 | ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E); | 
|  | 595 | ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E); | 
|  | 596 | ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); | 
|  | 597 | ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E); | 
|  | 598 | ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E); | 
|  | 599 | ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E); | 
|  | 600 | ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); | 
|  | 601 | ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); | 
|  | 602 | ExpectedStmt VisitMemberExpr(MemberExpr *E); | 
|  | 603 | ExpectedStmt VisitCallExpr(CallExpr *E); | 
|  | 604 | ExpectedStmt VisitLambdaExpr(LambdaExpr *LE); | 
|  | 605 | ExpectedStmt VisitInitListExpr(InitListExpr *E); | 
|  | 606 | ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E); | 
|  | 607 | ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E); | 
|  | 608 | ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); | 
|  | 609 | ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); | 
|  | 610 | ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); | 
|  | 611 | ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E); | 
|  | 612 | ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); | 
|  | 613 | ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E); | 
|  | 614 | ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 615 |  | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 616 | template<typename IIter, typename OIter> | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 617 | Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 618 | using ItemT = typename std::remove_reference<decltype(*Obegin)>::type; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 619 | for (; Ibegin != Iend; ++Ibegin, ++Obegin) { | 
|  | 620 | Expected<ItemT> ToOrErr = import(*Ibegin); | 
|  | 621 | if (!ToOrErr) | 
|  | 622 | return ToOrErr.takeError(); | 
|  | 623 | *Obegin = *ToOrErr; | 
|  | 624 | } | 
|  | 625 | return Error::success(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 626 | } | 
|  | 627 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 628 | // Import every item from a container structure into an output container. | 
|  | 629 | // If error occurs, stops at first error and returns the error. | 
|  | 630 | // The output container should have space for all needed elements (it is not | 
|  | 631 | // expanded, new items are put into from the beginning). | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 632 | template<typename InContainerTy, typename OutContainerTy> | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 633 | Error ImportContainerChecked( | 
|  | 634 | const InContainerTy &InContainer, OutContainerTy &OutContainer) { | 
|  | 635 | return ImportArrayChecked( | 
|  | 636 | InContainer.begin(), InContainer.end(), OutContainer.begin()); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 637 | } | 
|  | 638 |  | 
|  | 639 | template<typename InContainerTy, typename OIter> | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 640 | Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 641 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); | 
|  | 642 | } | 
| Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 643 |  | 
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 644 | Error ImportOverriddenMethods(CXXMethodDecl *ToMethod, | 
|  | 645 | CXXMethodDecl *FromMethod); | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 646 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 647 | Expected<FunctionDecl *> FindFunctionTemplateSpecialization( | 
|  | 648 | FunctionDecl *FromFD); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 649 | }; | 
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 650 |  | 
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 651 | template <typename InContainerTy> | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 652 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( | 
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 653 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, | 
|  | 654 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 655 | auto ToLAngleLocOrErr = import(FromLAngleLoc); | 
|  | 656 | if (!ToLAngleLocOrErr) | 
|  | 657 | return ToLAngleLocOrErr.takeError(); | 
|  | 658 | auto ToRAngleLocOrErr = import(FromRAngleLoc); | 
|  | 659 | if (!ToRAngleLocOrErr) | 
|  | 660 | return ToRAngleLocOrErr.takeError(); | 
|  | 661 |  | 
|  | 662 | TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr); | 
|  | 663 | if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo)) | 
|  | 664 | return Err; | 
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 665 | Result = ToTAInfo; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 666 | return Error::success(); | 
| Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 667 | } | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 668 |  | 
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 669 | template <> | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 670 | Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( | 
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 671 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { | 
|  | 672 | return ImportTemplateArgumentListInfo( | 
|  | 673 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); | 
|  | 674 | } | 
|  | 675 |  | 
|  | 676 | template <> | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 677 | Error ASTNodeImporter::ImportTemplateArgumentListInfo< | 
|  | 678 | ASTTemplateArgumentListInfo>( | 
|  | 679 | const ASTTemplateArgumentListInfo &From, | 
|  | 680 | TemplateArgumentListInfo &Result) { | 
|  | 681 | return ImportTemplateArgumentListInfo( | 
|  | 682 | From.LAngleLoc, From.RAngleLoc, From.arguments(), Result); | 
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 683 | } | 
|  | 684 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 685 | Expected<ASTNodeImporter::FunctionTemplateAndArgsTy> | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 686 | ASTNodeImporter::ImportFunctionTemplateWithTemplateArgsFromSpecialization( | 
|  | 687 | FunctionDecl *FromFD) { | 
|  | 688 | assert(FromFD->getTemplatedKind() == | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 689 | FunctionDecl::TK_FunctionTemplateSpecialization); | 
|  | 690 |  | 
|  | 691 | FunctionTemplateAndArgsTy Result; | 
|  | 692 |  | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 693 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 694 | if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate())) | 
|  | 695 | return std::move(Err); | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 696 |  | 
|  | 697 | // Import template arguments. | 
|  | 698 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 699 | if (Error Err = ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), | 
|  | 700 | std::get<1>(Result))) | 
|  | 701 | return std::move(Err); | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 702 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 703 | return Result; | 
|  | 704 | } | 
|  | 705 |  | 
|  | 706 | template <> | 
|  | 707 | Expected<TemplateParameterList *> | 
|  | 708 | ASTNodeImporter::import(TemplateParameterList *From) { | 
|  | 709 | SmallVector<NamedDecl *, 4> To(From->size()); | 
|  | 710 | if (Error Err = ImportContainerChecked(*From, To)) | 
|  | 711 | return std::move(Err); | 
|  | 712 |  | 
|  | 713 | ExpectedExpr ToRequiresClause = import(From->getRequiresClause()); | 
|  | 714 | if (!ToRequiresClause) | 
|  | 715 | return ToRequiresClause.takeError(); | 
|  | 716 |  | 
|  | 717 | auto ToTemplateLocOrErr = import(From->getTemplateLoc()); | 
|  | 718 | if (!ToTemplateLocOrErr) | 
|  | 719 | return ToTemplateLocOrErr.takeError(); | 
|  | 720 | auto ToLAngleLocOrErr = import(From->getLAngleLoc()); | 
|  | 721 | if (!ToLAngleLocOrErr) | 
|  | 722 | return ToLAngleLocOrErr.takeError(); | 
|  | 723 | auto ToRAngleLocOrErr = import(From->getRAngleLoc()); | 
|  | 724 | if (!ToRAngleLocOrErr) | 
|  | 725 | return ToRAngleLocOrErr.takeError(); | 
|  | 726 |  | 
|  | 727 | return TemplateParameterList::Create( | 
|  | 728 | Importer.getToContext(), | 
|  | 729 | *ToTemplateLocOrErr, | 
|  | 730 | *ToLAngleLocOrErr, | 
|  | 731 | To, | 
|  | 732 | *ToRAngleLocOrErr, | 
|  | 733 | *ToRequiresClause); | 
|  | 734 | } | 
|  | 735 |  | 
|  | 736 | template <> | 
|  | 737 | Expected<TemplateArgument> | 
|  | 738 | ASTNodeImporter::import(const TemplateArgument &From) { | 
|  | 739 | switch (From.getKind()) { | 
|  | 740 | case TemplateArgument::Null: | 
|  | 741 | return TemplateArgument(); | 
|  | 742 |  | 
|  | 743 | case TemplateArgument::Type: { | 
|  | 744 | ExpectedType ToTypeOrErr = import(From.getAsType()); | 
|  | 745 | if (!ToTypeOrErr) | 
|  | 746 | return ToTypeOrErr.takeError(); | 
|  | 747 | return TemplateArgument(*ToTypeOrErr); | 
|  | 748 | } | 
|  | 749 |  | 
|  | 750 | case TemplateArgument::Integral: { | 
|  | 751 | ExpectedType ToTypeOrErr = import(From.getIntegralType()); | 
|  | 752 | if (!ToTypeOrErr) | 
|  | 753 | return ToTypeOrErr.takeError(); | 
|  | 754 | return TemplateArgument(From, *ToTypeOrErr); | 
|  | 755 | } | 
|  | 756 |  | 
|  | 757 | case TemplateArgument::Declaration: { | 
|  | 758 | Expected<ValueDecl *> ToOrErr = import(From.getAsDecl()); | 
|  | 759 | if (!ToOrErr) | 
|  | 760 | return ToOrErr.takeError(); | 
|  | 761 | ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl()); | 
|  | 762 | if (!ToTypeOrErr) | 
|  | 763 | return ToTypeOrErr.takeError(); | 
|  | 764 | return TemplateArgument(*ToOrErr, *ToTypeOrErr); | 
|  | 765 | } | 
|  | 766 |  | 
|  | 767 | case TemplateArgument::NullPtr: { | 
|  | 768 | ExpectedType ToTypeOrErr = import(From.getNullPtrType()); | 
|  | 769 | if (!ToTypeOrErr) | 
|  | 770 | return ToTypeOrErr.takeError(); | 
|  | 771 | return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true); | 
|  | 772 | } | 
|  | 773 |  | 
|  | 774 | case TemplateArgument::Template: { | 
|  | 775 | Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate()); | 
|  | 776 | if (!ToTemplateOrErr) | 
|  | 777 | return ToTemplateOrErr.takeError(); | 
|  | 778 |  | 
|  | 779 | return TemplateArgument(*ToTemplateOrErr); | 
|  | 780 | } | 
|  | 781 |  | 
|  | 782 | case TemplateArgument::TemplateExpansion: { | 
|  | 783 | Expected<TemplateName> ToTemplateOrErr = | 
|  | 784 | import(From.getAsTemplateOrTemplatePattern()); | 
|  | 785 | if (!ToTemplateOrErr) | 
|  | 786 | return ToTemplateOrErr.takeError(); | 
|  | 787 |  | 
|  | 788 | return TemplateArgument( | 
|  | 789 | *ToTemplateOrErr, From.getNumTemplateExpansions()); | 
|  | 790 | } | 
|  | 791 |  | 
|  | 792 | case TemplateArgument::Expression: | 
|  | 793 | if (ExpectedExpr ToExpr = import(From.getAsExpr())) | 
|  | 794 | return TemplateArgument(*ToExpr); | 
|  | 795 | else | 
|  | 796 | return ToExpr.takeError(); | 
|  | 797 |  | 
|  | 798 | case TemplateArgument::Pack: { | 
|  | 799 | SmallVector<TemplateArgument, 2> ToPack; | 
|  | 800 | ToPack.reserve(From.pack_size()); | 
|  | 801 | if (Error Err = ImportTemplateArguments( | 
|  | 802 | From.pack_begin(), From.pack_size(), ToPack)) | 
|  | 803 | return std::move(Err); | 
|  | 804 |  | 
|  | 805 | return TemplateArgument( | 
|  | 806 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); | 
|  | 807 | } | 
|  | 808 | } | 
|  | 809 |  | 
|  | 810 | llvm_unreachable("Invalid template argument kind"); | 
|  | 811 | } | 
|  | 812 |  | 
|  | 813 | template <> | 
|  | 814 | Expected<TemplateArgumentLoc> | 
|  | 815 | ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) { | 
|  | 816 | Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument()); | 
|  | 817 | if (!ArgOrErr) | 
|  | 818 | return ArgOrErr.takeError(); | 
|  | 819 | TemplateArgument Arg = *ArgOrErr; | 
|  | 820 |  | 
|  | 821 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); | 
|  | 822 |  | 
|  | 823 | TemplateArgumentLocInfo ToInfo; | 
|  | 824 | if (Arg.getKind() == TemplateArgument::Expression) { | 
|  | 825 | ExpectedExpr E = import(FromInfo.getAsExpr()); | 
|  | 826 | if (!E) | 
|  | 827 | return E.takeError(); | 
|  | 828 | ToInfo = TemplateArgumentLocInfo(*E); | 
|  | 829 | } else if (Arg.getKind() == TemplateArgument::Type) { | 
|  | 830 | if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo())) | 
|  | 831 | ToInfo = TemplateArgumentLocInfo(*TSIOrErr); | 
|  | 832 | else | 
|  | 833 | return TSIOrErr.takeError(); | 
|  | 834 | } else { | 
|  | 835 | auto ToTemplateQualifierLocOrErr = | 
|  | 836 | import(FromInfo.getTemplateQualifierLoc()); | 
|  | 837 | if (!ToTemplateQualifierLocOrErr) | 
|  | 838 | return ToTemplateQualifierLocOrErr.takeError(); | 
|  | 839 | auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc()); | 
|  | 840 | if (!ToTemplateNameLocOrErr) | 
|  | 841 | return ToTemplateNameLocOrErr.takeError(); | 
|  | 842 | auto ToTemplateEllipsisLocOrErr = | 
|  | 843 | import(FromInfo.getTemplateEllipsisLoc()); | 
|  | 844 | if (!ToTemplateEllipsisLocOrErr) | 
|  | 845 | return ToTemplateEllipsisLocOrErr.takeError(); | 
|  | 846 |  | 
|  | 847 | ToInfo = TemplateArgumentLocInfo( | 
|  | 848 | *ToTemplateQualifierLocOrErr, | 
|  | 849 | *ToTemplateNameLocOrErr, | 
|  | 850 | *ToTemplateEllipsisLocOrErr); | 
|  | 851 | } | 
|  | 852 |  | 
|  | 853 | return TemplateArgumentLoc(Arg, ToInfo); | 
|  | 854 | } | 
|  | 855 |  | 
|  | 856 | template <> | 
|  | 857 | Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) { | 
|  | 858 | if (DG.isNull()) | 
|  | 859 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); | 
|  | 860 | size_t NumDecls = DG.end() - DG.begin(); | 
|  | 861 | SmallVector<Decl *, 1> ToDecls; | 
|  | 862 | ToDecls.reserve(NumDecls); | 
|  | 863 | for (Decl *FromD : DG) { | 
|  | 864 | if (auto ToDOrErr = import(FromD)) | 
|  | 865 | ToDecls.push_back(*ToDOrErr); | 
|  | 866 | else | 
|  | 867 | return ToDOrErr.takeError(); | 
|  | 868 | } | 
|  | 869 | return DeclGroupRef::Create(Importer.getToContext(), | 
|  | 870 | ToDecls.begin(), | 
|  | 871 | NumDecls); | 
|  | 872 | } | 
|  | 873 |  | 
|  | 874 | template <> | 
|  | 875 | Expected<ASTNodeImporter::Designator> | 
|  | 876 | ASTNodeImporter::import(const Designator &D) { | 
|  | 877 | if (D.isFieldDesignator()) { | 
|  | 878 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); | 
|  | 879 |  | 
|  | 880 | ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc()); | 
|  | 881 | if (!ToDotLocOrErr) | 
|  | 882 | return ToDotLocOrErr.takeError(); | 
|  | 883 |  | 
|  | 884 | ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc()); | 
|  | 885 | if (!ToFieldLocOrErr) | 
|  | 886 | return ToFieldLocOrErr.takeError(); | 
|  | 887 |  | 
|  | 888 | return Designator(ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr); | 
|  | 889 | } | 
|  | 890 |  | 
|  | 891 | ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc()); | 
|  | 892 | if (!ToLBracketLocOrErr) | 
|  | 893 | return ToLBracketLocOrErr.takeError(); | 
|  | 894 |  | 
|  | 895 | ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc()); | 
|  | 896 | if (!ToRBracketLocOrErr) | 
|  | 897 | return ToRBracketLocOrErr.takeError(); | 
|  | 898 |  | 
|  | 899 | if (D.isArrayDesignator()) | 
|  | 900 | return Designator(D.getFirstExprIndex(), | 
|  | 901 | *ToLBracketLocOrErr, *ToRBracketLocOrErr); | 
|  | 902 |  | 
|  | 903 | ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc()); | 
|  | 904 | if (!ToEllipsisLocOrErr) | 
|  | 905 | return ToEllipsisLocOrErr.takeError(); | 
|  | 906 |  | 
|  | 907 | assert(D.isArrayRangeDesignator()); | 
|  | 908 | return Designator( | 
|  | 909 | D.getFirstExprIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr, | 
|  | 910 | *ToRBracketLocOrErr); | 
|  | 911 | } | 
|  | 912 |  | 
|  | 913 | template <> | 
|  | 914 | Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) { | 
|  | 915 | VarDecl *Var = nullptr; | 
|  | 916 | if (From.capturesVariable()) { | 
|  | 917 | if (auto VarOrErr = import(From.getCapturedVar())) | 
|  | 918 | Var = *VarOrErr; | 
|  | 919 | else | 
|  | 920 | return VarOrErr.takeError(); | 
|  | 921 | } | 
|  | 922 |  | 
|  | 923 | auto LocationOrErr = import(From.getLocation()); | 
|  | 924 | if (!LocationOrErr) | 
|  | 925 | return LocationOrErr.takeError(); | 
|  | 926 |  | 
|  | 927 | SourceLocation EllipsisLoc; | 
|  | 928 | if (From.isPackExpansion()) | 
|  | 929 | if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc())) | 
|  | 930 | return std::move(Err); | 
|  | 931 |  | 
|  | 932 | return LambdaCapture( | 
|  | 933 | *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var, | 
|  | 934 | EllipsisLoc); | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 935 | } | 
|  | 936 |  | 
| Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 937 | template <typename T> | 
|  | 938 | bool ASTNodeImporter::hasSameVisibilityContext(T *Found, T *From) { | 
|  | 939 | if (From->hasExternalFormalLinkage()) | 
|  | 940 | return Found->hasExternalFormalLinkage(); | 
|  | 941 | if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl()) | 
|  | 942 | return false; | 
|  | 943 | if (From->isInAnonymousNamespace()) | 
|  | 944 | return Found->isInAnonymousNamespace(); | 
|  | 945 | else | 
|  | 946 | return !Found->isInAnonymousNamespace() && | 
|  | 947 | !Found->hasExternalFormalLinkage(); | 
|  | 948 | } | 
|  | 949 |  | 
|  | 950 | template <> | 
|  | 951 | bool ASTNodeImporter::hasSameVisibilityContext(TypedefNameDecl *Found, | 
|  | 952 | TypedefNameDecl *From) { | 
|  | 953 | if (From->isInAnonymousNamespace() && Found->isInAnonymousNamespace()) | 
|  | 954 | return Importer.GetFromTU(Found) == From->getTranslationUnitDecl(); | 
|  | 955 | return From->isInAnonymousNamespace() == Found->isInAnonymousNamespace(); | 
|  | 956 | } | 
|  | 957 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 958 | } // namespace clang | 
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 959 |  | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 960 | //---------------------------------------------------------------------------- | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 961 | // Import Types | 
|  | 962 | //---------------------------------------------------------------------------- | 
|  | 963 |  | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 964 | using namespace clang; | 
|  | 965 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 966 | ExpectedType ASTNodeImporter::VisitType(const Type *T) { | 
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 967 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) | 
|  | 968 | << T->getTypeClassName(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 969 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | 
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 970 | } | 
|  | 971 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 972 | ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ | 
|  | 973 | ExpectedType UnderlyingTypeOrErr = import(T->getValueType()); | 
|  | 974 | if (!UnderlyingTypeOrErr) | 
|  | 975 | return UnderlyingTypeOrErr.takeError(); | 
| Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 976 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 977 | return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr); | 
| Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 978 | } | 
|  | 979 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 980 | ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 981 | switch (T->getKind()) { | 
| Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 982 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ | 
|  | 983 | case BuiltinType::Id: \ | 
|  | 984 | return Importer.getToContext().SingletonId; | 
| Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 985 | #include "clang/Basic/OpenCLImageTypes.def" | 
| Andrew Savonichev | 3fee351 | 2018-11-08 11:25:41 +0000 | [diff] [blame] | 986 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ | 
|  | 987 | case BuiltinType::Id: \ | 
|  | 988 | return Importer.getToContext().Id##Ty; | 
|  | 989 | #include "clang/Basic/OpenCLExtensionTypes.def" | 
| Richard Sandiford | eb485fb | 2019-08-09 08:52:54 +0000 | [diff] [blame] | 990 | #define SVE_TYPE(Name, Id, SingletonId) \ | 
|  | 991 | case BuiltinType::Id: \ | 
|  | 992 | return Importer.getToContext().SingletonId; | 
|  | 993 | #include "clang/Basic/AArch64SVEACLETypes.def" | 
| John McCall | e314e27 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 994 | #define SHARED_SINGLETON_TYPE(Expansion) | 
|  | 995 | #define BUILTIN_TYPE(Id, SingletonId) \ | 
|  | 996 | case BuiltinType::Id: return Importer.getToContext().SingletonId; | 
|  | 997 | #include "clang/AST/BuiltinTypes.def" | 
|  | 998 |  | 
|  | 999 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" | 
|  | 1000 | // context supports C++. | 
|  | 1001 |  | 
|  | 1002 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" | 
|  | 1003 | // context supports ObjC. | 
|  | 1004 |  | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1005 | case BuiltinType::Char_U: | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1006 | // The context we're importing from has an unsigned 'char'. If we're | 
|  | 1007 | // importing into a context with a signed 'char', translate to | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1008 | // 'unsigned char' instead. | 
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1009 | if (Importer.getToContext().getLangOpts().CharIsSigned) | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1010 | return Importer.getToContext().UnsignedCharTy; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1011 |  | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1012 | return Importer.getToContext().CharTy; | 
|  | 1013 |  | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1014 | case BuiltinType::Char_S: | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1015 | // The context we're importing from has an unsigned 'char'. If we're | 
|  | 1016 | // importing into a context with a signed 'char', translate to | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1017 | // 'unsigned char' instead. | 
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1018 | if (!Importer.getToContext().getLangOpts().CharIsSigned) | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1019 | return Importer.getToContext().SignedCharTy; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1020 |  | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1021 | return Importer.getToContext().CharTy; | 
|  | 1022 |  | 
| Chris Lattner | ad3467e | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 1023 | case BuiltinType::WChar_S: | 
|  | 1024 | case BuiltinType::WChar_U: | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1025 | // FIXME: If not in C++, shall we translate to the C equivalent of | 
|  | 1026 | // wchar_t? | 
|  | 1027 | return Importer.getToContext().WCharTy; | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1028 | } | 
| David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 1029 |  | 
|  | 1030 | llvm_unreachable("Invalid BuiltinType Kind!"); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1031 | } | 
|  | 1032 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1033 | ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { | 
|  | 1034 | ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType()); | 
|  | 1035 | if (!ToOriginalTypeOrErr) | 
|  | 1036 | return ToOriginalTypeOrErr.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1037 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1038 | return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1039 | } | 
|  | 1040 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1041 | ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) { | 
|  | 1042 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | 
|  | 1043 | if (!ToElementTypeOrErr) | 
|  | 1044 | return ToElementTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1045 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1046 | return Importer.getToContext().getComplexType(*ToElementTypeOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1047 | } | 
|  | 1048 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1049 | ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) { | 
|  | 1050 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | 
|  | 1051 | if (!ToPointeeTypeOrErr) | 
|  | 1052 | return ToPointeeTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1053 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1054 | return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1055 | } | 
|  | 1056 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1057 | ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1058 | // FIXME: Check for blocks support in "to" context. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1059 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | 
|  | 1060 | if (!ToPointeeTypeOrErr) | 
|  | 1061 | return ToPointeeTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1062 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1063 | return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1064 | } | 
|  | 1065 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1066 | ExpectedType | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1067 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1068 | // FIXME: Check for C++ support in "to" context. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1069 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); | 
|  | 1070 | if (!ToPointeeTypeOrErr) | 
|  | 1071 | return ToPointeeTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1072 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1073 | return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1074 | } | 
|  | 1075 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1076 | ExpectedType | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1077 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1078 | // FIXME: Check for C++0x support in "to" context. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1079 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); | 
|  | 1080 | if (!ToPointeeTypeOrErr) | 
|  | 1081 | return ToPointeeTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1082 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1083 | return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1084 | } | 
|  | 1085 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1086 | ExpectedType | 
|  | 1087 | ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1088 | // FIXME: Check for C++ support in "to" context. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1089 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | 
|  | 1090 | if (!ToPointeeTypeOrErr) | 
|  | 1091 | return ToPointeeTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1092 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1093 | ExpectedType ClassTypeOrErr = import(QualType(T->getClass(), 0)); | 
|  | 1094 | if (!ClassTypeOrErr) | 
|  | 1095 | return ClassTypeOrErr.takeError(); | 
|  | 1096 |  | 
|  | 1097 | return Importer.getToContext().getMemberPointerType( | 
|  | 1098 | *ToPointeeTypeOrErr, (*ClassTypeOrErr).getTypePtr()); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1099 | } | 
|  | 1100 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1101 | ExpectedType | 
|  | 1102 | ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { | 
| Richard Smith | 772e266 | 2019-10-04 01:25:59 +0000 | [diff] [blame] | 1103 | QualType ToElementType; | 
|  | 1104 | const Expr *ToSizeExpr; | 
|  | 1105 | if (auto Imp = importSeq(T->getElementType(), T->getSizeExpr())) | 
|  | 1106 | std::tie(ToElementType, ToSizeExpr) = *Imp; | 
|  | 1107 | else | 
|  | 1108 | return Imp.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1109 |  | 
| Richard Smith | 772e266 | 2019-10-04 01:25:59 +0000 | [diff] [blame] | 1110 | return Importer.getToContext().getConstantArrayType( | 
|  | 1111 | ToElementType, T->getSize(), ToSizeExpr, T->getSizeModifier(), | 
|  | 1112 | T->getIndexTypeCVRQualifiers()); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1113 | } | 
|  | 1114 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1115 | ExpectedType | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1116 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1117 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | 
|  | 1118 | if (!ToElementTypeOrErr) | 
|  | 1119 | return ToElementTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1120 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1121 | return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr, | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1122 | T->getSizeModifier(), | 
|  | 1123 | T->getIndexTypeCVRQualifiers()); | 
|  | 1124 | } | 
|  | 1125 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1126 | ExpectedType | 
|  | 1127 | ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { | 
|  | 1128 | QualType ToElementType; | 
|  | 1129 | Expr *ToSizeExpr; | 
|  | 1130 | SourceRange ToBracketsRange; | 
|  | 1131 | if (auto Imp = importSeq( | 
|  | 1132 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) | 
|  | 1133 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; | 
|  | 1134 | else | 
|  | 1135 | return Imp.takeError(); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1136 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1137 | return Importer.getToContext().getVariableArrayType( | 
|  | 1138 | ToElementType, ToSizeExpr, T->getSizeModifier(), | 
|  | 1139 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1140 | } | 
|  | 1141 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1142 | ExpectedType ASTNodeImporter::VisitDependentSizedArrayType( | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1143 | const DependentSizedArrayType *T) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1144 | QualType ToElementType; | 
|  | 1145 | Expr *ToSizeExpr; | 
|  | 1146 | SourceRange ToBracketsRange; | 
|  | 1147 | if (auto Imp = importSeq( | 
|  | 1148 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) | 
|  | 1149 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; | 
|  | 1150 | else | 
|  | 1151 | return Imp.takeError(); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1152 | // SizeExpr may be null if size is not specified directly. | 
|  | 1153 | // For example, 'int a[]'. | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1154 |  | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1155 | return Importer.getToContext().getDependentSizedArrayType( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1156 | ToElementType, ToSizeExpr, T->getSizeModifier(), | 
|  | 1157 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1158 | } | 
|  | 1159 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1160 | ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) { | 
|  | 1161 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | 
|  | 1162 | if (!ToElementTypeOrErr) | 
|  | 1163 | return ToElementTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1164 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1165 | return Importer.getToContext().getVectorType(*ToElementTypeOrErr, | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1166 | T->getNumElements(), | 
| Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 1167 | T->getVectorKind()); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1168 | } | 
|  | 1169 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1170 | ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { | 
|  | 1171 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | 
|  | 1172 | if (!ToElementTypeOrErr) | 
|  | 1173 | return ToElementTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1174 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1175 | return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr, | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1176 | T->getNumElements()); | 
|  | 1177 | } | 
|  | 1178 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1179 | ExpectedType | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1180 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1181 | // FIXME: What happens if we're importing a function without a prototype | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1182 | // into C++? Should we make it variadic? | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1183 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); | 
|  | 1184 | if (!ToReturnTypeOrErr) | 
|  | 1185 | return ToReturnTypeOrErr.takeError(); | 
| Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1186 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1187 | return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr, | 
| Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1188 | T->getExtInfo()); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1189 | } | 
|  | 1190 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1191 | ExpectedType | 
|  | 1192 | ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { | 
|  | 1193 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); | 
|  | 1194 | if (!ToReturnTypeOrErr) | 
|  | 1195 | return ToReturnTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1196 |  | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1197 | // Import argument types | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1198 | SmallVector<QualType, 4> ArgTypes; | 
| Aaron Ballman | 40bd0aa | 2014-03-17 15:23:01 +0000 | [diff] [blame] | 1199 | for (const auto &A : T->param_types()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1200 | ExpectedType TyOrErr = import(A); | 
|  | 1201 | if (!TyOrErr) | 
|  | 1202 | return TyOrErr.takeError(); | 
|  | 1203 | ArgTypes.push_back(*TyOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1204 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1205 |  | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1206 | // Import exception types | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1207 | SmallVector<QualType, 4> ExceptionTypes; | 
| Aaron Ballman | b088fbe | 2014-03-17 15:38:09 +0000 | [diff] [blame] | 1208 | for (const auto &E : T->exceptions()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1209 | ExpectedType TyOrErr = import(E); | 
|  | 1210 | if (!TyOrErr) | 
|  | 1211 | return TyOrErr.takeError(); | 
|  | 1212 | ExceptionTypes.push_back(*TyOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1213 | } | 
| John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 1214 |  | 
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1215 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); | 
|  | 1216 | FunctionProtoType::ExtProtoInfo ToEPI; | 
|  | 1217 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1218 | auto Imp = importSeq( | 
|  | 1219 | FromEPI.ExceptionSpec.NoexceptExpr, | 
|  | 1220 | FromEPI.ExceptionSpec.SourceDecl, | 
|  | 1221 | FromEPI.ExceptionSpec.SourceTemplate); | 
|  | 1222 | if (!Imp) | 
|  | 1223 | return Imp.takeError(); | 
|  | 1224 |  | 
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1225 | ToEPI.ExtInfo = FromEPI.ExtInfo; | 
|  | 1226 | ToEPI.Variadic = FromEPI.Variadic; | 
|  | 1227 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; | 
|  | 1228 | ToEPI.TypeQuals = FromEPI.TypeQuals; | 
|  | 1229 | ToEPI.RefQualifier = FromEPI.RefQualifier; | 
| Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 1230 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; | 
|  | 1231 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1232 | std::tie( | 
|  | 1233 | ToEPI.ExceptionSpec.NoexceptExpr, | 
|  | 1234 | ToEPI.ExceptionSpec.SourceDecl, | 
|  | 1235 | ToEPI.ExceptionSpec.SourceTemplate) = *Imp; | 
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1236 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1237 | return Importer.getToContext().getFunctionType( | 
|  | 1238 | *ToReturnTypeOrErr, ArgTypes, ToEPI); | 
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1239 | } | 
|  | 1240 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1241 | ExpectedType ASTNodeImporter::VisitUnresolvedUsingType( | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1242 | const UnresolvedUsingType *T) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1243 | UnresolvedUsingTypenameDecl *ToD; | 
|  | 1244 | Decl *ToPrevD; | 
|  | 1245 | if (auto Imp = importSeq(T->getDecl(), T->getDecl()->getPreviousDecl())) | 
|  | 1246 | std::tie(ToD, ToPrevD) = *Imp; | 
|  | 1247 | else | 
|  | 1248 | return Imp.takeError(); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1249 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1250 | return Importer.getToContext().getTypeDeclType( | 
|  | 1251 | ToD, cast_or_null<TypeDecl>(ToPrevD)); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1252 | } | 
|  | 1253 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1254 | ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) { | 
|  | 1255 | ExpectedType ToInnerTypeOrErr = import(T->getInnerType()); | 
|  | 1256 | if (!ToInnerTypeOrErr) | 
|  | 1257 | return ToInnerTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1258 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1259 | return Importer.getToContext().getParenType(*ToInnerTypeOrErr); | 
| Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 1260 | } | 
|  | 1261 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1262 | ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { | 
|  | 1263 | Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl()); | 
|  | 1264 | if (!ToDeclOrErr) | 
|  | 1265 | return ToDeclOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1266 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1267 | return Importer.getToContext().getTypeDeclType(*ToDeclOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1268 | } | 
|  | 1269 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1270 | ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { | 
|  | 1271 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); | 
|  | 1272 | if (!ToExprOrErr) | 
|  | 1273 | return ToExprOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1274 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1275 | return Importer.getToContext().getTypeOfExprType(*ToExprOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1276 | } | 
|  | 1277 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1278 | ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { | 
|  | 1279 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); | 
|  | 1280 | if (!ToUnderlyingTypeOrErr) | 
|  | 1281 | return ToUnderlyingTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1282 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1283 | return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1284 | } | 
|  | 1285 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1286 | ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { | 
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1287 | // FIXME: Make sure that the "to" context supports C++0x! | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1288 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); | 
|  | 1289 | if (!ToExprOrErr) | 
|  | 1290 | return ToExprOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1291 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1292 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); | 
|  | 1293 | if (!ToUnderlyingTypeOrErr) | 
|  | 1294 | return ToUnderlyingTypeOrErr.takeError(); | 
| Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 1295 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1296 | return Importer.getToContext().getDecltypeType( | 
|  | 1297 | *ToExprOrErr, *ToUnderlyingTypeOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1298 | } | 
|  | 1299 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1300 | ExpectedType | 
|  | 1301 | ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { | 
|  | 1302 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); | 
|  | 1303 | if (!ToBaseTypeOrErr) | 
|  | 1304 | return ToBaseTypeOrErr.takeError(); | 
| Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1305 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1306 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); | 
|  | 1307 | if (!ToUnderlyingTypeOrErr) | 
|  | 1308 | return ToUnderlyingTypeOrErr.takeError(); | 
|  | 1309 |  | 
|  | 1310 | return Importer.getToContext().getUnaryTransformType( | 
|  | 1311 | *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind()); | 
| Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1312 | } | 
|  | 1313 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1314 | ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) { | 
| Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 1315 | // FIXME: Make sure that the "to" context supports C++11! | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1316 | ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType()); | 
|  | 1317 | if (!ToDeducedTypeOrErr) | 
|  | 1318 | return ToDeducedTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1319 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1320 | return Importer.getToContext().getAutoType(*ToDeducedTypeOrErr, | 
|  | 1321 | T->getKeyword(), | 
| Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 1322 | /*IsDependent*/false); | 
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1323 | } | 
|  | 1324 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1325 | ExpectedType ASTNodeImporter::VisitInjectedClassNameType( | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1326 | const InjectedClassNameType *T) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1327 | Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl()); | 
|  | 1328 | if (!ToDeclOrErr) | 
|  | 1329 | return ToDeclOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1330 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1331 | ExpectedType ToInjTypeOrErr = import(T->getInjectedSpecializationType()); | 
|  | 1332 | if (!ToInjTypeOrErr) | 
|  | 1333 | return ToInjTypeOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1334 |  | 
|  | 1335 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading | 
|  | 1336 | // See comments in InjectedClassNameType definition for details | 
|  | 1337 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); | 
|  | 1338 | enum { | 
|  | 1339 | TypeAlignmentInBits = 4, | 
|  | 1340 | TypeAlignment = 1 << TypeAlignmentInBits | 
|  | 1341 | }; | 
|  | 1342 |  | 
|  | 1343 | return QualType(new (Importer.getToContext(), TypeAlignment) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1344 | InjectedClassNameType(*ToDeclOrErr, *ToInjTypeOrErr), 0); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1345 | } | 
|  | 1346 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1347 | ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) { | 
|  | 1348 | Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl()); | 
|  | 1349 | if (!ToDeclOrErr) | 
|  | 1350 | return ToDeclOrErr.takeError(); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1351 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1352 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1353 | } | 
|  | 1354 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1355 | ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) { | 
|  | 1356 | Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl()); | 
|  | 1357 | if (!ToDeclOrErr) | 
|  | 1358 | return ToDeclOrErr.takeError(); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1359 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1360 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1361 | } | 
|  | 1362 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1363 | ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { | 
|  | 1364 | ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType()); | 
|  | 1365 | if (!ToModifiedTypeOrErr) | 
|  | 1366 | return ToModifiedTypeOrErr.takeError(); | 
|  | 1367 | ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType()); | 
|  | 1368 | if (!ToEquivalentTypeOrErr) | 
|  | 1369 | return ToEquivalentTypeOrErr.takeError(); | 
| Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1370 |  | 
|  | 1371 | return Importer.getToContext().getAttributedType(T->getAttrKind(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1372 | *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr); | 
| Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1373 | } | 
|  | 1374 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1375 | ExpectedType ASTNodeImporter::VisitTemplateTypeParmType( | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1376 | const TemplateTypeParmType *T) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1377 | Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl()); | 
|  | 1378 | if (!ToDeclOrErr) | 
|  | 1379 | return ToDeclOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1380 |  | 
|  | 1381 | return Importer.getToContext().getTemplateTypeParmType( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1382 | T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1383 | } | 
|  | 1384 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1385 | ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType( | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1386 | const SubstTemplateTypeParmType *T) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1387 | ExpectedType ReplacedOrErr = import(QualType(T->getReplacedParameter(), 0)); | 
|  | 1388 | if (!ReplacedOrErr) | 
|  | 1389 | return ReplacedOrErr.takeError(); | 
|  | 1390 | const TemplateTypeParmType *Replaced = | 
|  | 1391 | cast<TemplateTypeParmType>((*ReplacedOrErr).getTypePtr()); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1392 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1393 | ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType()); | 
|  | 1394 | if (!ToReplacementTypeOrErr) | 
|  | 1395 | return ToReplacementTypeOrErr.takeError(); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1396 |  | 
|  | 1397 | return Importer.getToContext().getSubstTemplateTypeParmType( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1398 | Replaced, (*ToReplacementTypeOrErr).getCanonicalType()); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1399 | } | 
|  | 1400 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1401 | ExpectedType ASTNodeImporter::VisitTemplateSpecializationType( | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1402 | const TemplateSpecializationType *T) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1403 | auto ToTemplateOrErr = import(T->getTemplateName()); | 
|  | 1404 | if (!ToTemplateOrErr) | 
|  | 1405 | return ToTemplateOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1406 |  | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1407 | SmallVector<TemplateArgument, 2> ToTemplateArgs; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1408 | if (Error Err = ImportTemplateArguments( | 
|  | 1409 | T->getArgs(), T->getNumArgs(), ToTemplateArgs)) | 
|  | 1410 | return std::move(Err); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1411 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1412 | QualType ToCanonType; | 
|  | 1413 | if (!QualType(T, 0).isCanonical()) { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1414 | QualType FromCanonType | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1415 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1416 | if (ExpectedType TyOrErr = import(FromCanonType)) | 
|  | 1417 | ToCanonType = *TyOrErr; | 
|  | 1418 | else | 
|  | 1419 | return TyOrErr.takeError(); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1420 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1421 | return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr, | 
| David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 1422 | ToTemplateArgs, | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1423 | ToCanonType); | 
|  | 1424 | } | 
|  | 1425 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1426 | ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { | 
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1427 | // Note: the qualifier in an ElaboratedType is optional. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1428 | auto ToQualifierOrErr = import(T->getQualifier()); | 
|  | 1429 | if (!ToQualifierOrErr) | 
|  | 1430 | return ToQualifierOrErr.takeError(); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1431 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1432 | ExpectedType ToNamedTypeOrErr = import(T->getNamedType()); | 
|  | 1433 | if (!ToNamedTypeOrErr) | 
|  | 1434 | return ToNamedTypeOrErr.takeError(); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1435 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1436 | Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl()); | 
|  | 1437 | if (!ToOwnedTagDeclOrErr) | 
|  | 1438 | return ToOwnedTagDeclOrErr.takeError(); | 
| Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 1439 |  | 
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1440 | return Importer.getToContext().getElaboratedType(T->getKeyword(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1441 | *ToQualifierOrErr, | 
|  | 1442 | *ToNamedTypeOrErr, | 
|  | 1443 | *ToOwnedTagDeclOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1444 | } | 
|  | 1445 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1446 | ExpectedType | 
|  | 1447 | ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { | 
|  | 1448 | ExpectedType ToPatternOrErr = import(T->getPattern()); | 
|  | 1449 | if (!ToPatternOrErr) | 
|  | 1450 | return ToPatternOrErr.takeError(); | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1451 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1452 | return Importer.getToContext().getPackExpansionType(*ToPatternOrErr, | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1453 | T->getNumExpansions()); | 
|  | 1454 | } | 
|  | 1455 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1456 | ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType( | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1457 | const DependentTemplateSpecializationType *T) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1458 | auto ToQualifierOrErr = import(T->getQualifier()); | 
|  | 1459 | if (!ToQualifierOrErr) | 
|  | 1460 | return ToQualifierOrErr.takeError(); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1461 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1462 | IdentifierInfo *ToName = Importer.Import(T->getIdentifier()); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1463 |  | 
|  | 1464 | SmallVector<TemplateArgument, 2> ToPack; | 
|  | 1465 | ToPack.reserve(T->getNumArgs()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1466 | if (Error Err = ImportTemplateArguments( | 
|  | 1467 | T->getArgs(), T->getNumArgs(), ToPack)) | 
|  | 1468 | return std::move(Err); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1469 |  | 
|  | 1470 | return Importer.getToContext().getDependentTemplateSpecializationType( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1471 | T->getKeyword(), *ToQualifierOrErr, ToName, ToPack); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1472 | } | 
|  | 1473 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1474 | ExpectedType | 
|  | 1475 | ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) { | 
|  | 1476 | auto ToQualifierOrErr = import(T->getQualifier()); | 
|  | 1477 | if (!ToQualifierOrErr) | 
|  | 1478 | return ToQualifierOrErr.takeError(); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1479 |  | 
|  | 1480 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1481 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1482 | QualType Canon; | 
|  | 1483 | if (T != T->getCanonicalTypeInternal().getTypePtr()) { | 
|  | 1484 | if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal())) | 
|  | 1485 | Canon = (*TyOrErr).getCanonicalType(); | 
|  | 1486 | else | 
|  | 1487 | return TyOrErr.takeError(); | 
|  | 1488 | } | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1489 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1490 | return Importer.getToContext().getDependentNameType(T->getKeyword(), | 
|  | 1491 | *ToQualifierOrErr, | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1492 | Name, Canon); | 
|  | 1493 | } | 
|  | 1494 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1495 | ExpectedType | 
|  | 1496 | ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { | 
|  | 1497 | Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl()); | 
|  | 1498 | if (!ToDeclOrErr) | 
|  | 1499 | return ToDeclOrErr.takeError(); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1500 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1501 | return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr); | 
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1502 | } | 
|  | 1503 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1504 | ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { | 
|  | 1505 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); | 
|  | 1506 | if (!ToBaseTypeOrErr) | 
|  | 1507 | return ToBaseTypeOrErr.takeError(); | 
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1508 |  | 
| Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1509 | SmallVector<QualType, 4> TypeArgs; | 
| Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 1510 | for (auto TypeArg : T->getTypeArgsAsWritten()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1511 | if (ExpectedType TyOrErr = import(TypeArg)) | 
|  | 1512 | TypeArgs.push_back(*TyOrErr); | 
|  | 1513 | else | 
|  | 1514 | return TyOrErr.takeError(); | 
| Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1515 | } | 
|  | 1516 |  | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1517 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | 
| Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 1518 | for (auto *P : T->quals()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1519 | if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P)) | 
|  | 1520 | Protocols.push_back(*ProtocolOrErr); | 
|  | 1521 | else | 
|  | 1522 | return ProtocolOrErr.takeError(); | 
|  | 1523 |  | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1524 | } | 
|  | 1525 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1526 | return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs, | 
| Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 1527 | Protocols, | 
|  | 1528 | T->isKindOfTypeAsWritten()); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1529 | } | 
|  | 1530 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1531 | ExpectedType | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1532 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1533 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | 
|  | 1534 | if (!ToPointeeTypeOrErr) | 
|  | 1535 | return ToPointeeTypeOrErr.takeError(); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1536 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1537 | return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1538 | } | 
|  | 1539 |  | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 1540 | //---------------------------------------------------------------------------- | 
|  | 1541 | // Import Declarations | 
|  | 1542 | //---------------------------------------------------------------------------- | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1543 | Error ASTNodeImporter::ImportDeclParts( | 
|  | 1544 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, | 
|  | 1545 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) { | 
| Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1546 | // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop. | 
|  | 1547 | // example: int struct_in_proto(struct data_t{int a;int b;} *d); | 
|  | 1548 | DeclContext *OrigDC = D->getDeclContext(); | 
|  | 1549 | FunctionDecl *FunDecl; | 
|  | 1550 | if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) && | 
|  | 1551 | FunDecl->hasBody()) { | 
| Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1552 | auto getLeafPointeeType = [](const Type *T) { | 
|  | 1553 | while (T->isPointerType() || T->isArrayType()) { | 
|  | 1554 | T = T->getPointeeOrArrayElementType(); | 
|  | 1555 | } | 
|  | 1556 | return T; | 
|  | 1557 | }; | 
|  | 1558 | for (const ParmVarDecl *P : FunDecl->parameters()) { | 
|  | 1559 | const Type *LeafT = | 
|  | 1560 | getLeafPointeeType(P->getType().getCanonicalType().getTypePtr()); | 
|  | 1561 | auto *RT = dyn_cast<RecordType>(LeafT); | 
|  | 1562 | if (RT && RT->getDecl() == D) { | 
|  | 1563 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) | 
|  | 1564 | << D->getDeclKindName(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1565 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | 
| Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1566 | } | 
| Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1567 | } | 
|  | 1568 | } | 
|  | 1569 |  | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1570 | // Import the context of this declaration. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1571 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | 
|  | 1572 | return Err; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1573 |  | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1574 | // Import the name of this declaration. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1575 | if (Error Err = importInto(Name, D->getDeclName())) | 
|  | 1576 | return Err; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1577 |  | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1578 | // Import the location of this declaration. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1579 | if (Error Err = importInto(Loc, D->getLocation())) | 
|  | 1580 | return Err; | 
|  | 1581 |  | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1582 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); | 
| Gabor Marton | be77a98 | 2018-12-12 11:22:55 +0000 | [diff] [blame] | 1583 | if (ToD) | 
|  | 1584 | if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD)) | 
|  | 1585 | return Err; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1586 |  | 
|  | 1587 | return Error::success(); | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1588 | } | 
|  | 1589 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1590 | Error ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1591 | if (!FromD) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1592 | return Error::success(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1593 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1594 | if (!ToD) | 
|  | 1595 | if (Error Err = importInto(ToD, FromD)) | 
|  | 1596 | return Err; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1597 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1598 | if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) { | 
|  | 1599 | if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) { | 
|  | 1600 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && | 
|  | 1601 | !ToRecord->getDefinition()) { | 
|  | 1602 | if (Error Err = ImportDefinition(FromRecord, ToRecord)) | 
|  | 1603 | return Err; | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1604 | } | 
|  | 1605 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1606 | return Error::success(); | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1607 | } | 
|  | 1608 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1609 | if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) { | 
|  | 1610 | if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) { | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1611 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1612 | if (Error Err = ImportDefinition(FromEnum, ToEnum)) | 
|  | 1613 | return Err; | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1614 | } | 
|  | 1615 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1616 | return Error::success(); | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1617 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1618 |  | 
|  | 1619 | return Error::success(); | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1620 | } | 
|  | 1621 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1622 | Error | 
|  | 1623 | ASTNodeImporter::ImportDeclarationNameLoc( | 
|  | 1624 | const DeclarationNameInfo &From, DeclarationNameInfo& To) { | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1625 | // NOTE: To.Name and To.Loc are already imported. | 
|  | 1626 | // We only have to import To.LocInfo. | 
|  | 1627 | switch (To.getName().getNameKind()) { | 
|  | 1628 | case DeclarationName::Identifier: | 
|  | 1629 | case DeclarationName::ObjCZeroArgSelector: | 
|  | 1630 | case DeclarationName::ObjCOneArgSelector: | 
|  | 1631 | case DeclarationName::ObjCMultiArgSelector: | 
|  | 1632 | case DeclarationName::CXXUsingDirective: | 
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1633 | case DeclarationName::CXXDeductionGuideName: | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1634 | return Error::success(); | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1635 |  | 
|  | 1636 | case DeclarationName::CXXOperatorName: { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1637 | if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange())) | 
|  | 1638 | To.setCXXOperatorNameRange(*ToRangeOrErr); | 
|  | 1639 | else | 
|  | 1640 | return ToRangeOrErr.takeError(); | 
|  | 1641 | return Error::success(); | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1642 | } | 
|  | 1643 | case DeclarationName::CXXLiteralOperatorName: { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1644 | if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc())) | 
|  | 1645 | To.setCXXLiteralOperatorNameLoc(*LocOrErr); | 
|  | 1646 | else | 
|  | 1647 | return LocOrErr.takeError(); | 
|  | 1648 | return Error::success(); | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1649 | } | 
|  | 1650 | case DeclarationName::CXXConstructorName: | 
|  | 1651 | case DeclarationName::CXXDestructorName: | 
|  | 1652 | case DeclarationName::CXXConversionFunctionName: { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1653 | if (auto ToTInfoOrErr = import(From.getNamedTypeInfo())) | 
|  | 1654 | To.setNamedTypeInfo(*ToTInfoOrErr); | 
|  | 1655 | else | 
|  | 1656 | return ToTInfoOrErr.takeError(); | 
|  | 1657 | return Error::success(); | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1658 | } | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1659 | } | 
| Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 1660 | llvm_unreachable("Unknown name kind."); | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1661 | } | 
|  | 1662 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1663 | Error | 
|  | 1664 | ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { | 
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1665 | if (Importer.isMinimalImport() && !ForceImport) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1666 | auto ToDCOrErr = Importer.ImportContext(FromDC); | 
|  | 1667 | return ToDCOrErr.takeError(); | 
|  | 1668 | } | 
| Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1669 |  | 
|  | 1670 | // We use strict error handling in case of records and enums, but not | 
|  | 1671 | // with e.g. namespaces. | 
|  | 1672 | // | 
|  | 1673 | // FIXME Clients of the ASTImporter should be able to choose an | 
|  | 1674 | // appropriate error handling strategy for their needs.  For instance, | 
|  | 1675 | // they may not want to mark an entire namespace as erroneous merely | 
|  | 1676 | // because there is an ODR error with two typedefs.  As another example, | 
|  | 1677 | // the client may allow EnumConstantDecls with same names but with | 
|  | 1678 | // different values in two distinct translation units. | 
|  | 1679 | bool AccumulateChildErrors = isa<TagDecl>(FromDC); | 
|  | 1680 |  | 
|  | 1681 | Error ChildErrors = Error::success(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1682 | for (auto *From : FromDC->decls()) { | 
|  | 1683 | ExpectedDecl ImportedOrErr = import(From); | 
| Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1684 | if (!ImportedOrErr) { | 
|  | 1685 | if (AccumulateChildErrors) | 
|  | 1686 | ChildErrors = | 
|  | 1687 | joinErrors(std::move(ChildErrors), ImportedOrErr.takeError()); | 
|  | 1688 | else | 
|  | 1689 | consumeError(ImportedOrErr.takeError()); | 
|  | 1690 | } | 
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1691 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1692 |  | 
| Gabor Marton | 48b16e1 | 2019-07-25 09:07:17 +0000 | [diff] [blame] | 1693 | // We reorder declarations in RecordDecls because they may have another order | 
|  | 1694 | // in the "to" context than they have in the "from" context. This may happen | 
|  | 1695 | // e.g when we import a class like this: | 
|  | 1696 | //    struct declToImport { | 
|  | 1697 | //        int a = c + b; | 
|  | 1698 | //        int b = 1; | 
|  | 1699 | //        int c = 2; | 
|  | 1700 | //    }; | 
|  | 1701 | // During the import of `a` we import first the dependencies in sequence, | 
|  | 1702 | // thus the order would be `c`, `b`, `a`. We will get the normal order by | 
|  | 1703 | // first removing the already imported members and then adding them in the | 
|  | 1704 | // order as they apper in the "from" context. | 
|  | 1705 | // | 
|  | 1706 | // Keeping field order is vital because it determines structure layout. | 
|  | 1707 | // | 
|  | 1708 | // Here and below, we cannot call field_begin() method and its callers on | 
|  | 1709 | // ToDC if it has an external storage. Calling field_begin() will | 
|  | 1710 | // automatically load all the fields by calling | 
|  | 1711 | // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would | 
|  | 1712 | // call ASTImporter::Import(). This is because the ExternalASTSource | 
|  | 1713 | // interface in LLDB is implemented by the means of the ASTImporter. However, | 
|  | 1714 | // calling an import at this point would result in an uncontrolled import, we | 
|  | 1715 | // must avoid that. | 
|  | 1716 | const auto *FromRD = dyn_cast<RecordDecl>(FromDC); | 
|  | 1717 | if (!FromRD) | 
|  | 1718 | return ChildErrors; | 
|  | 1719 |  | 
|  | 1720 | auto ToDCOrErr = Importer.ImportContext(FromDC); | 
|  | 1721 | if (!ToDCOrErr) { | 
|  | 1722 | consumeError(std::move(ChildErrors)); | 
|  | 1723 | return ToDCOrErr.takeError(); | 
|  | 1724 | } | 
|  | 1725 |  | 
|  | 1726 | DeclContext *ToDC = *ToDCOrErr; | 
|  | 1727 | // Remove all declarations, which may be in wrong order in the | 
|  | 1728 | // lexical DeclContext and then add them in the proper order. | 
|  | 1729 | for (auto *D : FromRD->decls()) { | 
| Balazs Keri | 6e08669 | 2019-09-02 07:17:01 +0000 | [diff] [blame] | 1730 | if (isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D) || isa<FriendDecl>(D)) { | 
| Gabor Marton | 48b16e1 | 2019-07-25 09:07:17 +0000 | [diff] [blame] | 1731 | assert(D && "DC contains a null decl"); | 
|  | 1732 | Decl *ToD = Importer.GetAlreadyImportedOrNull(D); | 
|  | 1733 | // Remove only the decls which we successfully imported. | 
|  | 1734 | if (ToD) { | 
|  | 1735 | assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD)); | 
|  | 1736 | // Remove the decl from its wrong place in the linked list. | 
|  | 1737 | ToDC->removeDecl(ToD); | 
|  | 1738 | // Add the decl to the end of the linked list. | 
|  | 1739 | // This time it will be at the proper place because the enclosing for | 
|  | 1740 | // loop iterates in the original (good) order of the decls. | 
|  | 1741 | ToDC->addDeclInternal(ToD); | 
|  | 1742 | } | 
|  | 1743 | } | 
|  | 1744 | } | 
|  | 1745 |  | 
| Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1746 | return ChildErrors; | 
| Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 1747 | } | 
|  | 1748 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1749 | Error ASTNodeImporter::ImportDeclContext( | 
|  | 1750 | Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) { | 
|  | 1751 | auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext()); | 
|  | 1752 | if (!ToDCOrErr) | 
|  | 1753 | return ToDCOrErr.takeError(); | 
|  | 1754 | ToDC = *ToDCOrErr; | 
|  | 1755 |  | 
|  | 1756 | if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) { | 
|  | 1757 | auto ToLexicalDCOrErr = Importer.ImportContext( | 
|  | 1758 | FromD->getLexicalDeclContext()); | 
|  | 1759 | if (!ToLexicalDCOrErr) | 
|  | 1760 | return ToLexicalDCOrErr.takeError(); | 
|  | 1761 | ToLexicalDC = *ToLexicalDCOrErr; | 
|  | 1762 | } else | 
|  | 1763 | ToLexicalDC = ToDC; | 
|  | 1764 |  | 
|  | 1765 | return Error::success(); | 
|  | 1766 | } | 
|  | 1767 |  | 
|  | 1768 | Error ASTNodeImporter::ImportImplicitMethods( | 
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1769 | const CXXRecordDecl *From, CXXRecordDecl *To) { | 
|  | 1770 | assert(From->isCompleteDefinition() && To->getDefinition() == To && | 
|  | 1771 | "Import implicit methods to or from non-definition"); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1772 |  | 
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1773 | for (CXXMethodDecl *FromM : From->methods()) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1774 | if (FromM->isImplicit()) { | 
|  | 1775 | Expected<CXXMethodDecl *> ToMOrErr = import(FromM); | 
|  | 1776 | if (!ToMOrErr) | 
|  | 1777 | return ToMOrErr.takeError(); | 
|  | 1778 | } | 
|  | 1779 |  | 
|  | 1780 | return Error::success(); | 
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1781 | } | 
|  | 1782 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1783 | static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, | 
|  | 1784 | ASTImporter &Importer) { | 
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1785 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 1786 | if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef)) | 
| Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 1787 | To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr)); | 
|  | 1788 | else | 
|  | 1789 | return ToTypedefOrErr.takeError(); | 
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1790 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1791 | return Error::success(); | 
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1792 | } | 
|  | 1793 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1794 | Error ASTNodeImporter::ImportDefinition( | 
|  | 1795 | RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) { | 
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 1796 | auto DefinitionCompleter = [To]() { | 
|  | 1797 | // There are cases in LLDB when we first import a class without its | 
|  | 1798 | // members. The class will have DefinitionData, but no members. Then, | 
|  | 1799 | // importDefinition is called from LLDB, which tries to get the members, so | 
|  | 1800 | // when we get here, the class already has the DefinitionData set, so we | 
|  | 1801 | // must unset the CompleteDefinition here to be able to complete again the | 
|  | 1802 | // definition. | 
|  | 1803 | To->setCompleteDefinition(false); | 
|  | 1804 | To->completeDefinition(); | 
|  | 1805 | }; | 
|  | 1806 |  | 
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1807 | if (To->getDefinition() || To->isBeingDefined()) { | 
| Gabor Marton | e73805f | 2019-07-08 12:49:13 +0000 | [diff] [blame] | 1808 | if (Kind == IDK_Everything || | 
|  | 1809 | // In case of lambdas, the class already has a definition ptr set, but | 
|  | 1810 | // the contained decls are not imported yet. Also, isBeingDefined was | 
|  | 1811 | // set in CXXRecordDecl::CreateLambda.  We must import the contained | 
|  | 1812 | // decls here and finish the definition. | 
|  | 1813 | (To->isLambda() && shouldForceImportDeclContext(Kind))) { | 
|  | 1814 | Error Result = ImportDeclContext(From, /*ForceImport=*/true); | 
|  | 1815 | // Finish the definition of the lambda, set isBeingDefined to false. | 
|  | 1816 | if (To->isLambda()) | 
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 1817 | DefinitionCompleter(); | 
| Gabor Marton | e73805f | 2019-07-08 12:49:13 +0000 | [diff] [blame] | 1818 | return Result; | 
|  | 1819 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1820 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1821 | return Error::success(); | 
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1822 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1823 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1824 | To->startDefinition(); | 
| Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1825 | // Complete the definition even if error is returned. | 
|  | 1826 | // The RecordDecl may be already part of the AST so it is better to | 
|  | 1827 | // have it in complete state even if something is wrong with it. | 
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 1828 | auto DefinitionCompleterScopeExit = | 
|  | 1829 | llvm::make_scope_exit(DefinitionCompleter); | 
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1830 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1831 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) | 
|  | 1832 | return Err; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1833 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1834 | // Add base classes. | 
| Gabor Marton | 17d3967 | 2018-11-26 15:54:08 +0000 | [diff] [blame] | 1835 | auto *ToCXX = dyn_cast<CXXRecordDecl>(To); | 
|  | 1836 | auto *FromCXX = dyn_cast<CXXRecordDecl>(From); | 
|  | 1837 | if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) { | 
| Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1838 |  | 
|  | 1839 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); | 
|  | 1840 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); | 
| Richard Smith | 91aeacc | 2019-10-11 00:29:04 +0000 | [diff] [blame] | 1841 |  | 
|  | 1842 | #define FIELD(Name, Width, Merge) \ | 
|  | 1843 | ToData.Name = FromData.Name; | 
|  | 1844 | #include "clang/AST/CXXRecordDeclDefinitionBits.def" | 
| Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1845 |  | 
| Shafik Yaghmour | 16b9073 | 2019-04-26 18:51:28 +0000 | [diff] [blame] | 1846 | // Copy over the data stored in RecordDeclBits | 
|  | 1847 | ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions()); | 
|  | 1848 |  | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1849 | SmallVector<CXXBaseSpecifier *, 4> Bases; | 
| Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1850 | for (const auto &Base1 : FromCXX->bases()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1851 | ExpectedType TyOrErr = import(Base1.getType()); | 
|  | 1852 | if (!TyOrErr) | 
|  | 1853 | return TyOrErr.takeError(); | 
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1854 |  | 
|  | 1855 | SourceLocation EllipsisLoc; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1856 | if (Base1.isPackExpansion()) { | 
|  | 1857 | if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc())) | 
|  | 1858 | EllipsisLoc = *LocOrErr; | 
|  | 1859 | else | 
|  | 1860 | return LocOrErr.takeError(); | 
|  | 1861 | } | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1862 |  | 
|  | 1863 | // Ensure that we have a definition for the base. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1864 | if (Error Err = | 
|  | 1865 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl())) | 
|  | 1866 | return Err; | 
|  | 1867 |  | 
|  | 1868 | auto RangeOrErr = import(Base1.getSourceRange()); | 
|  | 1869 | if (!RangeOrErr) | 
|  | 1870 | return RangeOrErr.takeError(); | 
|  | 1871 |  | 
|  | 1872 | auto TSIOrErr = import(Base1.getTypeSourceInfo()); | 
|  | 1873 | if (!TSIOrErr) | 
|  | 1874 | return TSIOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1875 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1876 | Bases.push_back( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1877 | new (Importer.getToContext()) CXXBaseSpecifier( | 
|  | 1878 | *RangeOrErr, | 
|  | 1879 | Base1.isVirtual(), | 
|  | 1880 | Base1.isBaseOfClass(), | 
|  | 1881 | Base1.getAccessSpecifierAsWritten(), | 
|  | 1882 | *TSIOrErr, | 
|  | 1883 | EllipsisLoc)); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1884 | } | 
|  | 1885 | if (!Bases.empty()) | 
| Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1886 | ToCXX->setBases(Bases.data(), Bases.size()); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1887 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1888 |  | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1889 | if (shouldForceImportDeclContext(Kind)) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1890 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | 
|  | 1891 | return Err; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1892 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1893 | return Error::success(); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1894 | } | 
|  | 1895 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1896 | Error ASTNodeImporter::ImportInitializer(VarDecl *From, VarDecl *To) { | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1897 | if (To->getAnyInitializer()) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1898 | return Error::success(); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1899 |  | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1900 | Expr *FromInit = From->getInit(); | 
|  | 1901 | if (!FromInit) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1902 | return Error::success(); | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1903 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1904 | ExpectedExpr ToInitOrErr = import(FromInit); | 
|  | 1905 | if (!ToInitOrErr) | 
|  | 1906 | return ToInitOrErr.takeError(); | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1907 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1908 | To->setInit(*ToInitOrErr); | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1909 | if (From->isInitKnownICE()) { | 
|  | 1910 | EvaluatedStmt *Eval = To->ensureEvaluatedStmt(); | 
|  | 1911 | Eval->CheckedICE = true; | 
|  | 1912 | Eval->IsICE = From->isInitICE(); | 
|  | 1913 | } | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1914 |  | 
|  | 1915 | // FIXME: Other bits to merge? | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1916 | return Error::success(); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1917 | } | 
|  | 1918 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1919 | Error ASTNodeImporter::ImportDefinition( | 
|  | 1920 | EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) { | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1921 | if (To->getDefinition() || To->isBeingDefined()) { | 
|  | 1922 | if (Kind == IDK_Everything) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1923 | return ImportDeclContext(From, /*ForceImport=*/true); | 
|  | 1924 | return Error::success(); | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1925 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1926 |  | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1927 | To->startDefinition(); | 
|  | 1928 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1929 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) | 
|  | 1930 | return Err; | 
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1931 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1932 | ExpectedType ToTypeOrErr = | 
|  | 1933 | import(Importer.getFromContext().getTypeDeclType(From)); | 
|  | 1934 | if (!ToTypeOrErr) | 
|  | 1935 | return ToTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1936 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1937 | ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType()); | 
|  | 1938 | if (!ToPromotionTypeOrErr) | 
|  | 1939 | return ToPromotionTypeOrErr.takeError(); | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1940 |  | 
|  | 1941 | if (shouldForceImportDeclContext(Kind)) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1942 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | 
|  | 1943 | return Err; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1944 |  | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1945 | // FIXME: we might need to merge the number of positive or negative bits | 
|  | 1946 | // if the enumerator lists don't match. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1947 | To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr, | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1948 | From->getNumPositiveBits(), | 
|  | 1949 | From->getNumNegativeBits()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1950 | return Error::success(); | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1951 | } | 
|  | 1952 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1953 | Error ASTNodeImporter::ImportTemplateArguments( | 
|  | 1954 | const TemplateArgument *FromArgs, unsigned NumFromArgs, | 
|  | 1955 | SmallVectorImpl<TemplateArgument> &ToArgs) { | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1956 | for (unsigned I = 0; I != NumFromArgs; ++I) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1957 | if (auto ToOrErr = import(FromArgs[I])) | 
|  | 1958 | ToArgs.push_back(*ToOrErr); | 
|  | 1959 | else | 
|  | 1960 | return ToOrErr.takeError(); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1961 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1962 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1963 | return Error::success(); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1964 | } | 
|  | 1965 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1966 | // FIXME: Do not forget to remove this and use only 'import'. | 
|  | 1967 | Expected<TemplateArgument> | 
|  | 1968 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { | 
|  | 1969 | return import(From); | 
|  | 1970 | } | 
|  | 1971 |  | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1972 | template <typename InContainerTy> | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1973 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1974 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { | 
|  | 1975 | for (const auto &FromLoc : Container) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1976 | if (auto ToLocOrErr = import(FromLoc)) | 
|  | 1977 | ToTAInfo.addArgument(*ToLocOrErr); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1978 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1979 | return ToLocOrErr.takeError(); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1980 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1981 | return Error::success(); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1982 | } | 
|  | 1983 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1984 | static StructuralEquivalenceKind | 
|  | 1985 | getStructuralEquivalenceKind(const ASTImporter &Importer) { | 
|  | 1986 | return Importer.isMinimalImport() ? StructuralEquivalenceKind::Minimal | 
|  | 1987 | : StructuralEquivalenceKind::Default; | 
|  | 1988 | } | 
|  | 1989 |  | 
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1990 | bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) { | 
|  | 1991 | StructuralEquivalenceContext Ctx( | 
|  | 1992 | Importer.getFromContext(), Importer.getToContext(), | 
|  | 1993 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), | 
|  | 1994 | false, Complain); | 
|  | 1995 | return Ctx.IsEquivalent(From, To); | 
|  | 1996 | } | 
|  | 1997 |  | 
|  | 1998 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, | 
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1999 | RecordDecl *ToRecord, bool Complain) { | 
| Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2000 | // Eliminate a potential failure point where we attempt to re-import | 
|  | 2001 | // something we're trying to import while completing ToRecord. | 
|  | 2002 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); | 
|  | 2003 | if (ToOrigin) { | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2004 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); | 
| Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2005 | if (ToOriginRecord) | 
|  | 2006 | ToRecord = ToOriginRecord; | 
|  | 2007 | } | 
|  | 2008 |  | 
| Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 2009 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), | 
| Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2010 | ToRecord->getASTContext(), | 
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2011 | Importer.getNonEquivalentDecls(), | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2012 | getStructuralEquivalenceKind(Importer), | 
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2013 | false, Complain); | 
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2014 | return Ctx.IsEquivalent(FromRecord, ToRecord); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2015 | } | 
|  | 2016 |  | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2017 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, | 
|  | 2018 | bool Complain) { | 
|  | 2019 | StructuralEquivalenceContext Ctx( | 
|  | 2020 | Importer.getFromContext(), Importer.getToContext(), | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2021 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), | 
|  | 2022 | false, Complain); | 
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2023 | return Ctx.IsEquivalent(FromVar, ToVar); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2024 | } | 
|  | 2025 |  | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2026 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { | 
| Shafik Yaghmour | e5094d6 | 2019-03-27 17:47:36 +0000 | [diff] [blame] | 2027 | // Eliminate a potential failure point where we attempt to re-import | 
| Raphael Isemann | fa26c20 | 2019-04-09 14:18:23 +0000 | [diff] [blame] | 2028 | // something we're trying to import while completing ToEnum. | 
| Shafik Yaghmour | e5094d6 | 2019-03-27 17:47:36 +0000 | [diff] [blame] | 2029 | if (Decl *ToOrigin = Importer.GetOriginalDecl(ToEnum)) | 
|  | 2030 | if (auto *ToOriginEnum = dyn_cast<EnumDecl>(ToOrigin)) | 
|  | 2031 | ToEnum = ToOriginEnum; | 
|  | 2032 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2033 | StructuralEquivalenceContext Ctx( | 
|  | 2034 | Importer.getFromContext(), Importer.getToContext(), | 
|  | 2035 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer)); | 
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2036 | return Ctx.IsEquivalent(FromEnum, ToEnum); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2037 | } | 
|  | 2038 |  | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2039 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, | 
|  | 2040 | FunctionTemplateDecl *To) { | 
|  | 2041 | StructuralEquivalenceContext Ctx( | 
|  | 2042 | Importer.getFromContext(), Importer.getToContext(), | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2043 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), | 
|  | 2044 | false, false); | 
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2045 | return Ctx.IsEquivalent(From, To); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2046 | } | 
|  | 2047 |  | 
| Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2048 | bool ASTNodeImporter::IsStructuralMatch(FunctionDecl *From, FunctionDecl *To) { | 
|  | 2049 | StructuralEquivalenceContext Ctx( | 
|  | 2050 | Importer.getFromContext(), Importer.getToContext(), | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2051 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), | 
|  | 2052 | false, false); | 
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2053 | return Ctx.IsEquivalent(From, To); | 
| Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2054 | } | 
|  | 2055 |  | 
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2056 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2057 | EnumConstantDecl *ToEC) { | 
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2058 | const llvm::APSInt &FromVal = FromEC->getInitVal(); | 
|  | 2059 | const llvm::APSInt &ToVal = ToEC->getInitVal(); | 
|  | 2060 |  | 
|  | 2061 | return FromVal.isSigned() == ToVal.isSigned() && | 
|  | 2062 | FromVal.getBitWidth() == ToVal.getBitWidth() && | 
|  | 2063 | FromVal == ToVal; | 
|  | 2064 | } | 
|  | 2065 |  | 
|  | 2066 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2067 | ClassTemplateDecl *To) { | 
|  | 2068 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), | 
|  | 2069 | Importer.getToContext(), | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2070 | Importer.getNonEquivalentDecls(), | 
|  | 2071 | getStructuralEquivalenceKind(Importer)); | 
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2072 | return Ctx.IsEquivalent(From, To); | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2073 | } | 
|  | 2074 |  | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2075 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, | 
|  | 2076 | VarTemplateDecl *To) { | 
|  | 2077 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), | 
|  | 2078 | Importer.getToContext(), | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2079 | Importer.getNonEquivalentDecls(), | 
|  | 2080 | getStructuralEquivalenceKind(Importer)); | 
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2081 | return Ctx.IsEquivalent(From, To); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2082 | } | 
|  | 2083 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2084 | ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) { | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 2085 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) | 
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2086 | << D->getDeclKindName(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2087 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | 
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2088 | } | 
|  | 2089 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2090 | ExpectedDecl ASTNodeImporter::VisitImportDecl(ImportDecl *D) { | 
|  | 2091 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) | 
|  | 2092 | << D->getDeclKindName(); | 
|  | 2093 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | 
|  | 2094 | } | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2095 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2096 | ExpectedDecl ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { | 
|  | 2097 | // Import the context of this declaration. | 
|  | 2098 | DeclContext *DC, *LexicalDC; | 
|  | 2099 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | 
|  | 2100 | return std::move(Err); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2101 |  | 
|  | 2102 | // Import the location of this declaration. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2103 | ExpectedSLoc LocOrErr = import(D->getLocation()); | 
|  | 2104 | if (!LocOrErr) | 
|  | 2105 | return LocOrErr.takeError(); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2106 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2107 | EmptyDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2108 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2109 | return ToD; | 
|  | 2110 |  | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2111 | ToD->setLexicalDeclContext(LexicalDC); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2112 | LexicalDC->addDeclInternal(ToD); | 
|  | 2113 | return ToD; | 
|  | 2114 | } | 
|  | 2115 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2116 | ExpectedDecl ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2117 | TranslationUnitDecl *ToD = | 
| Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2118 | Importer.getToContext().getTranslationUnitDecl(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2119 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2120 | Importer.MapImported(D, ToD); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2121 |  | 
| Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2122 | return ToD; | 
|  | 2123 | } | 
|  | 2124 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2125 | ExpectedDecl ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { | 
|  | 2126 | ExpectedSLoc LocOrErr = import(D->getLocation()); | 
|  | 2127 | if (!LocOrErr) | 
|  | 2128 | return LocOrErr.takeError(); | 
|  | 2129 | auto ColonLocOrErr = import(D->getColonLoc()); | 
|  | 2130 | if (!ColonLocOrErr) | 
|  | 2131 | return ColonLocOrErr.takeError(); | 
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2132 |  | 
|  | 2133 | // Import the context of this declaration. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2134 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); | 
|  | 2135 | if (!DCOrErr) | 
|  | 2136 | return DCOrErr.takeError(); | 
|  | 2137 | DeclContext *DC = *DCOrErr; | 
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2138 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2139 | AccessSpecDecl *ToD; | 
|  | 2140 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2141 | DC, *LocOrErr, *ColonLocOrErr)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2142 | return ToD; | 
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2143 |  | 
|  | 2144 | // Lexical DeclContext and Semantic DeclContext | 
|  | 2145 | // is always the same for the accessSpec. | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2146 | ToD->setLexicalDeclContext(DC); | 
|  | 2147 | DC->addDeclInternal(ToD); | 
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2148 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2149 | return ToD; | 
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2150 | } | 
|  | 2151 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2152 | ExpectedDecl ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { | 
|  | 2153 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); | 
|  | 2154 | if (!DCOrErr) | 
|  | 2155 | return DCOrErr.takeError(); | 
|  | 2156 | DeclContext *DC = *DCOrErr; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2157 | DeclContext *LexicalDC = DC; | 
|  | 2158 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2159 | SourceLocation ToLocation, ToRParenLoc; | 
|  | 2160 | Expr *ToAssertExpr; | 
|  | 2161 | StringLiteral *ToMessage; | 
|  | 2162 | if (auto Imp = importSeq( | 
|  | 2163 | D->getLocation(), D->getAssertExpr(), D->getMessage(), D->getRParenLoc())) | 
|  | 2164 | std::tie(ToLocation, ToAssertExpr, ToMessage, ToRParenLoc) = *Imp; | 
|  | 2165 | else | 
|  | 2166 | return Imp.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2167 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2168 | StaticAssertDecl *ToD; | 
|  | 2169 | if (GetImportedOrCreateDecl( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2170 | ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage, | 
|  | 2171 | ToRParenLoc, D->isFailed())) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2172 | return ToD; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2173 |  | 
|  | 2174 | ToD->setLexicalDeclContext(LexicalDC); | 
|  | 2175 | LexicalDC->addDeclInternal(ToD); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2176 | return ToD; | 
|  | 2177 | } | 
|  | 2178 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2179 | ExpectedDecl ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2180 | // Import the major distinguishing characteristics of this namespace. | 
|  | 2181 | DeclContext *DC, *LexicalDC; | 
|  | 2182 | DeclarationName Name; | 
|  | 2183 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2184 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2185 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 2186 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2187 | if (ToD) | 
|  | 2188 | return ToD; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2189 |  | 
|  | 2190 | NamespaceDecl *MergeWithNamespace = nullptr; | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2191 | if (!Name) { | 
|  | 2192 | // This is an anonymous namespace. Adopt an existing anonymous | 
|  | 2193 | // namespace if we can. | 
|  | 2194 | // FIXME: Not testable. | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2195 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2196 | MergeWithNamespace = TU->getAnonymousNamespace(); | 
|  | 2197 | else | 
|  | 2198 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); | 
|  | 2199 | } else { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2200 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2201 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2202 | for (auto *FoundDecl : FoundDecls) { | 
|  | 2203 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2204 | continue; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2205 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2206 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2207 | MergeWithNamespace = FoundNS; | 
|  | 2208 | ConflictingDecls.clear(); | 
|  | 2209 | break; | 
|  | 2210 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2211 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2212 | ConflictingDecls.push_back(FoundDecl); | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2213 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2214 |  | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2215 | if (!ConflictingDecls.empty()) { | 
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2216 | ExpectedName NameOrErr = Importer.HandleNameConflict( | 
|  | 2217 | Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(), | 
|  | 2218 | ConflictingDecls.size()); | 
|  | 2219 | if (NameOrErr) | 
|  | 2220 | Name = NameOrErr.get(); | 
|  | 2221 | else | 
|  | 2222 | return NameOrErr.takeError(); | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2223 | } | 
|  | 2224 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2225 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2226 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | 
|  | 2227 | if (!BeginLocOrErr) | 
|  | 2228 | return BeginLocOrErr.takeError(); | 
|  | 2229 |  | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2230 | // Create the "to" namespace, if needed. | 
|  | 2231 | NamespaceDecl *ToNamespace = MergeWithNamespace; | 
|  | 2232 | if (!ToNamespace) { | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2233 | if (GetImportedOrCreateDecl( | 
|  | 2234 | ToNamespace, D, Importer.getToContext(), DC, D->isInline(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2235 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2236 | /*PrevDecl=*/nullptr)) | 
|  | 2237 | return ToNamespace; | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2238 | ToNamespace->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2239 | LexicalDC->addDeclInternal(ToNamespace); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2240 |  | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2241 | // If this is an anonymous namespace, register it as the anonymous | 
|  | 2242 | // namespace within its context. | 
|  | 2243 | if (!Name) { | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2244 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2245 | TU->setAnonymousNamespace(ToNamespace); | 
|  | 2246 | else | 
|  | 2247 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); | 
|  | 2248 | } | 
|  | 2249 | } | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2250 | Importer.MapImported(D, ToNamespace); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2251 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2252 | if (Error Err = ImportDeclContext(D)) | 
|  | 2253 | return std::move(Err); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2254 |  | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2255 | return ToNamespace; | 
|  | 2256 | } | 
|  | 2257 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2258 | ExpectedDecl ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2259 | // Import the major distinguishing characteristics of this namespace. | 
|  | 2260 | DeclContext *DC, *LexicalDC; | 
|  | 2261 | DeclarationName Name; | 
|  | 2262 | SourceLocation Loc; | 
|  | 2263 | NamedDecl *LookupD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2264 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) | 
|  | 2265 | return std::move(Err); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2266 | if (LookupD) | 
|  | 2267 | return LookupD; | 
|  | 2268 |  | 
|  | 2269 | // NOTE: No conflict resolution is done for namespace aliases now. | 
|  | 2270 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2271 | SourceLocation ToNamespaceLoc, ToAliasLoc, ToTargetNameLoc; | 
|  | 2272 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 2273 | NamespaceDecl *ToNamespace; | 
|  | 2274 | if (auto Imp = importSeq( | 
|  | 2275 | D->getNamespaceLoc(), D->getAliasLoc(), D->getQualifierLoc(), | 
|  | 2276 | D->getTargetNameLoc(), D->getNamespace())) | 
|  | 2277 | std::tie( | 
|  | 2278 | ToNamespaceLoc, ToAliasLoc, ToQualifierLoc, ToTargetNameLoc, | 
|  | 2279 | ToNamespace) = *Imp; | 
|  | 2280 | else | 
|  | 2281 | return Imp.takeError(); | 
|  | 2282 | IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier()); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2283 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2284 | NamespaceAliasDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2285 | if (GetImportedOrCreateDecl( | 
|  | 2286 | ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc, | 
|  | 2287 | ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2288 | return ToD; | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2289 |  | 
|  | 2290 | ToD->setLexicalDeclContext(LexicalDC); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2291 | LexicalDC->addDeclInternal(ToD); | 
|  | 2292 |  | 
|  | 2293 | return ToD; | 
|  | 2294 | } | 
|  | 2295 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2296 | ExpectedDecl | 
|  | 2297 | ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2298 | // Import the major distinguishing characteristics of this typedef. | 
|  | 2299 | DeclContext *DC, *LexicalDC; | 
|  | 2300 | DeclarationName Name; | 
|  | 2301 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2302 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2303 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 2304 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2305 | if (ToD) | 
|  | 2306 | return ToD; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2307 |  | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2308 | // If this typedef is not in block scope, determine whether we've | 
|  | 2309 | // seen a typedef with the same name (that we can merge with) or any | 
|  | 2310 | // other entity by that name (which name lookup could conflict with). | 
| Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 2311 | // Note: Repeated typedefs are not valid in C99: | 
|  | 2312 | // 'typedef int T; typedef int T;' is invalid | 
|  | 2313 | // We do not care about this now. | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2314 | if (!DC->isFunctionOrMethod()) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2315 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2316 | unsigned IDNS = Decl::IDNS_Ordinary; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2317 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2318 | for (auto *FoundDecl : FoundDecls) { | 
|  | 2319 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2320 | continue; | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2321 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { | 
| Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 2322 | if (!hasSameVisibilityContext(FoundTypedef, D)) | 
|  | 2323 | continue; | 
|  | 2324 |  | 
| Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2325 | QualType FromUT = D->getUnderlyingType(); | 
|  | 2326 | QualType FoundUT = FoundTypedef->getUnderlyingType(); | 
|  | 2327 | if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) { | 
|  | 2328 | // If the "From" context has a complete underlying type but we | 
|  | 2329 | // already have a complete underlying type then return with that. | 
|  | 2330 | if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType()) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2331 | return Importer.MapImported(D, FoundTypedef); | 
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2332 | // FIXME Handle redecl chain. When you do that make consistent changes | 
|  | 2333 | // in ASTImporterLookupTable too. | 
|  | 2334 | } else { | 
|  | 2335 | ConflictingDecls.push_back(FoundDecl); | 
| Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2336 | } | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2337 | } | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2338 | } | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2339 |  | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2340 | if (!ConflictingDecls.empty()) { | 
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2341 | ExpectedName NameOrErr = Importer.HandleNameConflict( | 
|  | 2342 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); | 
|  | 2343 | if (NameOrErr) | 
|  | 2344 | Name = NameOrErr.get(); | 
|  | 2345 | else | 
|  | 2346 | return NameOrErr.takeError(); | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2347 | } | 
|  | 2348 | } | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2349 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2350 | QualType ToUnderlyingType; | 
|  | 2351 | TypeSourceInfo *ToTypeSourceInfo; | 
|  | 2352 | SourceLocation ToBeginLoc; | 
|  | 2353 | if (auto Imp = importSeq( | 
|  | 2354 | D->getUnderlyingType(), D->getTypeSourceInfo(), D->getBeginLoc())) | 
|  | 2355 | std::tie(ToUnderlyingType, ToTypeSourceInfo, ToBeginLoc) = *Imp; | 
|  | 2356 | else | 
|  | 2357 | return Imp.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2358 |  | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2359 | // Create the new typedef node. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2360 | // FIXME: ToUnderlyingType is not used. | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2361 | TypedefNameDecl *ToTypedef; | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2362 | if (IsAlias) { | 
|  | 2363 | if (GetImportedOrCreateDecl<TypeAliasDecl>( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2364 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, | 
|  | 2365 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2366 | return ToTypedef; | 
|  | 2367 | } else if (GetImportedOrCreateDecl<TypedefDecl>( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2368 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, | 
|  | 2369 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2370 | return ToTypedef; | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2371 |  | 
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2372 | ToTypedef->setAccess(D->getAccess()); | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2373 | ToTypedef->setLexicalDeclContext(LexicalDC); | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2374 |  | 
|  | 2375 | // Templated declarations should not appear in DeclContext. | 
|  | 2376 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; | 
|  | 2377 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) | 
|  | 2378 | LexicalDC->addDeclInternal(ToTypedef); | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2379 |  | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2380 | return ToTypedef; | 
|  | 2381 | } | 
|  | 2382 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2383 | ExpectedDecl ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2384 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); | 
|  | 2385 | } | 
|  | 2386 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2387 | ExpectedDecl ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2388 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); | 
|  | 2389 | } | 
|  | 2390 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2391 | ExpectedDecl | 
|  | 2392 | ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2393 | // Import the major distinguishing characteristics of this typedef. | 
|  | 2394 | DeclContext *DC, *LexicalDC; | 
|  | 2395 | DeclarationName Name; | 
|  | 2396 | SourceLocation Loc; | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2397 | NamedDecl *FoundD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2398 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) | 
|  | 2399 | return std::move(Err); | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2400 | if (FoundD) | 
|  | 2401 | return FoundD; | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2402 |  | 
|  | 2403 | // If this typedef is not in block scope, determine whether we've | 
|  | 2404 | // seen a typedef with the same name (that we can merge with) or any | 
|  | 2405 | // other entity by that name (which name lookup could conflict with). | 
|  | 2406 | if (!DC->isFunctionOrMethod()) { | 
|  | 2407 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
|  | 2408 | unsigned IDNS = Decl::IDNS_Ordinary; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2409 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2410 | for (auto *FoundDecl : FoundDecls) { | 
|  | 2411 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2412 | continue; | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2413 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2414 | return Importer.MapImported(D, FoundAlias); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2415 | ConflictingDecls.push_back(FoundDecl); | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2416 | } | 
|  | 2417 |  | 
|  | 2418 | if (!ConflictingDecls.empty()) { | 
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2419 | ExpectedName NameOrErr = Importer.HandleNameConflict( | 
|  | 2420 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); | 
|  | 2421 | if (NameOrErr) | 
|  | 2422 | Name = NameOrErr.get(); | 
|  | 2423 | else | 
|  | 2424 | return NameOrErr.takeError(); | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2425 | } | 
|  | 2426 | } | 
|  | 2427 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2428 | TemplateParameterList *ToTemplateParameters; | 
|  | 2429 | TypeAliasDecl *ToTemplatedDecl; | 
|  | 2430 | if (auto Imp = importSeq(D->getTemplateParameters(), D->getTemplatedDecl())) | 
|  | 2431 | std::tie(ToTemplateParameters, ToTemplatedDecl) = *Imp; | 
|  | 2432 | else | 
|  | 2433 | return Imp.takeError(); | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2434 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2435 | TypeAliasTemplateDecl *ToAlias; | 
|  | 2436 | if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2437 | Name, ToTemplateParameters, ToTemplatedDecl)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2438 | return ToAlias; | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2439 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2440 | ToTemplatedDecl->setDescribedAliasTemplate(ToAlias); | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2441 |  | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2442 | ToAlias->setAccess(D->getAccess()); | 
|  | 2443 | ToAlias->setLexicalDeclContext(LexicalDC); | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2444 | LexicalDC->addDeclInternal(ToAlias); | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2445 | return ToAlias; | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2446 | } | 
|  | 2447 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2448 | ExpectedDecl ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2449 | // Import the major distinguishing characteristics of this label. | 
|  | 2450 | DeclContext *DC, *LexicalDC; | 
|  | 2451 | DeclarationName Name; | 
|  | 2452 | SourceLocation Loc; | 
|  | 2453 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2454 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 2455 | return std::move(Err); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2456 | if (ToD) | 
|  | 2457 | return ToD; | 
|  | 2458 |  | 
|  | 2459 | assert(LexicalDC->isFunctionOrMethod()); | 
|  | 2460 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2461 | LabelDecl *ToLabel; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2462 | if (D->isGnuLocal()) { | 
|  | 2463 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | 
|  | 2464 | if (!BeginLocOrErr) | 
|  | 2465 | return BeginLocOrErr.takeError(); | 
|  | 2466 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, | 
|  | 2467 | Name.getAsIdentifierInfo(), *BeginLocOrErr)) | 
|  | 2468 | return ToLabel; | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2469 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2470 | } else { | 
|  | 2471 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, | 
|  | 2472 | Name.getAsIdentifierInfo())) | 
|  | 2473 | return ToLabel; | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2474 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2475 | } | 
|  | 2476 |  | 
|  | 2477 | Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt()); | 
|  | 2478 | if (!ToStmtOrErr) | 
|  | 2479 | return ToStmtOrErr.takeError(); | 
|  | 2480 |  | 
|  | 2481 | ToLabel->setStmt(*ToStmtOrErr); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2482 | ToLabel->setLexicalDeclContext(LexicalDC); | 
|  | 2483 | LexicalDC->addDeclInternal(ToLabel); | 
|  | 2484 | return ToLabel; | 
|  | 2485 | } | 
|  | 2486 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2487 | ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2488 | // Import the major distinguishing characteristics of this enum. | 
|  | 2489 | DeclContext *DC, *LexicalDC; | 
|  | 2490 | DeclarationName Name; | 
|  | 2491 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2492 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2493 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 2494 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2495 | if (ToD) | 
|  | 2496 | return ToD; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2497 |  | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2498 | // Figure out what enum name we're looking for. | 
|  | 2499 | unsigned IDNS = Decl::IDNS_Tag; | 
|  | 2500 | DeclarationName SearchName = Name; | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2501 | if (!SearchName && D->getTypedefNameForAnonDecl()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2502 | if (Error Err = importInto( | 
|  | 2503 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) | 
|  | 2504 | return std::move(Err); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2505 | IDNS = Decl::IDNS_Ordinary; | 
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2506 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2507 | IDNS |= Decl::IDNS_Ordinary; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2508 |  | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2509 | // We may already have an enum of the same name; try to find and match it. | 
|  | 2510 | if (!DC->isFunctionOrMethod() && SearchName) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2511 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2512 | auto FoundDecls = | 
|  | 2513 | Importer.findDeclsInToCtx(DC, SearchName); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2514 | for (auto *FoundDecl : FoundDecls) { | 
|  | 2515 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2516 | continue; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2517 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2518 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2519 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2520 | FoundDecl = Tag->getDecl(); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2521 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2522 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2523 | if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) { | 
| Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 2524 | if (!hasSameVisibilityContext(FoundEnum, D)) | 
|  | 2525 | continue; | 
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2526 | if (IsStructuralMatch(D, FoundEnum)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2527 | return Importer.MapImported(D, FoundEnum); | 
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2528 | ConflictingDecls.push_back(FoundDecl); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2529 | } | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2530 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2531 |  | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2532 | if (!ConflictingDecls.empty()) { | 
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2533 | ExpectedName NameOrErr = Importer.HandleNameConflict( | 
|  | 2534 | SearchName, DC, IDNS, ConflictingDecls.data(), | 
|  | 2535 | ConflictingDecls.size()); | 
|  | 2536 | if (NameOrErr) | 
|  | 2537 | Name = NameOrErr.get(); | 
|  | 2538 | else | 
|  | 2539 | return NameOrErr.takeError(); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2540 | } | 
|  | 2541 | } | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2542 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2543 | SourceLocation ToBeginLoc; | 
|  | 2544 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 2545 | QualType ToIntegerType; | 
|  | 2546 | if (auto Imp = importSeq( | 
|  | 2547 | D->getBeginLoc(), D->getQualifierLoc(), D->getIntegerType())) | 
|  | 2548 | std::tie(ToBeginLoc, ToQualifierLoc, ToIntegerType) = *Imp; | 
|  | 2549 | else | 
|  | 2550 | return Imp.takeError(); | 
|  | 2551 |  | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2552 | // Create the enum declaration. | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2553 | EnumDecl *D2; | 
|  | 2554 | if (GetImportedOrCreateDecl( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2555 | D2, D, Importer.getToContext(), DC, ToBeginLoc, | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2556 | Loc, Name.getAsIdentifierInfo(), nullptr, D->isScoped(), | 
|  | 2557 | D->isScopedUsingClassTag(), D->isFixed())) | 
|  | 2558 | return D2; | 
|  | 2559 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2560 | D2->setQualifierInfo(ToQualifierLoc); | 
|  | 2561 | D2->setIntegerType(ToIntegerType); | 
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2562 | D2->setAccess(D->getAccess()); | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2563 | D2->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2564 | LexicalDC->addDeclInternal(D2); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2565 |  | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2566 | // Import the definition | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2567 | if (D->isCompleteDefinition()) | 
|  | 2568 | if (Error Err = ImportDefinition(D, D2)) | 
|  | 2569 | return std::move(Err); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2570 |  | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2571 | return D2; | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2572 | } | 
|  | 2573 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2574 | ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { | 
| Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2575 | bool IsFriendTemplate = false; | 
|  | 2576 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { | 
|  | 2577 | IsFriendTemplate = | 
|  | 2578 | DCXX->getDescribedClassTemplate() && | 
|  | 2579 | DCXX->getDescribedClassTemplate()->getFriendObjectKind() != | 
|  | 2580 | Decl::FOK_None; | 
|  | 2581 | } | 
|  | 2582 |  | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2583 | // Import the major distinguishing characteristics of this record. | 
| Simon Pilgrim | 4706f3b | 2019-10-15 10:23:05 +0000 | [diff] [blame] | 2584 | DeclContext *DC = nullptr, *LexicalDC = nullptr; | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2585 | DeclarationName Name; | 
|  | 2586 | SourceLocation Loc; | 
| Simon Pilgrim | 4706f3b | 2019-10-15 10:23:05 +0000 | [diff] [blame] | 2587 | NamedDecl *ToD = nullptr; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2588 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 2589 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2590 | if (ToD) | 
|  | 2591 | return ToD; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2592 |  | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2593 | // Figure out what structure name we're looking for. | 
|  | 2594 | unsigned IDNS = Decl::IDNS_Tag; | 
|  | 2595 | DeclarationName SearchName = Name; | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2596 | if (!SearchName && D->getTypedefNameForAnonDecl()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2597 | if (Error Err = importInto( | 
|  | 2598 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) | 
|  | 2599 | return std::move(Err); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2600 | IDNS = Decl::IDNS_Ordinary; | 
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2601 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2602 | IDNS |= Decl::IDNS_Ordinary | Decl::IDNS_TagFriend; | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2603 |  | 
|  | 2604 | // We may already have a record of the same name; try to find and match it. | 
| Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2605 | RecordDecl *PrevDecl = nullptr; | 
| Gabor Marton | e3e83d7 | 2019-08-30 10:55:41 +0000 | [diff] [blame] | 2606 | if (!DC->isFunctionOrMethod() && !D->isLambda()) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2607 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2608 | auto FoundDecls = | 
|  | 2609 | Importer.findDeclsInToCtx(DC, SearchName); | 
| Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2610 | if (!FoundDecls.empty()) { | 
| Gabor Marton | 41e3892 | 2019-03-05 11:23:24 +0000 | [diff] [blame] | 2611 | // We're going to have to compare D against potentially conflicting Decls, | 
|  | 2612 | // so complete it. | 
| Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2613 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) | 
|  | 2614 | D->getASTContext().getExternalSource()->CompleteType(D); | 
|  | 2615 | } | 
|  | 2616 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2617 | for (auto *FoundDecl : FoundDecls) { | 
|  | 2618 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2619 | continue; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2620 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2621 | Decl *Found = FoundDecl; | 
|  | 2622 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { | 
|  | 2623 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2624 | Found = Tag->getDecl(); | 
|  | 2625 | } | 
| Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2626 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2627 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2628 | // Do not emit false positive diagnostic in case of unnamed | 
|  | 2629 | // struct/union and in case of anonymous structs.  Would be false | 
|  | 2630 | // because there may be several anonymous/unnamed structs in a class. | 
|  | 2631 | // E.g. these are both valid: | 
|  | 2632 | //  struct A { // unnamed structs | 
|  | 2633 | //    struct { struct A *next; } entry0; | 
|  | 2634 | //    struct { struct A *next; } entry1; | 
|  | 2635 | //  }; | 
|  | 2636 | //  struct X { struct { int a; }; struct { int b; }; }; // anon structs | 
|  | 2637 | if (!SearchName) | 
| Gabor Marton | 0bebf95 | 2018-07-05 09:51:13 +0000 | [diff] [blame] | 2638 | if (!IsStructuralMatch(D, FoundRecord, false)) | 
|  | 2639 | continue; | 
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2640 |  | 
| Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 2641 | if (!hasSameVisibilityContext(FoundRecord, D)) | 
|  | 2642 | continue; | 
|  | 2643 |  | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2644 | if (IsStructuralMatch(D, FoundRecord)) { | 
|  | 2645 | RecordDecl *FoundDef = FoundRecord->getDefinition(); | 
|  | 2646 | if (D->isThisDeclarationADefinition() && FoundDef) { | 
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2647 | // FIXME: Structural equivalence check should check for same | 
|  | 2648 | // user-defined methods. | 
|  | 2649 | Importer.MapImported(D, FoundDef); | 
|  | 2650 | if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { | 
|  | 2651 | auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef); | 
|  | 2652 | assert(FoundCXX && "Record type mismatch"); | 
|  | 2653 |  | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2654 | if (!Importer.isMinimalImport()) | 
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2655 | // FoundDef may not have every implicit method that D has | 
|  | 2656 | // because implicit methods are created only if they are used. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2657 | if (Error Err = ImportImplicitMethods(DCXX, FoundCXX)) | 
|  | 2658 | return std::move(Err); | 
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2659 | } | 
| Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2660 | } | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2661 | PrevDecl = FoundRecord->getMostRecentDecl(); | 
|  | 2662 | break; | 
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2663 | } | 
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2664 | ConflictingDecls.push_back(FoundDecl); | 
|  | 2665 | } // kind is RecordDecl | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2666 | } // for | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2667 |  | 
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2668 | if (!ConflictingDecls.empty() && SearchName) { | 
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2669 | ExpectedName NameOrErr = Importer.HandleNameConflict( | 
|  | 2670 | SearchName, DC, IDNS, ConflictingDecls.data(), | 
|  | 2671 | ConflictingDecls.size()); | 
|  | 2672 | if (NameOrErr) | 
|  | 2673 | Name = NameOrErr.get(); | 
|  | 2674 | else | 
|  | 2675 | return NameOrErr.takeError(); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2676 | } | 
|  | 2677 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2678 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2679 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | 
|  | 2680 | if (!BeginLocOrErr) | 
|  | 2681 | return BeginLocOrErr.takeError(); | 
|  | 2682 |  | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2683 | // Create the record declaration. | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2684 | RecordDecl *D2 = nullptr; | 
|  | 2685 | CXXRecordDecl *D2CXX = nullptr; | 
|  | 2686 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { | 
|  | 2687 | if (DCXX->isLambda()) { | 
|  | 2688 | auto TInfoOrErr = import(DCXX->getLambdaTypeInfo()); | 
|  | 2689 | if (!TInfoOrErr) | 
|  | 2690 | return TInfoOrErr.takeError(); | 
|  | 2691 | if (GetImportedOrCreateSpecialDecl( | 
|  | 2692 | D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(), | 
|  | 2693 | DC, *TInfoOrErr, Loc, DCXX->isDependentLambda(), | 
|  | 2694 | DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault())) | 
|  | 2695 | return D2CXX; | 
|  | 2696 | ExpectedDecl CDeclOrErr = import(DCXX->getLambdaContextDecl()); | 
|  | 2697 | if (!CDeclOrErr) | 
|  | 2698 | return CDeclOrErr.takeError(); | 
| Michael Liao | 243ebfb | 2019-10-19 00:15:19 +0000 | [diff] [blame] | 2699 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), *CDeclOrErr, | 
|  | 2700 | DCXX->hasKnownLambdaInternalLinkage()); | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2701 | } else if (DCXX->isInjectedClassName()) { | 
|  | 2702 | // We have to be careful to do a similar dance to the one in | 
|  | 2703 | // Sema::ActOnStartCXXMemberDeclarations | 
|  | 2704 | const bool DelayTypeCreation = true; | 
|  | 2705 | if (GetImportedOrCreateDecl( | 
|  | 2706 | D2CXX, D, Importer.getToContext(), D->getTagKind(), DC, | 
|  | 2707 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), | 
|  | 2708 | cast_or_null<CXXRecordDecl>(PrevDecl), DelayTypeCreation)) | 
|  | 2709 | return D2CXX; | 
|  | 2710 | Importer.getToContext().getTypeDeclType( | 
|  | 2711 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); | 
|  | 2712 | } else { | 
|  | 2713 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), | 
|  | 2714 | D->getTagKind(), DC, *BeginLocOrErr, Loc, | 
|  | 2715 | Name.getAsIdentifierInfo(), | 
|  | 2716 | cast_or_null<CXXRecordDecl>(PrevDecl))) | 
|  | 2717 | return D2CXX; | 
|  | 2718 | } | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2719 |  | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2720 | D2 = D2CXX; | 
|  | 2721 | D2->setAccess(D->getAccess()); | 
|  | 2722 | D2->setLexicalDeclContext(LexicalDC); | 
|  | 2723 | if (!DCXX->getDescribedClassTemplate() || DCXX->isImplicit()) | 
|  | 2724 | LexicalDC->addDeclInternal(D2); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2725 |  | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2726 | if (LexicalDC != DC && D->isInIdentifierNamespace(Decl::IDNS_TagFriend)) | 
|  | 2727 | DC->makeDeclVisibleInContext(D2); | 
|  | 2728 |  | 
|  | 2729 | if (ClassTemplateDecl *FromDescribed = | 
|  | 2730 | DCXX->getDescribedClassTemplate()) { | 
|  | 2731 | ClassTemplateDecl *ToDescribed; | 
|  | 2732 | if (Error Err = importInto(ToDescribed, FromDescribed)) | 
|  | 2733 | return std::move(Err); | 
|  | 2734 | D2CXX->setDescribedClassTemplate(ToDescribed); | 
|  | 2735 | if (!DCXX->isInjectedClassName() && !IsFriendTemplate) { | 
|  | 2736 | // In a record describing a template the type should be an | 
|  | 2737 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the | 
|  | 2738 | // previously set type to the correct value here (ToDescribed is not | 
|  | 2739 | // available at record create). | 
|  | 2740 | // FIXME: The previous type is cleared but not removed from | 
|  | 2741 | // ASTContext's internal storage. | 
|  | 2742 | CXXRecordDecl *Injected = nullptr; | 
|  | 2743 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { | 
|  | 2744 | auto *Record = dyn_cast<CXXRecordDecl>(Found); | 
|  | 2745 | if (Record && Record->isInjectedClassName()) { | 
|  | 2746 | Injected = Record; | 
|  | 2747 | break; | 
| Gabor Marton | 5915777e | 2018-06-26 13:44:24 +0000 | [diff] [blame] | 2748 | } | 
|  | 2749 | } | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2750 | // Create an injected type for the whole redecl chain. | 
|  | 2751 | SmallVector<Decl *, 2> Redecls = | 
|  | 2752 | getCanonicalForwardRedeclChain(D2CXX); | 
|  | 2753 | for (auto *R : Redecls) { | 
|  | 2754 | auto *RI = cast<CXXRecordDecl>(R); | 
|  | 2755 | RI->setTypeForDecl(nullptr); | 
|  | 2756 | // Below we create a new injected type and assign that to the | 
|  | 2757 | // canonical decl, subsequent declarations in the chain will reuse | 
|  | 2758 | // that type. | 
|  | 2759 | Importer.getToContext().getInjectedClassNameType( | 
|  | 2760 | RI, ToDescribed->getInjectedClassNameSpecialization()); | 
|  | 2761 | } | 
|  | 2762 | // Set the new type for the previous injected decl too. | 
|  | 2763 | if (Injected) { | 
|  | 2764 | Injected->setTypeForDecl(nullptr); | 
|  | 2765 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); | 
|  | 2766 | } | 
|  | 2767 | } | 
|  | 2768 | } else if (MemberSpecializationInfo *MemberInfo = | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2769 | DCXX->getMemberSpecializationInfo()) { | 
|  | 2770 | TemplateSpecializationKind SK = | 
|  | 2771 | MemberInfo->getTemplateSpecializationKind(); | 
|  | 2772 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2773 |  | 
|  | 2774 | if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst)) | 
|  | 2775 | D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK); | 
|  | 2776 | else | 
|  | 2777 | return ToInstOrErr.takeError(); | 
|  | 2778 |  | 
|  | 2779 | if (ExpectedSLoc POIOrErr = | 
|  | 2780 | import(MemberInfo->getPointOfInstantiation())) | 
|  | 2781 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( | 
|  | 2782 | *POIOrErr); | 
|  | 2783 | else | 
|  | 2784 | return POIOrErr.takeError(); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2785 | } | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2786 |  | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2787 | } else { | 
|  | 2788 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), | 
|  | 2789 | D->getTagKind(), DC, *BeginLocOrErr, Loc, | 
|  | 2790 | Name.getAsIdentifierInfo(), PrevDecl)) | 
|  | 2791 | return D2; | 
|  | 2792 | D2->setLexicalDeclContext(LexicalDC); | 
|  | 2793 | LexicalDC->addDeclInternal(D2); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2794 | } | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2795 |  | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2796 | if (auto QualifierLocOrErr = import(D->getQualifierLoc())) | 
|  | 2797 | D2->setQualifierInfo(*QualifierLocOrErr); | 
|  | 2798 | else | 
|  | 2799 | return QualifierLocOrErr.takeError(); | 
|  | 2800 |  | 
|  | 2801 | if (D->isAnonymousStructOrUnion()) | 
|  | 2802 | D2->setAnonymousStructOrUnion(true); | 
| Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2803 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2804 | if (D->isCompleteDefinition()) | 
|  | 2805 | if (Error Err = ImportDefinition(D, D2, IDK_Default)) | 
|  | 2806 | return std::move(Err); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2807 |  | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2808 | return D2; | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2809 | } | 
|  | 2810 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2811 | ExpectedDecl ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2812 | // Import the major distinguishing characteristics of this enumerator. | 
|  | 2813 | DeclContext *DC, *LexicalDC; | 
|  | 2814 | DeclarationName Name; | 
|  | 2815 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2816 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2817 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 2818 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2819 | if (ToD) | 
|  | 2820 | return ToD; | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2821 |  | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2822 | // Determine whether there are any other declarations with the same name and | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2823 | // in the same context. | 
|  | 2824 | if (!LexicalDC->isFunctionOrMethod()) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2825 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2826 | unsigned IDNS = Decl::IDNS_Ordinary; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2827 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2828 | for (auto *FoundDecl : FoundDecls) { | 
|  | 2829 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2830 | continue; | 
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2831 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2832 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { | 
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2833 | if (IsStructuralMatch(D, FoundEnumConstant)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2834 | return Importer.MapImported(D, FoundEnumConstant); | 
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2835 | ConflictingDecls.push_back(FoundDecl); | 
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2836 | } | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2837 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2838 |  | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2839 | if (!ConflictingDecls.empty()) { | 
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2840 | ExpectedName NameOrErr = Importer.HandleNameConflict( | 
|  | 2841 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); | 
|  | 2842 | if (NameOrErr) | 
|  | 2843 | Name = NameOrErr.get(); | 
|  | 2844 | else | 
|  | 2845 | return NameOrErr.takeError(); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2846 | } | 
|  | 2847 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2848 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2849 | ExpectedType TypeOrErr = import(D->getType()); | 
|  | 2850 | if (!TypeOrErr) | 
|  | 2851 | return TypeOrErr.takeError(); | 
|  | 2852 |  | 
|  | 2853 | ExpectedExpr InitOrErr = import(D->getInitExpr()); | 
|  | 2854 | if (!InitOrErr) | 
|  | 2855 | return InitOrErr.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2856 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2857 | EnumConstantDecl *ToEnumerator; | 
|  | 2858 | if (GetImportedOrCreateDecl( | 
|  | 2859 | ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2860 | Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal())) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2861 | return ToEnumerator; | 
|  | 2862 |  | 
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2863 | ToEnumerator->setAccess(D->getAccess()); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2864 | ToEnumerator->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2865 | LexicalDC->addDeclInternal(ToEnumerator); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2866 | return ToEnumerator; | 
|  | 2867 | } | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2868 |  | 
| Balazs Keri | 1efc974 | 2019-05-07 10:55:11 +0000 | [diff] [blame] | 2869 | Error ASTNodeImporter::ImportTemplateParameterLists(const DeclaratorDecl *FromD, | 
|  | 2870 | DeclaratorDecl *ToD) { | 
|  | 2871 | unsigned int Num = FromD->getNumTemplateParameterLists(); | 
|  | 2872 | if (Num == 0) | 
|  | 2873 | return Error::success(); | 
|  | 2874 | SmallVector<TemplateParameterList *, 2> ToTPLists(Num); | 
|  | 2875 | for (unsigned int I = 0; I < Num; ++I) | 
|  | 2876 | if (Expected<TemplateParameterList *> ToTPListOrErr = | 
|  | 2877 | import(FromD->getTemplateParameterList(I))) | 
|  | 2878 | ToTPLists[I] = *ToTPListOrErr; | 
|  | 2879 | else | 
|  | 2880 | return ToTPListOrErr.takeError(); | 
|  | 2881 | ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists); | 
|  | 2882 | return Error::success(); | 
|  | 2883 | } | 
|  | 2884 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2885 | Error ASTNodeImporter::ImportTemplateInformation( | 
|  | 2886 | FunctionDecl *FromFD, FunctionDecl *ToFD) { | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2887 | switch (FromFD->getTemplatedKind()) { | 
|  | 2888 | case FunctionDecl::TK_NonTemplate: | 
|  | 2889 | case FunctionDecl::TK_FunctionTemplate: | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2890 | return Error::success(); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2891 |  | 
|  | 2892 | case FunctionDecl::TK_MemberSpecialization: { | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2893 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2894 |  | 
|  | 2895 | if (Expected<FunctionDecl *> InstFDOrErr = | 
|  | 2896 | import(FromFD->getInstantiatedFromMemberFunction())) | 
|  | 2897 | ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK); | 
|  | 2898 | else | 
|  | 2899 | return InstFDOrErr.takeError(); | 
|  | 2900 |  | 
|  | 2901 | if (ExpectedSLoc POIOrErr = import( | 
|  | 2902 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation())) | 
|  | 2903 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr); | 
|  | 2904 | else | 
|  | 2905 | return POIOrErr.takeError(); | 
|  | 2906 |  | 
|  | 2907 | return Error::success(); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2908 | } | 
|  | 2909 |  | 
|  | 2910 | case FunctionDecl::TK_FunctionTemplateSpecialization: { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2911 | auto FunctionAndArgsOrErr = | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2912 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2913 | if (!FunctionAndArgsOrErr) | 
|  | 2914 | return FunctionAndArgsOrErr.takeError(); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2915 |  | 
|  | 2916 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2917 | Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr)); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2918 |  | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2919 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2920 | TemplateArgumentListInfo ToTAInfo; | 
|  | 2921 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2922 | if (FromTAArgsAsWritten) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2923 | if (Error Err = ImportTemplateArgumentListInfo( | 
|  | 2924 | *FromTAArgsAsWritten, ToTAInfo)) | 
|  | 2925 | return Err; | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2926 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2927 | ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation()); | 
|  | 2928 | if (!POIOrErr) | 
|  | 2929 | return POIOrErr.takeError(); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2930 |  | 
| Balazs Keri | 1efc974 | 2019-05-07 10:55:11 +0000 | [diff] [blame] | 2931 | if (Error Err = ImportTemplateParameterLists(FromFD, ToFD)) | 
|  | 2932 | return Err; | 
|  | 2933 |  | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2934 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2935 | ToFD->setFunctionTemplateSpecialization( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2936 | std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr, | 
|  | 2937 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr); | 
|  | 2938 | return Error::success(); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2939 | } | 
|  | 2940 |  | 
|  | 2941 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { | 
|  | 2942 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); | 
|  | 2943 | UnresolvedSet<8> TemplDecls; | 
|  | 2944 | unsigned NumTemplates = FromInfo->getNumTemplates(); | 
|  | 2945 | for (unsigned I = 0; I < NumTemplates; I++) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2946 | if (Expected<FunctionTemplateDecl *> ToFTDOrErr = | 
|  | 2947 | import(FromInfo->getTemplate(I))) | 
|  | 2948 | TemplDecls.addDecl(*ToFTDOrErr); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2949 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2950 | return ToFTDOrErr.takeError(); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2951 | } | 
|  | 2952 |  | 
|  | 2953 | // Import TemplateArgumentListInfo. | 
|  | 2954 | TemplateArgumentListInfo ToTAInfo; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2955 | if (Error Err = ImportTemplateArgumentListInfo( | 
|  | 2956 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), | 
|  | 2957 | llvm::makeArrayRef( | 
|  | 2958 | FromInfo->getTemplateArgs(), FromInfo->getNumTemplateArgs()), | 
|  | 2959 | ToTAInfo)) | 
|  | 2960 | return Err; | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2961 |  | 
|  | 2962 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), | 
|  | 2963 | TemplDecls, ToTAInfo); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2964 | return Error::success(); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2965 | } | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2966 | } | 
| Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2967 | llvm_unreachable("All cases should be covered!"); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2968 | } | 
|  | 2969 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2970 | Expected<FunctionDecl *> | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2971 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2972 | auto FunctionAndArgsOrErr = | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2973 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2974 | if (!FunctionAndArgsOrErr) | 
|  | 2975 | return FunctionAndArgsOrErr.takeError(); | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2976 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2977 | FunctionTemplateDecl *Template; | 
|  | 2978 | TemplateArgsTy ToTemplArgs; | 
|  | 2979 | std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr; | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2980 | void *InsertPos = nullptr; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2981 | auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos); | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2982 | return FoundSpec; | 
|  | 2983 | } | 
|  | 2984 |  | 
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 2985 | Error ASTNodeImporter::ImportFunctionDeclBody(FunctionDecl *FromFD, | 
|  | 2986 | FunctionDecl *ToFD) { | 
|  | 2987 | if (Stmt *FromBody = FromFD->getBody()) { | 
|  | 2988 | if (ExpectedStmt ToBodyOrErr = import(FromBody)) | 
|  | 2989 | ToFD->setBody(*ToBodyOrErr); | 
|  | 2990 | else | 
|  | 2991 | return ToBodyOrErr.takeError(); | 
|  | 2992 | } | 
|  | 2993 | return Error::success(); | 
|  | 2994 | } | 
|  | 2995 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2996 | ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2997 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2998 | SmallVector<Decl *, 2> Redecls = getCanonicalForwardRedeclChain(D); | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2999 | auto RedeclIt = Redecls.begin(); | 
|  | 3000 | // Import the first part of the decl chain. I.e. import all previous | 
|  | 3001 | // declarations starting from the canonical decl. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3002 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { | 
|  | 3003 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); | 
|  | 3004 | if (!ToRedeclOrErr) | 
|  | 3005 | return ToRedeclOrErr.takeError(); | 
|  | 3006 | } | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3007 | assert(*RedeclIt == D); | 
|  | 3008 |  | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3009 | // Import the major distinguishing characteristics of this function. | 
|  | 3010 | DeclContext *DC, *LexicalDC; | 
|  | 3011 | DeclarationName Name; | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3012 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3013 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3014 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 3015 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3016 | if (ToD) | 
|  | 3017 | return ToD; | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3018 |  | 
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3019 | FunctionDecl *FoundByLookup = nullptr; | 
| Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3020 | FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); | 
| Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 3021 |  | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3022 | // If this is a function template specialization, then try to find the same | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3023 | // existing specialization in the "to" context. The lookup below will not | 
|  | 3024 | // find any specialization, but would find the primary template; thus, we | 
|  | 3025 | // have to skip normal lookup in case of specializations. | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3026 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? | 
|  | 3027 | if (D->getTemplatedKind() == | 
|  | 3028 | FunctionDecl::TK_FunctionTemplateSpecialization) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3029 | auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D); | 
|  | 3030 | if (!FoundFunctionOrErr) | 
|  | 3031 | return FoundFunctionOrErr.takeError(); | 
|  | 3032 | if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) { | 
| Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 3033 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) | 
|  | 3034 | return Def; | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3035 | FoundByLookup = FoundFunction; | 
|  | 3036 | } | 
|  | 3037 | } | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3038 | // Try to find a function in our own ("to") context with the same name, same | 
|  | 3039 | // type, and in the same context as the function we're importing. | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3040 | else if (!LexicalDC->isFunctionOrMethod()) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3041 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3042 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3043 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3044 | for (auto *FoundDecl : FoundDecls) { | 
|  | 3045 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3046 | continue; | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3047 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3048 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3049 | if (!hasSameVisibilityContext(FoundFunction, D)) | 
|  | 3050 | continue; | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3051 |  | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3052 | if (IsStructuralMatch(D, FoundFunction)) { | 
| Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 3053 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) | 
|  | 3054 | return Def; | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3055 | FoundByLookup = FoundFunction; | 
|  | 3056 | break; | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3057 | } | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3058 | // FIXME: Check for overloading more carefully, e.g., by boosting | 
|  | 3059 | // Sema::IsOverload out to the AST library. | 
|  | 3060 |  | 
|  | 3061 | // Function overloading is okay in C++. | 
|  | 3062 | if (Importer.getToContext().getLangOpts().CPlusPlus) | 
|  | 3063 | continue; | 
|  | 3064 |  | 
|  | 3065 | // Complain about inconsistent function types. | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3066 | Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent) | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3067 | << Name << D->getType() << FoundFunction->getType(); | 
|  | 3068 | Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here) | 
|  | 3069 | << FoundFunction->getType(); | 
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 3070 | ConflictingDecls.push_back(FoundDecl); | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3071 | } | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3072 | } | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3073 |  | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3074 | if (!ConflictingDecls.empty()) { | 
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 3075 | ExpectedName NameOrErr = Importer.HandleNameConflict( | 
|  | 3076 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); | 
|  | 3077 | if (NameOrErr) | 
|  | 3078 | Name = NameOrErr.get(); | 
|  | 3079 | else | 
|  | 3080 | return NameOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3081 | } | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3082 | } | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3083 |  | 
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3084 | // We do not allow more than one in-class declaration of a function. This is | 
|  | 3085 | // because AST clients like VTableBuilder asserts on this. VTableBuilder | 
|  | 3086 | // assumes there is only one in-class declaration. Building a redecl | 
|  | 3087 | // chain would result in more than one in-class declaration for | 
|  | 3088 | // overrides (even if they are part of the same redecl chain inside the | 
|  | 3089 | // derived class.) | 
|  | 3090 | if (FoundByLookup) { | 
| Mikael Holmen | c1c97aa | 2019-01-29 06:53:31 +0000 | [diff] [blame] | 3091 | if (isa<CXXMethodDecl>(FoundByLookup)) { | 
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3092 | if (D->getLexicalDeclContext() == D->getDeclContext()) { | 
| Balazs Keri | e9719f9 | 2019-08-07 12:40:17 +0000 | [diff] [blame] | 3093 | if (!D->doesThisDeclarationHaveABody()) { | 
|  | 3094 | if (FunctionTemplateDecl *DescribedD = | 
|  | 3095 | D->getDescribedFunctionTemplate()) { | 
|  | 3096 | // Handle a "templated" function together with its described | 
|  | 3097 | // template. This avoids need for a similar check at import of the | 
|  | 3098 | // described template. | 
|  | 3099 | assert(FoundByLookup->getDescribedFunctionTemplate() && | 
|  | 3100 | "Templated function mapped to non-templated?"); | 
|  | 3101 | Importer.MapImported(DescribedD, | 
|  | 3102 | FoundByLookup->getDescribedFunctionTemplate()); | 
|  | 3103 | } | 
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3104 | return Importer.MapImported(D, FoundByLookup); | 
| Balazs Keri | e9719f9 | 2019-08-07 12:40:17 +0000 | [diff] [blame] | 3105 | } else { | 
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3106 | // Let's continue and build up the redecl chain in this case. | 
|  | 3107 | // FIXME Merge the functions into one decl. | 
|  | 3108 | } | 
|  | 3109 | } | 
|  | 3110 | } | 
|  | 3111 | } | 
|  | 3112 |  | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3113 | DeclarationNameInfo NameInfo(Name, Loc); | 
|  | 3114 | // Import additional name location/type info. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3115 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) | 
|  | 3116 | return std::move(Err); | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3117 |  | 
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3118 | QualType FromTy = D->getType(); | 
|  | 3119 | bool usedDifferentExceptionSpec = false; | 
|  | 3120 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3121 | if (const auto *FromFPT = D->getType()->getAs<FunctionProtoType>()) { | 
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3122 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); | 
|  | 3123 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the | 
|  | 3124 | // FunctionDecl that we are importing the FunctionProtoType for. | 
|  | 3125 | // To avoid an infinite recursion when importing, create the FunctionDecl | 
|  | 3126 | // with a simplified function type and update it afterwards. | 
| Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 3127 | if (FromEPI.ExceptionSpec.SourceDecl || | 
|  | 3128 | FromEPI.ExceptionSpec.SourceTemplate || | 
|  | 3129 | FromEPI.ExceptionSpec.NoexceptExpr) { | 
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3130 | FunctionProtoType::ExtProtoInfo DefaultEPI; | 
|  | 3131 | FromTy = Importer.getFromContext().getFunctionType( | 
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3132 | FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI); | 
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3133 | usedDifferentExceptionSpec = true; | 
|  | 3134 | } | 
|  | 3135 | } | 
|  | 3136 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3137 | QualType T; | 
|  | 3138 | TypeSourceInfo *TInfo; | 
|  | 3139 | SourceLocation ToInnerLocStart, ToEndLoc; | 
|  | 3140 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 3141 | if (auto Imp = importSeq( | 
|  | 3142 | FromTy, D->getTypeSourceInfo(), D->getInnerLocStart(), | 
|  | 3143 | D->getQualifierLoc(), D->getEndLoc())) | 
|  | 3144 | std::tie(T, TInfo, ToInnerLocStart, ToQualifierLoc, ToEndLoc) = *Imp; | 
|  | 3145 | else | 
|  | 3146 | return Imp.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3147 |  | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3148 | // Import the function parameters. | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3149 | SmallVector<ParmVarDecl *, 8> Parameters; | 
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3150 | for (auto P : D->parameters()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3151 | if (Expected<ParmVarDecl *> ToPOrErr = import(P)) | 
|  | 3152 | Parameters.push_back(*ToPOrErr); | 
|  | 3153 | else | 
|  | 3154 | return ToPOrErr.takeError(); | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3155 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3156 |  | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3157 | // Create the imported function. | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3158 | FunctionDecl *ToFunction = nullptr; | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3159 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { | 
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3160 | Expr *ExplicitExpr = nullptr; | 
|  | 3161 | if (FromConstructor->getExplicitSpecifier().getExpr()) { | 
|  | 3162 | auto Imp = importSeq(FromConstructor->getExplicitSpecifier().getExpr()); | 
|  | 3163 | if (!Imp) | 
|  | 3164 | return Imp.takeError(); | 
|  | 3165 | std::tie(ExplicitExpr) = *Imp; | 
|  | 3166 | } | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3167 | if (GetImportedOrCreateDecl<CXXConstructorDecl>( | 
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3168 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | 
|  | 3169 | ToInnerLocStart, NameInfo, T, TInfo, | 
|  | 3170 | ExplicitSpecifier( | 
|  | 3171 | ExplicitExpr, | 
|  | 3172 | FromConstructor->getExplicitSpecifier().getKind()), | 
| Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3173 | D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind())) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3174 | return ToFunction; | 
| Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3175 | } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) { | 
|  | 3176 |  | 
|  | 3177 | auto Imp = | 
|  | 3178 | importSeq(const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()), | 
|  | 3179 | FromDtor->getOperatorDeleteThisArg()); | 
|  | 3180 |  | 
|  | 3181 | if (!Imp) | 
|  | 3182 | return Imp.takeError(); | 
|  | 3183 |  | 
|  | 3184 | FunctionDecl *ToOperatorDelete; | 
|  | 3185 | Expr *ToThisArg; | 
|  | 3186 | std::tie(ToOperatorDelete, ToThisArg) = *Imp; | 
|  | 3187 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3188 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3189 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | 
|  | 3190 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), | 
| Richard Smith | 457226e | 2019-09-23 03:48:44 +0000 | [diff] [blame] | 3191 | D->isImplicit(), D->getConstexprKind())) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3192 | return ToFunction; | 
| Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3193 |  | 
|  | 3194 | CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction); | 
|  | 3195 |  | 
|  | 3196 | ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg); | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3197 | } else if (CXXConversionDecl *FromConversion = | 
|  | 3198 | dyn_cast<CXXConversionDecl>(D)) { | 
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3199 | Expr *ExplicitExpr = nullptr; | 
|  | 3200 | if (FromConversion->getExplicitSpecifier().getExpr()) { | 
|  | 3201 | auto Imp = importSeq(FromConversion->getExplicitSpecifier().getExpr()); | 
|  | 3202 | if (!Imp) | 
|  | 3203 | return Imp.takeError(); | 
|  | 3204 | std::tie(ExplicitExpr) = *Imp; | 
|  | 3205 | } | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3206 | if (GetImportedOrCreateDecl<CXXConversionDecl>( | 
|  | 3207 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3208 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), | 
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3209 | ExplicitSpecifier(ExplicitExpr, | 
|  | 3210 | FromConversion->getExplicitSpecifier().getKind()), | 
| Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3211 | D->getConstexprKind(), SourceLocation())) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3212 | return ToFunction; | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3213 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3214 | if (GetImportedOrCreateDecl<CXXMethodDecl>( | 
|  | 3215 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3216 | ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), | 
| Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3217 | Method->isInlineSpecified(), D->getConstexprKind(), | 
|  | 3218 | SourceLocation())) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3219 | return ToFunction; | 
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3220 | } else { | 
| Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3221 | if (GetImportedOrCreateDecl( | 
|  | 3222 | ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, | 
|  | 3223 | NameInfo, T, TInfo, D->getStorageClass(), D->isInlineSpecified(), | 
|  | 3224 | D->hasWrittenPrototype(), D->getConstexprKind())) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3225 | return ToFunction; | 
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3226 | } | 
| John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3227 |  | 
| Gabor Marton | f5e4f0a | 2018-11-20 14:19:39 +0000 | [diff] [blame] | 3228 | // Connect the redecl chain. | 
|  | 3229 | if (FoundByLookup) { | 
|  | 3230 | auto *Recent = const_cast<FunctionDecl *>( | 
|  | 3231 | FoundByLookup->getMostRecentDecl()); | 
|  | 3232 | ToFunction->setPreviousDecl(Recent); | 
| Gabor Marton | ce6b781 | 2019-05-08 15:23:48 +0000 | [diff] [blame] | 3233 | // FIXME Probably we should merge exception specifications.  E.g. In the | 
|  | 3234 | // "To" context the existing function may have exception specification with | 
|  | 3235 | // noexcept-unevaluated, while the newly imported function may have an | 
|  | 3236 | // evaluated noexcept.  A call to adjustExceptionSpec() on the imported | 
|  | 3237 | // decl and its redeclarations may be required. | 
| Gabor Marton | f5e4f0a | 2018-11-20 14:19:39 +0000 | [diff] [blame] | 3238 | } | 
|  | 3239 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3240 | ToFunction->setQualifierInfo(ToQualifierLoc); | 
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3241 | ToFunction->setAccess(D->getAccess()); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3242 | ToFunction->setLexicalDeclContext(LexicalDC); | 
| John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 3243 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); | 
|  | 3244 | ToFunction->setTrivial(D->isTrivial()); | 
|  | 3245 | ToFunction->setPure(D->isPure()); | 
| Balazs Keri | b427c06 | 2019-08-13 08:04:06 +0000 | [diff] [blame] | 3246 | ToFunction->setDefaulted(D->isDefaulted()); | 
|  | 3247 | ToFunction->setExplicitlyDefaulted(D->isExplicitlyDefaulted()); | 
|  | 3248 | ToFunction->setDeletedAsWritten(D->isDeletedAsWritten()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3249 | ToFunction->setRangeEnd(ToEndLoc); | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3250 |  | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3251 | // Set the parameters. | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3252 | for (auto *Param : Parameters) { | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3253 | Param->setOwningFunction(ToFunction); | 
|  | 3254 | ToFunction->addDeclInternal(Param); | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3255 | } | 
| David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 3256 | ToFunction->setParams(Parameters); | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3257 |  | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3258 | // We need to complete creation of FunctionProtoTypeLoc manually with setting | 
|  | 3259 | // params it refers to. | 
|  | 3260 | if (TInfo) { | 
|  | 3261 | if (auto ProtoLoc = | 
|  | 3262 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { | 
|  | 3263 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) | 
|  | 3264 | ProtoLoc.setParam(I, Parameters[I]); | 
|  | 3265 | } | 
|  | 3266 | } | 
|  | 3267 |  | 
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3268 | if (usedDifferentExceptionSpec) { | 
|  | 3269 | // Update FunctionProtoType::ExtProtoInfo. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3270 | if (ExpectedType TyOrErr = import(D->getType())) | 
|  | 3271 | ToFunction->setType(*TyOrErr); | 
|  | 3272 | else | 
|  | 3273 | return TyOrErr.takeError(); | 
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 3274 | } | 
|  | 3275 |  | 
| Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3276 | // Import the describing template function, if any. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3277 | if (FromFT) { | 
|  | 3278 | auto ToFTOrErr = import(FromFT); | 
|  | 3279 | if (!ToFTOrErr) | 
|  | 3280 | return ToFTOrErr.takeError(); | 
|  | 3281 | } | 
| Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3282 |  | 
| Balazs Keri | e13e836 | 2019-08-16 12:10:03 +0000 | [diff] [blame] | 3283 | // Import Ctor initializers. | 
|  | 3284 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { | 
|  | 3285 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { | 
|  | 3286 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers); | 
|  | 3287 | // Import first, then allocate memory and copy if there was no error. | 
|  | 3288 | if (Error Err = ImportContainerChecked( | 
|  | 3289 | FromConstructor->inits(), CtorInitializers)) | 
|  | 3290 | return std::move(Err); | 
|  | 3291 | auto **Memory = | 
|  | 3292 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; | 
|  | 3293 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); | 
|  | 3294 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); | 
|  | 3295 | ToCtor->setCtorInitializers(Memory); | 
|  | 3296 | ToCtor->setNumCtorInitializers(NumInitializers); | 
|  | 3297 | } | 
|  | 3298 | } | 
|  | 3299 |  | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3300 | if (D->doesThisDeclarationHaveABody()) { | 
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3301 | Error Err = ImportFunctionDeclBody(D, ToFunction); | 
|  | 3302 |  | 
|  | 3303 | if (Err) | 
|  | 3304 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3305 | } | 
|  | 3306 |  | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3307 | // FIXME: Other bits to merge? | 
| Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3308 |  | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3309 | // If it is a template, import all related things. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3310 | if (Error Err = ImportTemplateInformation(D, ToFunction)) | 
|  | 3311 | return std::move(Err); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3312 |  | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3313 | bool IsFriend = D->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend); | 
|  | 3314 |  | 
|  | 3315 | // TODO Can we generalize this approach to other AST nodes as well? | 
|  | 3316 | if (D->getDeclContext()->containsDeclAndLoad(D)) | 
|  | 3317 | DC->addDeclInternal(ToFunction); | 
|  | 3318 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3319 | LexicalDC->addDeclInternal(ToFunction); | 
| Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3320 |  | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3321 | // Friend declaration's lexical context is the befriending class, but the | 
|  | 3322 | // semantic context is the enclosing scope of the befriending class. | 
|  | 3323 | // We want the friend functions to be found in the semantic context by lookup. | 
|  | 3324 | // FIXME should we handle this generically in VisitFriendDecl? | 
|  | 3325 | // In Other cases when LexicalDC != DC we don't want it to be added, | 
|  | 3326 | // e.g out-of-class definitions like void B::f() {} . | 
|  | 3327 | if (LexicalDC != DC && IsFriend) { | 
|  | 3328 | DC->makeDeclVisibleInContext(ToFunction); | 
|  | 3329 | } | 
|  | 3330 |  | 
| Gabor Marton | 7a0841e | 2018-10-29 10:18:28 +0000 | [diff] [blame] | 3331 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) | 
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 3332 | if (Error Err = ImportOverriddenMethods(cast<CXXMethodDecl>(ToFunction), | 
|  | 3333 | FromCXXMethod)) | 
|  | 3334 | return std::move(Err); | 
| Gabor Marton | 7a0841e | 2018-10-29 10:18:28 +0000 | [diff] [blame] | 3335 |  | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3336 | // Import the rest of the chain. I.e. import all subsequent declarations. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3337 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { | 
|  | 3338 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); | 
|  | 3339 | if (!ToRedeclOrErr) | 
|  | 3340 | return ToRedeclOrErr.takeError(); | 
|  | 3341 | } | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3342 |  | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3343 | return ToFunction; | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3344 | } | 
|  | 3345 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3346 | ExpectedDecl ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { | 
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3347 | return VisitFunctionDecl(D); | 
|  | 3348 | } | 
|  | 3349 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3350 | ExpectedDecl ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { | 
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3351 | return VisitCXXMethodDecl(D); | 
|  | 3352 | } | 
|  | 3353 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3354 | ExpectedDecl ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { | 
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3355 | return VisitCXXMethodDecl(D); | 
|  | 3356 | } | 
|  | 3357 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3358 | ExpectedDecl ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { | 
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3359 | return VisitCXXMethodDecl(D); | 
|  | 3360 | } | 
|  | 3361 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3362 | ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3363 | // Import the major distinguishing characteristics of a variable. | 
|  | 3364 | DeclContext *DC, *LexicalDC; | 
|  | 3365 | DeclarationName Name; | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3366 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3367 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3368 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 3369 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3370 | if (ToD) | 
|  | 3371 | return ToD; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3372 |  | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3373 | // Determine whether we've already imported this field. | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3374 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3375 | for (auto *FoundDecl : FoundDecls) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3376 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { | 
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3377 | // For anonymous fields, match up by index. | 
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3378 | if (!Name && | 
|  | 3379 | ASTImporter::getFieldIndex(D) != | 
|  | 3380 | ASTImporter::getFieldIndex(FoundField)) | 
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3381 | continue; | 
|  | 3382 |  | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3383 | if (Importer.IsStructurallyEquivalent(D->getType(), | 
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3384 | FoundField->getType())) { | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3385 | Importer.MapImported(D, FoundField); | 
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3386 | // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the | 
|  | 3387 | // initializer of a FieldDecl might not had been instantiated in the | 
|  | 3388 | // "To" context.  However, the "From" context might instantiated that, | 
|  | 3389 | // thus we have to merge that. | 
|  | 3390 | if (Expr *FromInitializer = D->getInClassInitializer()) { | 
|  | 3391 | // We don't have yet the initializer set. | 
|  | 3392 | if (FoundField->hasInClassInitializer() && | 
|  | 3393 | !FoundField->getInClassInitializer()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3394 | if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) | 
|  | 3395 | FoundField->setInClassInitializer(*ToInitializerOrErr); | 
|  | 3396 | else { | 
|  | 3397 | // We can't return error here, | 
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3398 | // since we already mapped D as imported. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3399 | // FIXME: warning message? | 
|  | 3400 | consumeError(ToInitializerOrErr.takeError()); | 
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3401 | return FoundField; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3402 | } | 
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3403 | } | 
|  | 3404 | } | 
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3405 | return FoundField; | 
|  | 3406 | } | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3407 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3408 | // FIXME: Why is this case not handled with calling HandleNameConflict? | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3409 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) | 
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3410 | << Name << D->getType() << FoundField->getType(); | 
|  | 3411 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) | 
|  | 3412 | << FoundField->getType(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3413 |  | 
|  | 3414 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3415 | } | 
|  | 3416 | } | 
|  | 3417 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3418 | QualType ToType; | 
|  | 3419 | TypeSourceInfo *ToTInfo; | 
|  | 3420 | Expr *ToBitWidth; | 
|  | 3421 | SourceLocation ToInnerLocStart; | 
|  | 3422 | Expr *ToInitializer; | 
|  | 3423 | if (auto Imp = importSeq( | 
|  | 3424 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), | 
|  | 3425 | D->getInnerLocStart(), D->getInClassInitializer())) | 
|  | 3426 | std::tie( | 
|  | 3427 | ToType, ToTInfo, ToBitWidth, ToInnerLocStart, ToInitializer) = *Imp; | 
|  | 3428 | else | 
|  | 3429 | return Imp.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3430 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3431 | FieldDecl *ToField; | 
|  | 3432 | if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3433 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), | 
|  | 3434 | ToType, ToTInfo, ToBitWidth, D->isMutable(), | 
|  | 3435 | D->getInClassInitStyle())) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3436 | return ToField; | 
|  | 3437 |  | 
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3438 | ToField->setAccess(D->getAccess()); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3439 | ToField->setLexicalDeclContext(LexicalDC); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3440 | if (ToInitializer) | 
|  | 3441 | ToField->setInClassInitializer(ToInitializer); | 
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3442 | ToField->setImplicit(D->isImplicit()); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3443 | LexicalDC->addDeclInternal(ToField); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3444 | return ToField; | 
|  | 3445 | } | 
|  | 3446 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3447 | ExpectedDecl ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { | 
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3448 | // Import the major distinguishing characteristics of a variable. | 
|  | 3449 | DeclContext *DC, *LexicalDC; | 
|  | 3450 | DeclarationName Name; | 
|  | 3451 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3452 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3453 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 3454 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3455 | if (ToD) | 
|  | 3456 | return ToD; | 
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3457 |  | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3458 | // Determine whether we've already imported this field. | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3459 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3460 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3461 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { | 
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3462 | // For anonymous indirect fields, match up by index. | 
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3463 | if (!Name && | 
|  | 3464 | ASTImporter::getFieldIndex(D) != | 
|  | 3465 | ASTImporter::getFieldIndex(FoundField)) | 
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3466 | continue; | 
|  | 3467 |  | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3468 | if (Importer.IsStructurallyEquivalent(D->getType(), | 
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3469 | FoundField->getType(), | 
| David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 3470 | !Name.isEmpty())) { | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3471 | Importer.MapImported(D, FoundField); | 
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3472 | return FoundField; | 
|  | 3473 | } | 
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3474 |  | 
|  | 3475 | // If there are more anonymous fields to check, continue. | 
|  | 3476 | if (!Name && I < N-1) | 
|  | 3477 | continue; | 
|  | 3478 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3479 | // FIXME: Why is this case not handled with calling HandleNameConflict? | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3480 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) | 
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3481 | << Name << D->getType() << FoundField->getType(); | 
|  | 3482 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) | 
|  | 3483 | << FoundField->getType(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3484 |  | 
|  | 3485 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3486 | } | 
|  | 3487 | } | 
|  | 3488 |  | 
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3489 | // Import the type. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3490 | auto TypeOrErr = import(D->getType()); | 
|  | 3491 | if (!TypeOrErr) | 
|  | 3492 | return TypeOrErr.takeError(); | 
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3493 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3494 | auto **NamedChain = | 
|  | 3495 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; | 
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3496 |  | 
|  | 3497 | unsigned i = 0; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3498 | for (auto *PI : D->chain()) | 
|  | 3499 | if (Expected<NamedDecl *> ToD = import(PI)) | 
|  | 3500 | NamedChain[i++] = *ToD; | 
|  | 3501 | else | 
|  | 3502 | return ToD.takeError(); | 
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3503 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3504 | llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()}; | 
|  | 3505 | IndirectFieldDecl *ToIndirectField; | 
|  | 3506 | if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3507 | Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3508 | // FIXME here we leak `NamedChain` which is allocated before | 
|  | 3509 | return ToIndirectField; | 
| Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 3510 |  | 
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3511 | ToIndirectField->setAccess(D->getAccess()); | 
|  | 3512 | ToIndirectField->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3513 | LexicalDC->addDeclInternal(ToIndirectField); | 
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3514 | return ToIndirectField; | 
|  | 3515 | } | 
|  | 3516 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3517 | ExpectedDecl ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3518 | // Import the major distinguishing characteristics of a declaration. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3519 | DeclContext *DC, *LexicalDC; | 
|  | 3520 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | 
|  | 3521 | return std::move(Err); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3522 |  | 
|  | 3523 | // Determine whether we've already imported this decl. | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3524 | // FriendDecl is not a NamedDecl so we cannot use lookup. | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3525 | auto *RD = cast<CXXRecordDecl>(DC); | 
|  | 3526 | FriendDecl *ImportedFriend = RD->getFirstFriend(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3527 |  | 
|  | 3528 | while (ImportedFriend) { | 
|  | 3529 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { | 
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 3530 | if (IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(), | 
|  | 3531 | /*Complain=*/false)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3532 | return Importer.MapImported(D, ImportedFriend); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3533 |  | 
|  | 3534 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { | 
|  | 3535 | if (Importer.IsStructurallyEquivalent( | 
|  | 3536 | D->getFriendType()->getType(), | 
|  | 3537 | ImportedFriend->getFriendType()->getType(), true)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3538 | return Importer.MapImported(D, ImportedFriend); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3539 | } | 
|  | 3540 | ImportedFriend = ImportedFriend->getNextFriend(); | 
|  | 3541 | } | 
|  | 3542 |  | 
|  | 3543 | // Not found. Create it. | 
|  | 3544 | FriendDecl::FriendUnion ToFU; | 
| Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3545 | if (NamedDecl *FriendD = D->getFriendDecl()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3546 | NamedDecl *ToFriendD; | 
|  | 3547 | if (Error Err = importInto(ToFriendD, FriendD)) | 
|  | 3548 | return std::move(Err); | 
|  | 3549 |  | 
|  | 3550 | if (FriendD->getFriendObjectKind() != Decl::FOK_None && | 
| Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3551 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) | 
|  | 3552 | ToFriendD->setObjectOfFriendDecl(false); | 
|  | 3553 |  | 
|  | 3554 | ToFU = ToFriendD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3555 | } else { // The friend is a type, not a decl. | 
|  | 3556 | if (auto TSIOrErr = import(D->getFriendType())) | 
|  | 3557 | ToFU = *TSIOrErr; | 
|  | 3558 | else | 
|  | 3559 | return TSIOrErr.takeError(); | 
|  | 3560 | } | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3561 |  | 
|  | 3562 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3563 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3564 | for (unsigned I = 0; I < D->NumTPLists; I++) { | 
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 3565 | if (auto ListOrErr = import(FromTPLists[I])) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3566 | ToTPLists[I] = *ListOrErr; | 
|  | 3567 | else | 
|  | 3568 | return ListOrErr.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3569 | } | 
|  | 3570 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3571 | auto LocationOrErr = import(D->getLocation()); | 
|  | 3572 | if (!LocationOrErr) | 
|  | 3573 | return LocationOrErr.takeError(); | 
|  | 3574 | auto FriendLocOrErr = import(D->getFriendLoc()); | 
|  | 3575 | if (!FriendLocOrErr) | 
|  | 3576 | return FriendLocOrErr.takeError(); | 
|  | 3577 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3578 | FriendDecl *FrD; | 
|  | 3579 | if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3580 | *LocationOrErr, ToFU, | 
|  | 3581 | *FriendLocOrErr, ToTPLists)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3582 | return FrD; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3583 |  | 
|  | 3584 | FrD->setAccess(D->getAccess()); | 
|  | 3585 | FrD->setLexicalDeclContext(LexicalDC); | 
|  | 3586 | LexicalDC->addDeclInternal(FrD); | 
|  | 3587 | return FrD; | 
|  | 3588 | } | 
|  | 3589 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3590 | ExpectedDecl ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3591 | // Import the major distinguishing characteristics of an ivar. | 
|  | 3592 | DeclContext *DC, *LexicalDC; | 
|  | 3593 | DeclarationName Name; | 
|  | 3594 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3595 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3596 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 3597 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3598 | if (ToD) | 
|  | 3599 | return ToD; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3600 |  | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3601 | // Determine whether we've already imported this ivar | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3602 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3603 | for (auto *FoundDecl : FoundDecls) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3604 | if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3605 | if (Importer.IsStructurallyEquivalent(D->getType(), | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3606 | FoundIvar->getType())) { | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3607 | Importer.MapImported(D, FoundIvar); | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3608 | return FoundIvar; | 
|  | 3609 | } | 
|  | 3610 |  | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3611 | Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent) | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3612 | << Name << D->getType() << FoundIvar->getType(); | 
|  | 3613 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) | 
|  | 3614 | << FoundIvar->getType(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3615 |  | 
|  | 3616 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3617 | } | 
|  | 3618 | } | 
|  | 3619 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3620 | QualType ToType; | 
|  | 3621 | TypeSourceInfo *ToTypeSourceInfo; | 
|  | 3622 | Expr *ToBitWidth; | 
|  | 3623 | SourceLocation ToInnerLocStart; | 
|  | 3624 | if (auto Imp = importSeq( | 
|  | 3625 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), D->getInnerLocStart())) | 
|  | 3626 | std::tie(ToType, ToTypeSourceInfo, ToBitWidth, ToInnerLocStart) = *Imp; | 
|  | 3627 | else | 
|  | 3628 | return Imp.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3629 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3630 | ObjCIvarDecl *ToIvar; | 
|  | 3631 | if (GetImportedOrCreateDecl( | 
|  | 3632 | ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3633 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), | 
|  | 3634 | ToType, ToTypeSourceInfo, | 
|  | 3635 | D->getAccessControl(),ToBitWidth, D->getSynthesize())) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3636 | return ToIvar; | 
|  | 3637 |  | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3638 | ToIvar->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3639 | LexicalDC->addDeclInternal(ToIvar); | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3640 | return ToIvar; | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3641 | } | 
|  | 3642 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3643 | ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) { | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3644 |  | 
|  | 3645 | SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D); | 
|  | 3646 | auto RedeclIt = Redecls.begin(); | 
|  | 3647 | // Import the first part of the decl chain. I.e. import all previous | 
|  | 3648 | // declarations starting from the canonical decl. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3649 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { | 
|  | 3650 | ExpectedDecl RedeclOrErr = import(*RedeclIt); | 
|  | 3651 | if (!RedeclOrErr) | 
|  | 3652 | return RedeclOrErr.takeError(); | 
|  | 3653 | } | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3654 | assert(*RedeclIt == D); | 
|  | 3655 |  | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3656 | // Import the major distinguishing characteristics of a variable. | 
|  | 3657 | DeclContext *DC, *LexicalDC; | 
|  | 3658 | DeclarationName Name; | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3659 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3660 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3661 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 3662 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3663 | if (ToD) | 
|  | 3664 | return ToD; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3665 |  | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3666 | // Try to find a variable in our own ("to") context with the same name and | 
|  | 3667 | // in the same context as the variable we're importing. | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3668 | VarDecl *FoundByLookup = nullptr; | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3669 | if (D->isFileVarDecl()) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3670 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3671 | unsigned IDNS = Decl::IDNS_Ordinary; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3672 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3673 | for (auto *FoundDecl : FoundDecls) { | 
|  | 3674 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3675 | continue; | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3676 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3677 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3678 | if (!hasSameVisibilityContext(FoundVar, D)) | 
|  | 3679 | continue; | 
|  | 3680 | if (Importer.IsStructurallyEquivalent(D->getType(), | 
|  | 3681 | FoundVar->getType())) { | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3682 |  | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3683 | // The VarDecl in the "From" context has a definition, but in the | 
|  | 3684 | // "To" context we already have a definition. | 
|  | 3685 | VarDecl *FoundDef = FoundVar->getDefinition(); | 
|  | 3686 | if (D->isThisDeclarationADefinition() && FoundDef) | 
|  | 3687 | // FIXME Check for ODR error if the two definitions have | 
|  | 3688 | // different initializers? | 
|  | 3689 | return Importer.MapImported(D, FoundDef); | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3690 |  | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3691 | // The VarDecl in the "From" context has an initializer, but in the | 
|  | 3692 | // "To" context we already have an initializer. | 
|  | 3693 | const VarDecl *FoundDInit = nullptr; | 
|  | 3694 | if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit)) | 
|  | 3695 | // FIXME Diagnose ODR error if the two initializers are different? | 
|  | 3696 | return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit)); | 
|  | 3697 |  | 
|  | 3698 | FoundByLookup = FoundVar; | 
|  | 3699 | break; | 
|  | 3700 | } | 
|  | 3701 |  | 
|  | 3702 | const ArrayType *FoundArray | 
|  | 3703 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); | 
|  | 3704 | const ArrayType *TArray | 
|  | 3705 | = Importer.getToContext().getAsArrayType(D->getType()); | 
|  | 3706 | if (FoundArray && TArray) { | 
|  | 3707 | if (isa<IncompleteArrayType>(FoundArray) && | 
|  | 3708 | isa<ConstantArrayType>(TArray)) { | 
|  | 3709 | // Import the type. | 
|  | 3710 | if (auto TyOrErr = import(D->getType())) | 
|  | 3711 | FoundVar->setType(*TyOrErr); | 
|  | 3712 | else | 
|  | 3713 | return TyOrErr.takeError(); | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3714 |  | 
|  | 3715 | FoundByLookup = FoundVar; | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3716 | break; | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3717 | } else if (isa<IncompleteArrayType>(TArray) && | 
|  | 3718 | isa<ConstantArrayType>(FoundArray)) { | 
|  | 3719 | FoundByLookup = FoundVar; | 
|  | 3720 | break; | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3721 | } | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3722 | } | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3723 |  | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3724 | Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent) | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3725 | << Name << D->getType() << FoundVar->getType(); | 
|  | 3726 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) | 
|  | 3727 | << FoundVar->getType(); | 
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 3728 | ConflictingDecls.push_back(FoundDecl); | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3729 | } | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3730 | } | 
|  | 3731 |  | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3732 | if (!ConflictingDecls.empty()) { | 
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 3733 | ExpectedName NameOrErr = Importer.HandleNameConflict( | 
|  | 3734 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); | 
|  | 3735 | if (NameOrErr) | 
|  | 3736 | Name = NameOrErr.get(); | 
|  | 3737 | else | 
|  | 3738 | return NameOrErr.takeError(); | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3739 | } | 
|  | 3740 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3741 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3742 | QualType ToType; | 
|  | 3743 | TypeSourceInfo *ToTypeSourceInfo; | 
|  | 3744 | SourceLocation ToInnerLocStart; | 
|  | 3745 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 3746 | if (auto Imp = importSeq( | 
|  | 3747 | D->getType(), D->getTypeSourceInfo(), D->getInnerLocStart(), | 
|  | 3748 | D->getQualifierLoc())) | 
|  | 3749 | std::tie(ToType, ToTypeSourceInfo, ToInnerLocStart, ToQualifierLoc) = *Imp; | 
|  | 3750 | else | 
|  | 3751 | return Imp.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3752 |  | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3753 | // Create the imported variable. | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3754 | VarDecl *ToVar; | 
|  | 3755 | if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3756 | ToInnerLocStart, Loc, | 
|  | 3757 | Name.getAsIdentifierInfo(), | 
|  | 3758 | ToType, ToTypeSourceInfo, | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3759 | D->getStorageClass())) | 
|  | 3760 | return ToVar; | 
|  | 3761 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3762 | ToVar->setQualifierInfo(ToQualifierLoc); | 
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3763 | ToVar->setAccess(D->getAccess()); | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3764 | ToVar->setLexicalDeclContext(LexicalDC); | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3765 |  | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3766 | if (FoundByLookup) { | 
|  | 3767 | auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl()); | 
|  | 3768 | ToVar->setPreviousDecl(Recent); | 
|  | 3769 | } | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3770 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3771 | if (Error Err = ImportInitializer(D, ToVar)) | 
|  | 3772 | return std::move(Err); | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3773 |  | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3774 | if (D->isConstexpr()) | 
|  | 3775 | ToVar->setConstexpr(true); | 
|  | 3776 |  | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3777 | if (D->getDeclContext()->containsDeclAndLoad(D)) | 
|  | 3778 | DC->addDeclInternal(ToVar); | 
|  | 3779 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) | 
|  | 3780 | LexicalDC->addDeclInternal(ToVar); | 
|  | 3781 |  | 
|  | 3782 | // Import the rest of the chain. I.e. import all subsequent declarations. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3783 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { | 
|  | 3784 | ExpectedDecl RedeclOrErr = import(*RedeclIt); | 
|  | 3785 | if (!RedeclOrErr) | 
|  | 3786 | return RedeclOrErr.takeError(); | 
|  | 3787 | } | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3788 |  | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3789 | return ToVar; | 
|  | 3790 | } | 
|  | 3791 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3792 | ExpectedDecl ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { | 
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3793 | // Parameters are created in the translation unit's context, then moved | 
|  | 3794 | // into the function declaration's context afterward. | 
|  | 3795 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3796 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3797 | DeclarationName ToDeclName; | 
|  | 3798 | SourceLocation ToLocation; | 
|  | 3799 | QualType ToType; | 
|  | 3800 | if (auto Imp = importSeq(D->getDeclName(), D->getLocation(), D->getType())) | 
|  | 3801 | std::tie(ToDeclName, ToLocation, ToType) = *Imp; | 
|  | 3802 | else | 
|  | 3803 | return Imp.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3804 |  | 
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3805 | // Create the imported parameter. | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3806 | ImplicitParamDecl *ToParm = nullptr; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3807 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, | 
|  | 3808 | ToLocation, ToDeclName.getAsIdentifierInfo(), | 
|  | 3809 | ToType, D->getParameterKind())) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3810 | return ToParm; | 
|  | 3811 | return ToParm; | 
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3812 | } | 
|  | 3813 |  | 
| Balazs Keri | c509594 | 2019-08-14 09:41:39 +0000 | [diff] [blame] | 3814 | Error ASTNodeImporter::ImportDefaultArgOfParmVarDecl( | 
|  | 3815 | const ParmVarDecl *FromParam, ParmVarDecl *ToParam) { | 
|  | 3816 | ToParam->setHasInheritedDefaultArg(FromParam->hasInheritedDefaultArg()); | 
|  | 3817 | ToParam->setKNRPromoted(FromParam->isKNRPromoted()); | 
|  | 3818 |  | 
|  | 3819 | if (FromParam->hasUninstantiatedDefaultArg()) { | 
|  | 3820 | if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg())) | 
|  | 3821 | ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr); | 
|  | 3822 | else | 
|  | 3823 | return ToDefArgOrErr.takeError(); | 
|  | 3824 | } else if (FromParam->hasUnparsedDefaultArg()) { | 
|  | 3825 | ToParam->setUnparsedDefaultArg(); | 
|  | 3826 | } else if (FromParam->hasDefaultArg()) { | 
|  | 3827 | if (auto ToDefArgOrErr = import(FromParam->getDefaultArg())) | 
|  | 3828 | ToParam->setDefaultArg(*ToDefArgOrErr); | 
|  | 3829 | else | 
|  | 3830 | return ToDefArgOrErr.takeError(); | 
|  | 3831 | } | 
|  | 3832 |  | 
|  | 3833 | return Error::success(); | 
|  | 3834 | } | 
|  | 3835 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3836 | ExpectedDecl ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3837 | // Parameters are created in the translation unit's context, then moved | 
|  | 3838 | // into the function declaration's context afterward. | 
|  | 3839 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3840 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3841 | DeclarationName ToDeclName; | 
|  | 3842 | SourceLocation ToLocation, ToInnerLocStart; | 
|  | 3843 | QualType ToType; | 
|  | 3844 | TypeSourceInfo *ToTypeSourceInfo; | 
|  | 3845 | if (auto Imp = importSeq( | 
|  | 3846 | D->getDeclName(), D->getLocation(), D->getType(), D->getInnerLocStart(), | 
|  | 3847 | D->getTypeSourceInfo())) | 
|  | 3848 | std::tie( | 
|  | 3849 | ToDeclName, ToLocation, ToType, ToInnerLocStart, | 
|  | 3850 | ToTypeSourceInfo) = *Imp; | 
|  | 3851 | else | 
|  | 3852 | return Imp.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3853 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3854 | ParmVarDecl *ToParm; | 
|  | 3855 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3856 | ToInnerLocStart, ToLocation, | 
|  | 3857 | ToDeclName.getAsIdentifierInfo(), ToType, | 
|  | 3858 | ToTypeSourceInfo, D->getStorageClass(), | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3859 | /*DefaultArg*/ nullptr)) | 
|  | 3860 | return ToParm; | 
| Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3861 |  | 
| Balazs Keri | c509594 | 2019-08-14 09:41:39 +0000 | [diff] [blame] | 3862 | // Set the default argument. It should be no problem if it was already done. | 
|  | 3863 | // Do not import the default expression before GetImportedOrCreateDecl call | 
|  | 3864 | // to avoid possible infinite import loop because circular dependency. | 
|  | 3865 | if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm)) | 
|  | 3866 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3867 |  | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3868 | if (D->isObjCMethodParameter()) { | 
|  | 3869 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); | 
|  | 3870 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); | 
|  | 3871 | } else { | 
|  | 3872 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), | 
|  | 3873 | D->getFunctionScopeIndex()); | 
|  | 3874 | } | 
|  | 3875 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3876 | return ToParm; | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3877 | } | 
|  | 3878 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3879 | ExpectedDecl ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3880 | // Import the major distinguishing characteristics of a method. | 
|  | 3881 | DeclContext *DC, *LexicalDC; | 
|  | 3882 | DeclarationName Name; | 
|  | 3883 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3884 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3885 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 3886 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3887 | if (ToD) | 
|  | 3888 | return ToD; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3889 |  | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3890 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3891 | for (auto *FoundDecl : FoundDecls) { | 
|  | 3892 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3893 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) | 
|  | 3894 | continue; | 
|  | 3895 |  | 
|  | 3896 | // Check return types. | 
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3897 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), | 
|  | 3898 | FoundMethod->getReturnType())) { | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3899 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent) | 
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3900 | << D->isInstanceMethod() << Name << D->getReturnType() | 
|  | 3901 | << FoundMethod->getReturnType(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3902 | Importer.ToDiag(FoundMethod->getLocation(), | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3903 | diag::note_odr_objc_method_here) | 
|  | 3904 | << D->isInstanceMethod() << Name; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3905 |  | 
|  | 3906 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3907 | } | 
|  | 3908 |  | 
|  | 3909 | // Check the number of parameters. | 
|  | 3910 | if (D->param_size() != FoundMethod->param_size()) { | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3911 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent) | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3912 | << D->isInstanceMethod() << Name | 
|  | 3913 | << D->param_size() << FoundMethod->param_size(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3914 | Importer.ToDiag(FoundMethod->getLocation(), | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3915 | diag::note_odr_objc_method_here) | 
|  | 3916 | << D->isInstanceMethod() << Name; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3917 |  | 
|  | 3918 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3919 | } | 
|  | 3920 |  | 
|  | 3921 | // Check parameter types. | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3922 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3923 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); | 
|  | 3924 | P != PEnd; ++P, ++FoundP) { | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3925 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3926 | (*FoundP)->getType())) { | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3927 | Importer.FromDiag((*P)->getLocation(), | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3928 | diag::warn_odr_objc_method_param_type_inconsistent) | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3929 | << D->isInstanceMethod() << Name | 
|  | 3930 | << (*P)->getType() << (*FoundP)->getType(); | 
|  | 3931 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) | 
|  | 3932 | << (*FoundP)->getType(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3933 |  | 
|  | 3934 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3935 | } | 
|  | 3936 | } | 
|  | 3937 |  | 
|  | 3938 | // Check variadic/non-variadic. | 
|  | 3939 | // Check the number of parameters. | 
|  | 3940 | if (D->isVariadic() != FoundMethod->isVariadic()) { | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3941 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent) | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3942 | << D->isInstanceMethod() << Name; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3943 | Importer.ToDiag(FoundMethod->getLocation(), | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3944 | diag::note_odr_objc_method_here) | 
|  | 3945 | << D->isInstanceMethod() << Name; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3946 |  | 
|  | 3947 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3948 | } | 
|  | 3949 |  | 
|  | 3950 | // FIXME: Any other bits we need to merge? | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3951 | return Importer.MapImported(D, FoundMethod); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3952 | } | 
|  | 3953 | } | 
|  | 3954 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3955 | SourceLocation ToEndLoc; | 
|  | 3956 | QualType ToReturnType; | 
|  | 3957 | TypeSourceInfo *ToReturnTypeSourceInfo; | 
|  | 3958 | if (auto Imp = importSeq( | 
|  | 3959 | D->getEndLoc(), D->getReturnType(), D->getReturnTypeSourceInfo())) | 
|  | 3960 | std::tie(ToEndLoc, ToReturnType, ToReturnTypeSourceInfo) = *Imp; | 
|  | 3961 | else | 
|  | 3962 | return Imp.takeError(); | 
| Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 3963 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3964 | ObjCMethodDecl *ToMethod; | 
|  | 3965 | if (GetImportedOrCreateDecl( | 
| Adrian Prantl | 2073dd2 | 2019-11-04 14:28:14 -0800 | [diff] [blame] | 3966 | ToMethod, D, Importer.getToContext(), Loc, ToEndLoc, | 
|  | 3967 | Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC, | 
|  | 3968 | D->isInstanceMethod(), D->isVariadic(), D->isPropertyAccessor(), | 
|  | 3969 | D->isSynthesizedAccessorStub(), D->isImplicit(), D->isDefined(), | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3970 | D->getImplementationControl(), D->hasRelatedResultType())) | 
|  | 3971 | return ToMethod; | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3972 |  | 
|  | 3973 | // FIXME: When we decide to merge method definitions, we'll need to | 
|  | 3974 | // deal with implicit parameters. | 
|  | 3975 |  | 
|  | 3976 | // Import the parameters | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3977 | SmallVector<ParmVarDecl *, 5> ToParams; | 
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3978 | for (auto *FromP : D->parameters()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3979 | if (Expected<ParmVarDecl *> ToPOrErr = import(FromP)) | 
|  | 3980 | ToParams.push_back(*ToPOrErr); | 
|  | 3981 | else | 
|  | 3982 | return ToPOrErr.takeError(); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3983 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3984 |  | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3985 | // Set the parameters. | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3986 | for (auto *ToParam : ToParams) { | 
|  | 3987 | ToParam->setOwningFunction(ToMethod); | 
|  | 3988 | ToMethod->addDeclInternal(ToParam); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3989 | } | 
| Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3990 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3991 | SmallVector<SourceLocation, 12> FromSelLocs; | 
|  | 3992 | D->getSelectorLocs(FromSelLocs); | 
|  | 3993 | SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size()); | 
|  | 3994 | if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs)) | 
|  | 3995 | return std::move(Err); | 
| Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3996 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3997 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3998 |  | 
|  | 3999 | ToMethod->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4000 | LexicalDC->addDeclInternal(ToMethod); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4001 | return ToMethod; | 
|  | 4002 | } | 
|  | 4003 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4004 | ExpectedDecl ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { | 
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4005 | // Import the major distinguishing characteristics of a category. | 
|  | 4006 | DeclContext *DC, *LexicalDC; | 
|  | 4007 | DeclarationName Name; | 
|  | 4008 | SourceLocation Loc; | 
|  | 4009 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4010 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 4011 | return std::move(Err); | 
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4012 | if (ToD) | 
|  | 4013 | return ToD; | 
|  | 4014 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4015 | SourceLocation ToVarianceLoc, ToLocation, ToColonLoc; | 
|  | 4016 | TypeSourceInfo *ToTypeSourceInfo; | 
|  | 4017 | if (auto Imp = importSeq( | 
|  | 4018 | D->getVarianceLoc(), D->getLocation(), D->getColonLoc(), | 
|  | 4019 | D->getTypeSourceInfo())) | 
|  | 4020 | std::tie(ToVarianceLoc, ToLocation, ToColonLoc, ToTypeSourceInfo) = *Imp; | 
|  | 4021 | else | 
|  | 4022 | return Imp.takeError(); | 
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4023 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4024 | ObjCTypeParamDecl *Result; | 
|  | 4025 | if (GetImportedOrCreateDecl( | 
|  | 4026 | Result, D, Importer.getToContext(), DC, D->getVariance(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4027 | ToVarianceLoc, D->getIndex(), | 
|  | 4028 | ToLocation, Name.getAsIdentifierInfo(), | 
|  | 4029 | ToColonLoc, ToTypeSourceInfo)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4030 | return Result; | 
|  | 4031 |  | 
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4032 | Result->setLexicalDeclContext(LexicalDC); | 
|  | 4033 | return Result; | 
|  | 4034 | } | 
|  | 4035 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4036 | ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4037 | // Import the major distinguishing characteristics of a category. | 
|  | 4038 | DeclContext *DC, *LexicalDC; | 
|  | 4039 | DeclarationName Name; | 
|  | 4040 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4041 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4042 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 4043 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4044 | if (ToD) | 
|  | 4045 | return ToD; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4046 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4047 | ObjCInterfaceDecl *ToInterface; | 
|  | 4048 | if (Error Err = importInto(ToInterface, D->getClassInterface())) | 
|  | 4049 | return std::move(Err); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4050 |  | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4051 | // Determine if we've already encountered this category. | 
|  | 4052 | ObjCCategoryDecl *MergeWithCategory | 
|  | 4053 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); | 
|  | 4054 | ObjCCategoryDecl *ToCategory = MergeWithCategory; | 
|  | 4055 | if (!ToCategory) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4056 | SourceLocation ToAtStartLoc, ToCategoryNameLoc; | 
|  | 4057 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; | 
|  | 4058 | if (auto Imp = importSeq( | 
|  | 4059 | D->getAtStartLoc(), D->getCategoryNameLoc(), | 
|  | 4060 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) | 
|  | 4061 | std::tie( | 
|  | 4062 | ToAtStartLoc, ToCategoryNameLoc, | 
|  | 4063 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; | 
|  | 4064 | else | 
|  | 4065 | return Imp.takeError(); | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4066 |  | 
|  | 4067 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4068 | ToAtStartLoc, Loc, | 
|  | 4069 | ToCategoryNameLoc, | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4070 | Name.getAsIdentifierInfo(), ToInterface, | 
|  | 4071 | /*TypeParamList=*/nullptr, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4072 | ToIvarLBraceLoc, | 
|  | 4073 | ToIvarRBraceLoc)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4074 | return ToCategory; | 
|  | 4075 |  | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4076 | ToCategory->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4077 | LexicalDC->addDeclInternal(ToCategory); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4078 | // Import the type parameter list after MapImported, to avoid | 
| Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4079 | // loops when bringing in their DeclContext. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4080 | if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList())) | 
|  | 4081 | ToCategory->setTypeParamList(*PListOrErr); | 
|  | 4082 | else | 
|  | 4083 | return PListOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4084 |  | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4085 | // Import protocols | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4086 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | 
|  | 4087 | SmallVector<SourceLocation, 4> ProtocolLocs; | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4088 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc | 
|  | 4089 | = D->protocol_loc_begin(); | 
|  | 4090 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), | 
|  | 4091 | FromProtoEnd = D->protocol_end(); | 
|  | 4092 | FromProto != FromProtoEnd; | 
|  | 4093 | ++FromProto, ++FromProtoLoc) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4094 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) | 
|  | 4095 | Protocols.push_back(*ToProtoOrErr); | 
|  | 4096 | else | 
|  | 4097 | return ToProtoOrErr.takeError(); | 
|  | 4098 |  | 
|  | 4099 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) | 
|  | 4100 | ProtocolLocs.push_back(*ToProtoLocOrErr); | 
|  | 4101 | else | 
|  | 4102 | return ToProtoLocOrErr.takeError(); | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4103 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4104 |  | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4105 | // FIXME: If we're merging, make sure that the protocol list is the same. | 
|  | 4106 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), | 
|  | 4107 | ProtocolLocs.data(), Importer.getToContext()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4108 |  | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4109 | } else { | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4110 | Importer.MapImported(D, ToCategory); | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4111 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4112 |  | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4113 | // Import all of the members of this category. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4114 | if (Error Err = ImportDeclContext(D)) | 
|  | 4115 | return std::move(Err); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4116 |  | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4117 | // If we have an implementation, import it as well. | 
|  | 4118 | if (D->getImplementation()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4119 | if (Expected<ObjCCategoryImplDecl *> ToImplOrErr = | 
|  | 4120 | import(D->getImplementation())) | 
|  | 4121 | ToCategory->setImplementation(*ToImplOrErr); | 
|  | 4122 | else | 
|  | 4123 | return ToImplOrErr.takeError(); | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4124 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4125 |  | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4126 | return ToCategory; | 
|  | 4127 | } | 
|  | 4128 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4129 | Error ASTNodeImporter::ImportDefinition( | 
|  | 4130 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, ImportDefinitionKind Kind) { | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4131 | if (To->getDefinition()) { | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4132 | if (shouldForceImportDeclContext(Kind)) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4133 | if (Error Err = ImportDeclContext(From)) | 
|  | 4134 | return Err; | 
|  | 4135 | return Error::success(); | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4136 | } | 
|  | 4137 |  | 
|  | 4138 | // Start the protocol definition | 
|  | 4139 | To->startDefinition(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4140 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4141 | // Import protocols | 
|  | 4142 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | 
|  | 4143 | SmallVector<SourceLocation, 4> ProtocolLocs; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4144 | ObjCProtocolDecl::protocol_loc_iterator FromProtoLoc = | 
|  | 4145 | From->protocol_loc_begin(); | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4146 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), | 
|  | 4147 | FromProtoEnd = From->protocol_end(); | 
|  | 4148 | FromProto != FromProtoEnd; | 
|  | 4149 | ++FromProto, ++FromProtoLoc) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4150 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) | 
|  | 4151 | Protocols.push_back(*ToProtoOrErr); | 
|  | 4152 | else | 
|  | 4153 | return ToProtoOrErr.takeError(); | 
|  | 4154 |  | 
|  | 4155 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) | 
|  | 4156 | ProtocolLocs.push_back(*ToProtoLocOrErr); | 
|  | 4157 | else | 
|  | 4158 | return ToProtoLocOrErr.takeError(); | 
|  | 4159 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4160 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4161 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4162 | // FIXME: If we're merging, make sure that the protocol list is the same. | 
|  | 4163 | To->setProtocolList(Protocols.data(), Protocols.size(), | 
|  | 4164 | ProtocolLocs.data(), Importer.getToContext()); | 
|  | 4165 |  | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4166 | if (shouldForceImportDeclContext(Kind)) { | 
|  | 4167 | // Import all of the members of this protocol. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4168 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | 
|  | 4169 | return Err; | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4170 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4171 | return Error::success(); | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4172 | } | 
|  | 4173 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4174 | ExpectedDecl ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4175 | // If this protocol has a definition in the translation unit we're coming | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4176 | // from, but this particular declaration is not that definition, import the | 
|  | 4177 | // definition and map to that. | 
|  | 4178 | ObjCProtocolDecl *Definition = D->getDefinition(); | 
|  | 4179 | if (Definition && Definition != D) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4180 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) | 
|  | 4181 | return Importer.MapImported(D, *ImportedDefOrErr); | 
|  | 4182 | else | 
|  | 4183 | return ImportedDefOrErr.takeError(); | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4184 | } | 
|  | 4185 |  | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4186 | // Import the major distinguishing characteristics of a protocol. | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4187 | DeclContext *DC, *LexicalDC; | 
|  | 4188 | DeclarationName Name; | 
|  | 4189 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4190 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4191 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 4192 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4193 | if (ToD) | 
|  | 4194 | return ToD; | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4195 |  | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4196 | ObjCProtocolDecl *MergeWithProtocol = nullptr; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4197 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4198 | for (auto *FoundDecl : FoundDecls) { | 
|  | 4199 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4200 | continue; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4201 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4202 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4203 | break; | 
|  | 4204 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4205 |  | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4206 | ObjCProtocolDecl *ToProto = MergeWithProtocol; | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4207 | if (!ToProto) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4208 | auto ToAtBeginLocOrErr = import(D->getAtStartLoc()); | 
|  | 4209 | if (!ToAtBeginLocOrErr) | 
|  | 4210 | return ToAtBeginLocOrErr.takeError(); | 
|  | 4211 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4212 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, | 
|  | 4213 | Name.getAsIdentifierInfo(), Loc, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4214 | *ToAtBeginLocOrErr, | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4215 | /*PrevDecl=*/nullptr)) | 
|  | 4216 | return ToProto; | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4217 | ToProto->setLexicalDeclContext(LexicalDC); | 
|  | 4218 | LexicalDC->addDeclInternal(ToProto); | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4219 | } | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4220 |  | 
|  | 4221 | Importer.MapImported(D, ToProto); | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4222 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4223 | if (D->isThisDeclarationADefinition()) | 
|  | 4224 | if (Error Err = ImportDefinition(D, ToProto)) | 
|  | 4225 | return std::move(Err); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4226 |  | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4227 | return ToProto; | 
|  | 4228 | } | 
|  | 4229 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4230 | ExpectedDecl ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { | 
|  | 4231 | DeclContext *DC, *LexicalDC; | 
|  | 4232 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | 
|  | 4233 | return std::move(Err); | 
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4234 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4235 | ExpectedSLoc ExternLocOrErr = import(D->getExternLoc()); | 
|  | 4236 | if (!ExternLocOrErr) | 
|  | 4237 | return ExternLocOrErr.takeError(); | 
|  | 4238 |  | 
|  | 4239 | ExpectedSLoc LangLocOrErr = import(D->getLocation()); | 
|  | 4240 | if (!LangLocOrErr) | 
|  | 4241 | return LangLocOrErr.takeError(); | 
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4242 |  | 
|  | 4243 | bool HasBraces = D->hasBraces(); | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4244 |  | 
|  | 4245 | LinkageSpecDecl *ToLinkageSpec; | 
|  | 4246 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4247 | *ExternLocOrErr, *LangLocOrErr, | 
|  | 4248 | D->getLanguage(), HasBraces)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4249 | return ToLinkageSpec; | 
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4250 |  | 
|  | 4251 | if (HasBraces) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4252 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); | 
|  | 4253 | if (!RBraceLocOrErr) | 
|  | 4254 | return RBraceLocOrErr.takeError(); | 
|  | 4255 | ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr); | 
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4256 | } | 
|  | 4257 |  | 
|  | 4258 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); | 
|  | 4259 | LexicalDC->addDeclInternal(ToLinkageSpec); | 
|  | 4260 |  | 
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4261 | return ToLinkageSpec; | 
|  | 4262 | } | 
|  | 4263 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4264 | ExpectedDecl ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4265 | DeclContext *DC, *LexicalDC; | 
|  | 4266 | DeclarationName Name; | 
|  | 4267 | SourceLocation Loc; | 
|  | 4268 | NamedDecl *ToD = nullptr; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4269 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 4270 | return std::move(Err); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4271 | if (ToD) | 
|  | 4272 | return ToD; | 
|  | 4273 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4274 | SourceLocation ToLoc, ToUsingLoc; | 
|  | 4275 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 4276 | if (auto Imp = importSeq( | 
|  | 4277 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc())) | 
|  | 4278 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc) = *Imp; | 
|  | 4279 | else | 
|  | 4280 | return Imp.takeError(); | 
|  | 4281 |  | 
|  | 4282 | DeclarationNameInfo NameInfo(Name, ToLoc); | 
|  | 4283 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) | 
|  | 4284 | return std::move(Err); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4285 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4286 | UsingDecl *ToUsing; | 
|  | 4287 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4288 | ToUsingLoc, ToQualifierLoc, NameInfo, | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4289 | D->hasTypename())) | 
|  | 4290 | return ToUsing; | 
|  | 4291 |  | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4292 | ToUsing->setLexicalDeclContext(LexicalDC); | 
|  | 4293 | LexicalDC->addDeclInternal(ToUsing); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4294 |  | 
|  | 4295 | if (NamedDecl *FromPattern = | 
|  | 4296 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4297 | if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern)) | 
|  | 4298 | Importer.getToContext().setInstantiatedFromUsingDecl( | 
|  | 4299 | ToUsing, *ToPatternOrErr); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4300 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4301 | return ToPatternOrErr.takeError(); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4302 | } | 
|  | 4303 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4304 | for (UsingShadowDecl *FromShadow : D->shadows()) { | 
|  | 4305 | if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow)) | 
|  | 4306 | ToUsing->addShadowDecl(*ToShadowOrErr); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4307 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4308 | // FIXME: We return error here but the definition is already created | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4309 | // and available with lookups. How to fix this?.. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4310 | return ToShadowOrErr.takeError(); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4311 | } | 
|  | 4312 | return ToUsing; | 
|  | 4313 | } | 
|  | 4314 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4315 | ExpectedDecl ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4316 | DeclContext *DC, *LexicalDC; | 
|  | 4317 | DeclarationName Name; | 
|  | 4318 | SourceLocation Loc; | 
|  | 4319 | NamedDecl *ToD = nullptr; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4320 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 4321 | return std::move(Err); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4322 | if (ToD) | 
|  | 4323 | return ToD; | 
|  | 4324 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4325 | Expected<UsingDecl *> ToUsingOrErr = import(D->getUsingDecl()); | 
|  | 4326 | if (!ToUsingOrErr) | 
|  | 4327 | return ToUsingOrErr.takeError(); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4328 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4329 | Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl()); | 
|  | 4330 | if (!ToTargetOrErr) | 
|  | 4331 | return ToTargetOrErr.takeError(); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4332 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4333 | UsingShadowDecl *ToShadow; | 
|  | 4334 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4335 | *ToUsingOrErr, *ToTargetOrErr)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4336 | return ToShadow; | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4337 |  | 
|  | 4338 | ToShadow->setLexicalDeclContext(LexicalDC); | 
|  | 4339 | ToShadow->setAccess(D->getAccess()); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4340 |  | 
|  | 4341 | if (UsingShadowDecl *FromPattern = | 
|  | 4342 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4343 | if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern)) | 
|  | 4344 | Importer.getToContext().setInstantiatedFromUsingShadowDecl( | 
|  | 4345 | ToShadow, *ToPatternOrErr); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4346 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4347 | // FIXME: We return error here but the definition is already created | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4348 | // and available with lookups. How to fix this?.. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4349 | return ToPatternOrErr.takeError(); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4350 | } | 
|  | 4351 |  | 
|  | 4352 | LexicalDC->addDeclInternal(ToShadow); | 
|  | 4353 |  | 
|  | 4354 | return ToShadow; | 
|  | 4355 | } | 
|  | 4356 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4357 | ExpectedDecl ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4358 | DeclContext *DC, *LexicalDC; | 
|  | 4359 | DeclarationName Name; | 
|  | 4360 | SourceLocation Loc; | 
|  | 4361 | NamedDecl *ToD = nullptr; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4362 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 4363 | return std::move(Err); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4364 | if (ToD) | 
|  | 4365 | return ToD; | 
|  | 4366 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4367 | auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor()); | 
|  | 4368 | if (!ToComAncestorOrErr) | 
|  | 4369 | return ToComAncestorOrErr.takeError(); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4370 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4371 | NamespaceDecl *ToNominatedNamespace; | 
|  | 4372 | SourceLocation ToUsingLoc, ToNamespaceKeyLocation, ToIdentLocation; | 
|  | 4373 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 4374 | if (auto Imp = importSeq( | 
|  | 4375 | D->getNominatedNamespace(), D->getUsingLoc(), | 
|  | 4376 | D->getNamespaceKeyLocation(), D->getQualifierLoc(), | 
|  | 4377 | D->getIdentLocation())) | 
|  | 4378 | std::tie( | 
|  | 4379 | ToNominatedNamespace, ToUsingLoc, ToNamespaceKeyLocation, | 
|  | 4380 | ToQualifierLoc, ToIdentLocation) = *Imp; | 
|  | 4381 | else | 
|  | 4382 | return Imp.takeError(); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4383 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4384 | UsingDirectiveDecl *ToUsingDir; | 
|  | 4385 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4386 | ToUsingLoc, | 
|  | 4387 | ToNamespaceKeyLocation, | 
|  | 4388 | ToQualifierLoc, | 
|  | 4389 | ToIdentLocation, | 
|  | 4390 | ToNominatedNamespace, *ToComAncestorOrErr)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4391 | return ToUsingDir; | 
|  | 4392 |  | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4393 | ToUsingDir->setLexicalDeclContext(LexicalDC); | 
|  | 4394 | LexicalDC->addDeclInternal(ToUsingDir); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4395 |  | 
|  | 4396 | return ToUsingDir; | 
|  | 4397 | } | 
|  | 4398 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4399 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl( | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4400 | UnresolvedUsingValueDecl *D) { | 
|  | 4401 | DeclContext *DC, *LexicalDC; | 
|  | 4402 | DeclarationName Name; | 
|  | 4403 | SourceLocation Loc; | 
|  | 4404 | NamedDecl *ToD = nullptr; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4405 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 4406 | return std::move(Err); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4407 | if (ToD) | 
|  | 4408 | return ToD; | 
|  | 4409 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4410 | SourceLocation ToLoc, ToUsingLoc, ToEllipsisLoc; | 
|  | 4411 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 4412 | if (auto Imp = importSeq( | 
|  | 4413 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc(), | 
|  | 4414 | D->getEllipsisLoc())) | 
|  | 4415 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; | 
|  | 4416 | else | 
|  | 4417 | return Imp.takeError(); | 
|  | 4418 |  | 
|  | 4419 | DeclarationNameInfo NameInfo(Name, ToLoc); | 
|  | 4420 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) | 
|  | 4421 | return std::move(Err); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4422 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4423 | UnresolvedUsingValueDecl *ToUsingValue; | 
|  | 4424 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4425 | ToUsingLoc, ToQualifierLoc, NameInfo, | 
|  | 4426 | ToEllipsisLoc)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4427 | return ToUsingValue; | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4428 |  | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4429 | ToUsingValue->setAccess(D->getAccess()); | 
|  | 4430 | ToUsingValue->setLexicalDeclContext(LexicalDC); | 
|  | 4431 | LexicalDC->addDeclInternal(ToUsingValue); | 
|  | 4432 |  | 
|  | 4433 | return ToUsingValue; | 
|  | 4434 | } | 
|  | 4435 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4436 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4437 | UnresolvedUsingTypenameDecl *D) { | 
|  | 4438 | DeclContext *DC, *LexicalDC; | 
|  | 4439 | DeclarationName Name; | 
|  | 4440 | SourceLocation Loc; | 
|  | 4441 | NamedDecl *ToD = nullptr; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4442 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 4443 | return std::move(Err); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4444 | if (ToD) | 
|  | 4445 | return ToD; | 
|  | 4446 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4447 | SourceLocation ToUsingLoc, ToTypenameLoc, ToEllipsisLoc; | 
|  | 4448 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 4449 | if (auto Imp = importSeq( | 
|  | 4450 | D->getUsingLoc(), D->getTypenameLoc(), D->getQualifierLoc(), | 
|  | 4451 | D->getEllipsisLoc())) | 
|  | 4452 | std::tie(ToUsingLoc, ToTypenameLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; | 
|  | 4453 | else | 
|  | 4454 | return Imp.takeError(); | 
|  | 4455 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4456 | UnresolvedUsingTypenameDecl *ToUsing; | 
|  | 4457 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4458 | ToUsingLoc, ToTypenameLoc, | 
|  | 4459 | ToQualifierLoc, Loc, Name, ToEllipsisLoc)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4460 | return ToUsing; | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4461 |  | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4462 | ToUsing->setAccess(D->getAccess()); | 
|  | 4463 | ToUsing->setLexicalDeclContext(LexicalDC); | 
|  | 4464 | LexicalDC->addDeclInternal(ToUsing); | 
|  | 4465 |  | 
|  | 4466 | return ToUsing; | 
|  | 4467 | } | 
|  | 4468 |  | 
| Raphael Isemann | ba7bde6 | 2019-10-30 14:50:35 +0100 | [diff] [blame] | 4469 | ExpectedDecl ASTNodeImporter::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D) { | 
|  | 4470 | Decl* ToD = nullptr; | 
|  | 4471 | switch (D->getBuiltinTemplateKind()) { | 
|  | 4472 | case BuiltinTemplateKind::BTK__make_integer_seq: | 
|  | 4473 | ToD = Importer.getToContext().getMakeIntegerSeqDecl(); | 
|  | 4474 | break; | 
|  | 4475 | case BuiltinTemplateKind::BTK__type_pack_element: | 
|  | 4476 | ToD = Importer.getToContext().getTypePackElementDecl(); | 
|  | 4477 | break; | 
|  | 4478 | } | 
|  | 4479 | assert(ToD && "BuiltinTemplateDecl of unsupported kind!"); | 
|  | 4480 | Importer.MapImported(D, ToD); | 
|  | 4481 | return ToD; | 
|  | 4482 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4483 |  | 
|  | 4484 | Error ASTNodeImporter::ImportDefinition( | 
|  | 4485 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, ImportDefinitionKind Kind) { | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4486 | if (To->getDefinition()) { | 
|  | 4487 | // Check consistency of superclass. | 
|  | 4488 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); | 
|  | 4489 | if (FromSuper) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4490 | if (auto FromSuperOrErr = import(FromSuper)) | 
|  | 4491 | FromSuper = *FromSuperOrErr; | 
|  | 4492 | else | 
|  | 4493 | return FromSuperOrErr.takeError(); | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4494 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4495 |  | 
|  | 4496 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4497 | if ((bool)FromSuper != (bool)ToSuper || | 
|  | 4498 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4499 | Importer.ToDiag(To->getLocation(), | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4500 | diag::warn_odr_objc_superclass_inconsistent) | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4501 | << To->getDeclName(); | 
|  | 4502 | if (ToSuper) | 
|  | 4503 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) | 
|  | 4504 | << To->getSuperClass()->getDeclName(); | 
|  | 4505 | else | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4506 | Importer.ToDiag(To->getLocation(), | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4507 | diag::note_odr_objc_missing_superclass); | 
|  | 4508 | if (From->getSuperClass()) | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4509 | Importer.FromDiag(From->getSuperClassLoc(), | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4510 | diag::note_odr_objc_superclass) | 
|  | 4511 | << From->getSuperClass()->getDeclName(); | 
|  | 4512 | else | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4513 | Importer.FromDiag(From->getLocation(), | 
|  | 4514 | diag::note_odr_objc_missing_superclass); | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4515 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4516 |  | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4517 | if (shouldForceImportDeclContext(Kind)) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4518 | if (Error Err = ImportDeclContext(From)) | 
|  | 4519 | return Err; | 
|  | 4520 | return Error::success(); | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4521 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4522 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4523 | // Start the definition. | 
|  | 4524 | To->startDefinition(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4525 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4526 | // If this class has a superclass, import it. | 
|  | 4527 | if (From->getSuperClass()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4528 | if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo())) | 
|  | 4529 | To->setSuperClass(*SuperTInfoOrErr); | 
|  | 4530 | else | 
|  | 4531 | return SuperTInfoOrErr.takeError(); | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4532 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4533 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4534 | // Import protocols | 
|  | 4535 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | 
|  | 4536 | SmallVector<SourceLocation, 4> ProtocolLocs; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4537 | ObjCInterfaceDecl::protocol_loc_iterator FromProtoLoc = | 
|  | 4538 | From->protocol_loc_begin(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4539 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4540 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), | 
|  | 4541 | FromProtoEnd = From->protocol_end(); | 
|  | 4542 | FromProto != FromProtoEnd; | 
|  | 4543 | ++FromProto, ++FromProtoLoc) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4544 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) | 
|  | 4545 | Protocols.push_back(*ToProtoOrErr); | 
|  | 4546 | else | 
|  | 4547 | return ToProtoOrErr.takeError(); | 
|  | 4548 |  | 
|  | 4549 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) | 
|  | 4550 | ProtocolLocs.push_back(*ToProtoLocOrErr); | 
|  | 4551 | else | 
|  | 4552 | return ToProtoLocOrErr.takeError(); | 
|  | 4553 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4554 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4555 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4556 | // FIXME: If we're merging, make sure that the protocol list is the same. | 
|  | 4557 | To->setProtocolList(Protocols.data(), Protocols.size(), | 
|  | 4558 | ProtocolLocs.data(), Importer.getToContext()); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4559 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4560 | // Import categories. When the categories themselves are imported, they'll | 
|  | 4561 | // hook themselves into this interface. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4562 | for (auto *Cat : From->known_categories()) { | 
|  | 4563 | auto ToCatOrErr = import(Cat); | 
|  | 4564 | if (!ToCatOrErr) | 
|  | 4565 | return ToCatOrErr.takeError(); | 
|  | 4566 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4567 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4568 | // If we have an @implementation, import it as well. | 
|  | 4569 | if (From->getImplementation()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4570 | if (Expected<ObjCImplementationDecl *> ToImplOrErr = | 
|  | 4571 | import(From->getImplementation())) | 
|  | 4572 | To->setImplementation(*ToImplOrErr); | 
|  | 4573 | else | 
|  | 4574 | return ToImplOrErr.takeError(); | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4575 | } | 
|  | 4576 |  | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4577 | if (shouldForceImportDeclContext(Kind)) { | 
|  | 4578 | // Import all of the members of this class. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4579 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | 
|  | 4580 | return Err; | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4581 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4582 | return Error::success(); | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4583 | } | 
|  | 4584 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4585 | Expected<ObjCTypeParamList *> | 
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4586 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { | 
|  | 4587 | if (!list) | 
|  | 4588 | return nullptr; | 
|  | 4589 |  | 
|  | 4590 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4591 | for (auto *fromTypeParam : *list) { | 
|  | 4592 | if (auto toTypeParamOrErr = import(fromTypeParam)) | 
|  | 4593 | toTypeParams.push_back(*toTypeParamOrErr); | 
|  | 4594 | else | 
|  | 4595 | return toTypeParamOrErr.takeError(); | 
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4596 | } | 
|  | 4597 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4598 | auto LAngleLocOrErr = import(list->getLAngleLoc()); | 
|  | 4599 | if (!LAngleLocOrErr) | 
|  | 4600 | return LAngleLocOrErr.takeError(); | 
|  | 4601 |  | 
|  | 4602 | auto RAngleLocOrErr = import(list->getRAngleLoc()); | 
|  | 4603 | if (!RAngleLocOrErr) | 
|  | 4604 | return RAngleLocOrErr.takeError(); | 
|  | 4605 |  | 
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4606 | return ObjCTypeParamList::create(Importer.getToContext(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4607 | *LAngleLocOrErr, | 
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4608 | toTypeParams, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4609 | *RAngleLocOrErr); | 
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4610 | } | 
|  | 4611 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4612 | ExpectedDecl ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4613 | // If this class has a definition in the translation unit we're coming from, | 
|  | 4614 | // but this particular declaration is not that definition, import the | 
|  | 4615 | // definition and map to that. | 
|  | 4616 | ObjCInterfaceDecl *Definition = D->getDefinition(); | 
|  | 4617 | if (Definition && Definition != D) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4618 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) | 
|  | 4619 | return Importer.MapImported(D, *ImportedDefOrErr); | 
|  | 4620 | else | 
|  | 4621 | return ImportedDefOrErr.takeError(); | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4622 | } | 
|  | 4623 |  | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4624 | // Import the major distinguishing characteristics of an @interface. | 
|  | 4625 | DeclContext *DC, *LexicalDC; | 
|  | 4626 | DeclarationName Name; | 
|  | 4627 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4628 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4629 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 4630 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4631 | if (ToD) | 
|  | 4632 | return ToD; | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4633 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4634 | // Look for an existing interface with the same name. | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4635 | ObjCInterfaceDecl *MergeWithIface = nullptr; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4636 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4637 | for (auto *FoundDecl : FoundDecls) { | 
|  | 4638 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4639 | continue; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4640 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4641 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4642 | break; | 
|  | 4643 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4644 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4645 | // Create an interface declaration, if one does not already exist. | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4646 | ObjCInterfaceDecl *ToIface = MergeWithIface; | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4647 | if (!ToIface) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4648 | ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc()); | 
|  | 4649 | if (!AtBeginLocOrErr) | 
|  | 4650 | return AtBeginLocOrErr.takeError(); | 
|  | 4651 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4652 | if (GetImportedOrCreateDecl( | 
|  | 4653 | ToIface, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4654 | *AtBeginLocOrErr, Name.getAsIdentifierInfo(), | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4655 | /*TypeParamList=*/nullptr, | 
|  | 4656 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) | 
|  | 4657 | return ToIface; | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4658 | ToIface->setLexicalDeclContext(LexicalDC); | 
|  | 4659 | LexicalDC->addDeclInternal(ToIface); | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4660 | } | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4661 | Importer.MapImported(D, ToIface); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4662 | // Import the type parameter list after MapImported, to avoid | 
| Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4663 | // loops when bringing in their DeclContext. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4664 | if (auto ToPListOrErr = | 
|  | 4665 | ImportObjCTypeParamList(D->getTypeParamListAsWritten())) | 
|  | 4666 | ToIface->setTypeParamList(*ToPListOrErr); | 
|  | 4667 | else | 
|  | 4668 | return ToPListOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4669 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4670 | if (D->isThisDeclarationADefinition()) | 
|  | 4671 | if (Error Err = ImportDefinition(D, ToIface)) | 
|  | 4672 | return std::move(Err); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4673 |  | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4674 | return ToIface; | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4675 | } | 
|  | 4676 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4677 | ExpectedDecl | 
|  | 4678 | ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { | 
|  | 4679 | ObjCCategoryDecl *Category; | 
|  | 4680 | if (Error Err = importInto(Category, D->getCategoryDecl())) | 
|  | 4681 | return std::move(Err); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4682 |  | 
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4683 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); | 
|  | 4684 | if (!ToImpl) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4685 | DeclContext *DC, *LexicalDC; | 
|  | 4686 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | 
|  | 4687 | return std::move(Err); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4688 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4689 | SourceLocation ToLocation, ToAtStartLoc, ToCategoryNameLoc; | 
|  | 4690 | if (auto Imp = importSeq( | 
|  | 4691 | D->getLocation(), D->getAtStartLoc(), D->getCategoryNameLoc())) | 
|  | 4692 | std::tie(ToLocation, ToAtStartLoc, ToCategoryNameLoc) = *Imp; | 
|  | 4693 | else | 
|  | 4694 | return Imp.takeError(); | 
|  | 4695 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4696 | if (GetImportedOrCreateDecl( | 
|  | 4697 | ToImpl, D, Importer.getToContext(), DC, | 
|  | 4698 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4699 | ToLocation, ToAtStartLoc, ToCategoryNameLoc)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4700 | return ToImpl; | 
|  | 4701 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4702 | ToImpl->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4703 | LexicalDC->addDeclInternal(ToImpl); | 
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4704 | Category->setImplementation(ToImpl); | 
|  | 4705 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4706 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4707 | Importer.MapImported(D, ToImpl); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4708 | if (Error Err = ImportDeclContext(D)) | 
|  | 4709 | return std::move(Err); | 
|  | 4710 |  | 
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4711 | return ToImpl; | 
|  | 4712 | } | 
|  | 4713 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4714 | ExpectedDecl | 
|  | 4715 | ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4716 | // Find the corresponding interface. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4717 | ObjCInterfaceDecl *Iface; | 
|  | 4718 | if (Error Err = importInto(Iface, D->getClassInterface())) | 
|  | 4719 | return std::move(Err); | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4720 |  | 
|  | 4721 | // Import the superclass, if any. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4722 | ObjCInterfaceDecl *Super; | 
|  | 4723 | if (Error Err = importInto(Super, D->getSuperClass())) | 
|  | 4724 | return std::move(Err); | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4725 |  | 
|  | 4726 | ObjCImplementationDecl *Impl = Iface->getImplementation(); | 
|  | 4727 | if (!Impl) { | 
|  | 4728 | // We haven't imported an implementation yet. Create a new @implementation | 
|  | 4729 | // now. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4730 | DeclContext *DC, *LexicalDC; | 
|  | 4731 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | 
|  | 4732 | return std::move(Err); | 
|  | 4733 |  | 
|  | 4734 | SourceLocation ToLocation, ToAtStartLoc, ToSuperClassLoc; | 
|  | 4735 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; | 
|  | 4736 | if (auto Imp = importSeq( | 
|  | 4737 | D->getLocation(), D->getAtStartLoc(), D->getSuperClassLoc(), | 
|  | 4738 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) | 
|  | 4739 | std::tie( | 
|  | 4740 | ToLocation, ToAtStartLoc, ToSuperClassLoc, | 
|  | 4741 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; | 
|  | 4742 | else | 
|  | 4743 | return Imp.takeError(); | 
|  | 4744 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4745 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4746 | DC, Iface, Super, | 
|  | 4747 | ToLocation, | 
|  | 4748 | ToAtStartLoc, | 
|  | 4749 | ToSuperClassLoc, | 
|  | 4750 | ToIvarLBraceLoc, | 
|  | 4751 | ToIvarRBraceLoc)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4752 | return Impl; | 
|  | 4753 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4754 | Impl->setLexicalDeclContext(LexicalDC); | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4755 |  | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4756 | // Associate the implementation with the class it implements. | 
|  | 4757 | Iface->setImplementation(Impl); | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4758 | Importer.MapImported(D, Iface->getImplementation()); | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4759 | } else { | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4760 | Importer.MapImported(D, Iface->getImplementation()); | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4761 |  | 
|  | 4762 | // Verify that the existing @implementation has the same superclass. | 
|  | 4763 | if ((Super && !Impl->getSuperClass()) || | 
|  | 4764 | (!Super && Impl->getSuperClass()) || | 
| Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4765 | (Super && Impl->getSuperClass() && | 
|  | 4766 | !declaresSameEntity(Super->getCanonicalDecl(), | 
|  | 4767 | Impl->getSuperClass()))) { | 
|  | 4768 | Importer.ToDiag(Impl->getLocation(), | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4769 | diag::warn_odr_objc_superclass_inconsistent) | 
| Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4770 | << Iface->getDeclName(); | 
|  | 4771 | // FIXME: It would be nice to have the location of the superclass | 
|  | 4772 | // below. | 
|  | 4773 | if (Impl->getSuperClass()) | 
|  | 4774 | Importer.ToDiag(Impl->getLocation(), | 
|  | 4775 | diag::note_odr_objc_superclass) | 
|  | 4776 | << Impl->getSuperClass()->getDeclName(); | 
|  | 4777 | else | 
|  | 4778 | Importer.ToDiag(Impl->getLocation(), | 
|  | 4779 | diag::note_odr_objc_missing_superclass); | 
|  | 4780 | if (D->getSuperClass()) | 
|  | 4781 | Importer.FromDiag(D->getLocation(), | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4782 | diag::note_odr_objc_superclass) | 
| Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4783 | << D->getSuperClass()->getDeclName(); | 
|  | 4784 | else | 
|  | 4785 | Importer.FromDiag(D->getLocation(), | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4786 | diag::note_odr_objc_missing_superclass); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4787 |  | 
|  | 4788 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4789 | } | 
|  | 4790 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4791 |  | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4792 | // Import all of the members of this @implementation. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4793 | if (Error Err = ImportDeclContext(D)) | 
|  | 4794 | return std::move(Err); | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4795 |  | 
|  | 4796 | return Impl; | 
|  | 4797 | } | 
|  | 4798 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4799 | ExpectedDecl ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4800 | // Import the major distinguishing characteristics of an @property. | 
|  | 4801 | DeclContext *DC, *LexicalDC; | 
|  | 4802 | DeclarationName Name; | 
|  | 4803 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4804 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4805 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 4806 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4807 | if (ToD) | 
|  | 4808 | return ToD; | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4809 |  | 
|  | 4810 | // Check whether we have already imported this property. | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4811 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4812 | for (auto *FoundDecl : FoundDecls) { | 
|  | 4813 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4814 | // Check property types. | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4815 | if (!Importer.IsStructurallyEquivalent(D->getType(), | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4816 | FoundProp->getType())) { | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4817 | Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent) | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4818 | << Name << D->getType() << FoundProp->getType(); | 
|  | 4819 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) | 
|  | 4820 | << FoundProp->getType(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4821 |  | 
|  | 4822 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4823 | } | 
|  | 4824 |  | 
|  | 4825 | // FIXME: Check property attributes, getters, setters, etc.? | 
|  | 4826 |  | 
|  | 4827 | // Consider these properties to be equivalent. | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4828 | Importer.MapImported(D, FoundProp); | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4829 | return FoundProp; | 
|  | 4830 | } | 
|  | 4831 | } | 
|  | 4832 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4833 | QualType ToType; | 
|  | 4834 | TypeSourceInfo *ToTypeSourceInfo; | 
|  | 4835 | SourceLocation ToAtLoc, ToLParenLoc; | 
|  | 4836 | if (auto Imp = importSeq( | 
|  | 4837 | D->getType(), D->getTypeSourceInfo(), D->getAtLoc(), D->getLParenLoc())) | 
|  | 4838 | std::tie(ToType, ToTypeSourceInfo, ToAtLoc, ToLParenLoc) = *Imp; | 
|  | 4839 | else | 
|  | 4840 | return Imp.takeError(); | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4841 |  | 
|  | 4842 | // Create the new property. | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4843 | ObjCPropertyDecl *ToProperty; | 
|  | 4844 | if (GetImportedOrCreateDecl( | 
|  | 4845 | ToProperty, D, Importer.getToContext(), DC, Loc, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4846 | Name.getAsIdentifierInfo(), ToAtLoc, | 
|  | 4847 | ToLParenLoc, ToType, | 
|  | 4848 | ToTypeSourceInfo, D->getPropertyImplementation())) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4849 | return ToProperty; | 
|  | 4850 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4851 | Selector ToGetterName, ToSetterName; | 
|  | 4852 | SourceLocation ToGetterNameLoc, ToSetterNameLoc; | 
|  | 4853 | ObjCMethodDecl *ToGetterMethodDecl, *ToSetterMethodDecl; | 
|  | 4854 | ObjCIvarDecl *ToPropertyIvarDecl; | 
|  | 4855 | if (auto Imp = importSeq( | 
|  | 4856 | D->getGetterName(), D->getSetterName(), | 
|  | 4857 | D->getGetterNameLoc(), D->getSetterNameLoc(), | 
|  | 4858 | D->getGetterMethodDecl(), D->getSetterMethodDecl(), | 
|  | 4859 | D->getPropertyIvarDecl())) | 
|  | 4860 | std::tie( | 
|  | 4861 | ToGetterName, ToSetterName, | 
|  | 4862 | ToGetterNameLoc, ToSetterNameLoc, | 
|  | 4863 | ToGetterMethodDecl, ToSetterMethodDecl, | 
|  | 4864 | ToPropertyIvarDecl) = *Imp; | 
|  | 4865 | else | 
|  | 4866 | return Imp.takeError(); | 
|  | 4867 |  | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4868 | ToProperty->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4869 | LexicalDC->addDeclInternal(ToProperty); | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4870 |  | 
|  | 4871 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); | 
| Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 4872 | ToProperty->setPropertyAttributesAsWritten( | 
|  | 4873 | D->getPropertyAttributesAsWritten()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4874 | ToProperty->setGetterName(ToGetterName, ToGetterNameLoc); | 
|  | 4875 | ToProperty->setSetterName(ToSetterName, ToSetterNameLoc); | 
|  | 4876 | ToProperty->setGetterMethodDecl(ToGetterMethodDecl); | 
|  | 4877 | ToProperty->setSetterMethodDecl(ToSetterMethodDecl); | 
|  | 4878 | ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl); | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4879 | return ToProperty; | 
|  | 4880 | } | 
|  | 4881 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4882 | ExpectedDecl | 
|  | 4883 | ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { | 
|  | 4884 | ObjCPropertyDecl *Property; | 
|  | 4885 | if (Error Err = importInto(Property, D->getPropertyDecl())) | 
|  | 4886 | return std::move(Err); | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4887 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4888 | DeclContext *DC, *LexicalDC; | 
|  | 4889 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | 
|  | 4890 | return std::move(Err); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4891 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4892 | auto *InImpl = cast<ObjCImplDecl>(LexicalDC); | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4893 |  | 
|  | 4894 | // Import the ivar (for an @synthesize). | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4895 | ObjCIvarDecl *Ivar = nullptr; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4896 | if (Error Err = importInto(Ivar, D->getPropertyIvarDecl())) | 
|  | 4897 | return std::move(Err); | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4898 |  | 
|  | 4899 | ObjCPropertyImplDecl *ToImpl | 
| Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 4900 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), | 
|  | 4901 | Property->getQueryKind()); | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4902 | if (!ToImpl) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4903 | SourceLocation ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc; | 
|  | 4904 | if (auto Imp = importSeq( | 
|  | 4905 | D->getBeginLoc(), D->getLocation(), D->getPropertyIvarDeclLoc())) | 
|  | 4906 | std::tie(ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc) = *Imp; | 
|  | 4907 | else | 
|  | 4908 | return Imp.takeError(); | 
|  | 4909 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4910 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4911 | ToBeginLoc, | 
|  | 4912 | ToLocation, Property, | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4913 | D->getPropertyImplementation(), Ivar, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4914 | ToPropertyIvarDeclLoc)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4915 | return ToImpl; | 
|  | 4916 |  | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4917 | ToImpl->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4918 | LexicalDC->addDeclInternal(ToImpl); | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4919 | } else { | 
|  | 4920 | // Check that we have the same kind of property implementation (@synthesize | 
|  | 4921 | // vs. @dynamic). | 
|  | 4922 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4923 | Importer.ToDiag(ToImpl->getLocation(), | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4924 | diag::warn_odr_objc_property_impl_kind_inconsistent) | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4925 | << Property->getDeclName() | 
|  | 4926 | << (ToImpl->getPropertyImplementation() | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4927 | == ObjCPropertyImplDecl::Dynamic); | 
|  | 4928 | Importer.FromDiag(D->getLocation(), | 
|  | 4929 | diag::note_odr_objc_property_impl_kind) | 
|  | 4930 | << D->getPropertyDecl()->getDeclName() | 
|  | 4931 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4932 |  | 
|  | 4933 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4934 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4935 |  | 
|  | 4936 | // For @synthesize, check that we have the same | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4937 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && | 
|  | 4938 | Ivar != ToImpl->getPropertyIvarDecl()) { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4939 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4940 | diag::warn_odr_objc_synthesize_ivar_inconsistent) | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4941 | << Property->getDeclName() | 
|  | 4942 | << ToImpl->getPropertyIvarDecl()->getDeclName() | 
|  | 4943 | << Ivar->getDeclName(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4944 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4945 | diag::note_odr_objc_synthesize_ivar_here) | 
|  | 4946 | << D->getPropertyIvarDecl()->getDeclName(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4947 |  | 
|  | 4948 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4949 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4950 |  | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4951 | // Merge the existing implementation with the new implementation. | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4952 | Importer.MapImported(D, ToImpl); | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4953 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4954 |  | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4955 | return ToImpl; | 
|  | 4956 | } | 
|  | 4957 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4958 | ExpectedDecl | 
|  | 4959 | ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4960 | // For template arguments, we adopt the translation unit as our declaration | 
|  | 4961 | // context. This context will be fixed when the actual template declaration | 
|  | 4962 | // is created. | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4963 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4964 | // FIXME: Import default argument. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4965 |  | 
|  | 4966 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | 
|  | 4967 | if (!BeginLocOrErr) | 
|  | 4968 | return BeginLocOrErr.takeError(); | 
|  | 4969 |  | 
|  | 4970 | ExpectedSLoc LocationOrErr = import(D->getLocation()); | 
|  | 4971 | if (!LocationOrErr) | 
|  | 4972 | return LocationOrErr.takeError(); | 
|  | 4973 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4974 | TemplateTypeParmDecl *ToD = nullptr; | 
|  | 4975 | (void)GetImportedOrCreateDecl( | 
|  | 4976 | ToD, D, Importer.getToContext(), | 
|  | 4977 | Importer.getToContext().getTranslationUnitDecl(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4978 | *BeginLocOrErr, *LocationOrErr, | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4979 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), | 
|  | 4980 | D->wasDeclaredWithTypename(), D->isParameterPack()); | 
|  | 4981 | return ToD; | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4982 | } | 
|  | 4983 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4984 | ExpectedDecl | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4985 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4986 | DeclarationName ToDeclName; | 
|  | 4987 | SourceLocation ToLocation, ToInnerLocStart; | 
|  | 4988 | QualType ToType; | 
|  | 4989 | TypeSourceInfo *ToTypeSourceInfo; | 
|  | 4990 | if (auto Imp = importSeq( | 
|  | 4991 | D->getDeclName(), D->getLocation(), D->getType(), D->getTypeSourceInfo(), | 
|  | 4992 | D->getInnerLocStart())) | 
|  | 4993 | std::tie( | 
|  | 4994 | ToDeclName, ToLocation, ToType, ToTypeSourceInfo, | 
|  | 4995 | ToInnerLocStart) = *Imp; | 
|  | 4996 | else | 
|  | 4997 | return Imp.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4998 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4999 | // FIXME: Import default argument. | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5000 |  | 
|  | 5001 | NonTypeTemplateParmDecl *ToD = nullptr; | 
|  | 5002 | (void)GetImportedOrCreateDecl( | 
|  | 5003 | ToD, D, Importer.getToContext(), | 
|  | 5004 | Importer.getToContext().getTranslationUnitDecl(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5005 | ToInnerLocStart, ToLocation, D->getDepth(), | 
|  | 5006 | D->getPosition(), ToDeclName.getAsIdentifierInfo(), ToType, | 
|  | 5007 | D->isParameterPack(), ToTypeSourceInfo); | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5008 | return ToD; | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5009 | } | 
|  | 5010 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5011 | ExpectedDecl | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5012 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { | 
|  | 5013 | // Import the name of this declaration. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5014 | auto NameOrErr = import(D->getDeclName()); | 
|  | 5015 | if (!NameOrErr) | 
|  | 5016 | return NameOrErr.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5017 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5018 | // Import the location of this declaration. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5019 | ExpectedSLoc LocationOrErr = import(D->getLocation()); | 
|  | 5020 | if (!LocationOrErr) | 
|  | 5021 | return LocationOrErr.takeError(); | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5022 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5023 | // Import template parameters. | 
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5024 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5025 | if (!TemplateParamsOrErr) | 
|  | 5026 | return TemplateParamsOrErr.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5027 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5028 | // FIXME: Import default argument. | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5029 |  | 
|  | 5030 | TemplateTemplateParmDecl *ToD = nullptr; | 
|  | 5031 | (void)GetImportedOrCreateDecl( | 
|  | 5032 | ToD, D, Importer.getToContext(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5033 | Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr, | 
|  | 5034 | D->getDepth(), D->getPosition(), D->isParameterPack(), | 
|  | 5035 | (*NameOrErr).getAsIdentifierInfo(), | 
|  | 5036 | *TemplateParamsOrErr); | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5037 | return ToD; | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5038 | } | 
|  | 5039 |  | 
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5040 | // Returns the definition for a (forward) declaration of a TemplateDecl, if | 
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5041 | // it has any definition in the redecl chain. | 
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5042 | template <typename T> static auto getTemplateDefinition(T *D) -> T * { | 
|  | 5043 | assert(D->getTemplatedDecl() && "Should be called on templates only"); | 
|  | 5044 | auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); | 
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5045 | if (!ToTemplatedDef) | 
|  | 5046 | return nullptr; | 
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5047 | auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate(); | 
|  | 5048 | return cast_or_null<T>(TemplateWithDef); | 
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5049 | } | 
|  | 5050 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5051 | ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { | 
| Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5052 | bool IsFriend = D->getFriendObjectKind() != Decl::FOK_None; | 
|  | 5053 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5054 | // Import the major distinguishing characteristics of this class template. | 
|  | 5055 | DeclContext *DC, *LexicalDC; | 
|  | 5056 | DeclarationName Name; | 
|  | 5057 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5058 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5059 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 5060 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5061 | if (ToD) | 
|  | 5062 | return ToD; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5063 |  | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5064 | ClassTemplateDecl *FoundByLookup = nullptr; | 
|  | 5065 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5066 | // We may already have a template of the same name; try to find and match it. | 
|  | 5067 | if (!DC->isFunctionOrMethod()) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5068 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5069 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5070 | for (auto *FoundDecl : FoundDecls) { | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5071 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary | | 
|  | 5072 | Decl::IDNS_TagFriend)) | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5073 | continue; | 
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5074 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5075 | Decl *Found = FoundDecl; | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5076 | auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found); | 
|  | 5077 | if (FoundTemplate) { | 
| Balázs Kéri | c2f6efc | 2019-11-15 15:05:20 +0100 | [diff] [blame^] | 5078 | if (!hasSameVisibilityContext(FoundTemplate, D)) | 
|  | 5079 | continue; | 
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5080 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5081 | if (IsStructuralMatch(D, FoundTemplate)) { | 
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5082 | ClassTemplateDecl *TemplateWithDef = | 
|  | 5083 | getTemplateDefinition(FoundTemplate); | 
| Balazs Keri | 2e16060 | 2019-08-12 10:07:38 +0000 | [diff] [blame] | 5084 | if (D->isThisDeclarationADefinition() && TemplateWithDef) | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5085 | return Importer.MapImported(D, TemplateWithDef); | 
| Balazs Keri | 2e16060 | 2019-08-12 10:07:38 +0000 | [diff] [blame] | 5086 | if (!FoundByLookup) | 
|  | 5087 | FoundByLookup = FoundTemplate; | 
|  | 5088 | // Search in all matches because there may be multiple decl chains, | 
|  | 5089 | // see ASTTests test ImportExistingFriendClassTemplateDef. | 
|  | 5090 | continue; | 
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5091 | } | 
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 5092 | ConflictingDecls.push_back(FoundDecl); | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5093 | } | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5094 | } | 
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5095 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5096 | if (!ConflictingDecls.empty()) { | 
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 5097 | ExpectedName NameOrErr = Importer.HandleNameConflict( | 
|  | 5098 | Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(), | 
|  | 5099 | ConflictingDecls.size()); | 
|  | 5100 | if (NameOrErr) | 
|  | 5101 | Name = NameOrErr.get(); | 
|  | 5102 | else | 
|  | 5103 | return NameOrErr.takeError(); | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5104 | } | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5105 | } | 
|  | 5106 |  | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5107 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); | 
|  | 5108 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5109 | // Create the declaration that is being templated. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5110 | CXXRecordDecl *ToTemplated; | 
|  | 5111 | if (Error Err = importInto(ToTemplated, FromTemplated)) | 
|  | 5112 | return std::move(Err); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5113 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5114 | // Create the class template declaration itself. | 
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5115 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5116 | if (!TemplateParamsOrErr) | 
|  | 5117 | return TemplateParamsOrErr.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5118 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5119 | ClassTemplateDecl *D2; | 
|  | 5120 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5121 | *TemplateParamsOrErr, ToTemplated)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5122 | return D2; | 
|  | 5123 |  | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5124 | ToTemplated->setDescribedClassTemplate(D2); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5125 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5126 | D2->setAccess(D->getAccess()); | 
|  | 5127 | D2->setLexicalDeclContext(LexicalDC); | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5128 |  | 
|  | 5129 | if (D->getDeclContext()->containsDeclAndLoad(D)) | 
|  | 5130 | DC->addDeclInternal(D2); | 
|  | 5131 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) | 
| Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5132 | LexicalDC->addDeclInternal(D2); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5133 |  | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5134 | if (FoundByLookup) { | 
|  | 5135 | auto *Recent = | 
|  | 5136 | const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl()); | 
|  | 5137 |  | 
|  | 5138 | // It is possible that during the import of the class template definition | 
|  | 5139 | // we start the import of a fwd friend decl of the very same class template | 
|  | 5140 | // and we add the fwd friend decl to the lookup table. But the ToTemplated | 
|  | 5141 | // had been created earlier and by that time the lookup could not find | 
|  | 5142 | // anything existing, so it has no previous decl. Later, (still during the | 
|  | 5143 | // import of the fwd friend decl) we start to import the definition again | 
|  | 5144 | // and this time the lookup finds the previous fwd friend class template. | 
|  | 5145 | // In this case we must set up the previous decl for the templated decl. | 
|  | 5146 | if (!ToTemplated->getPreviousDecl()) { | 
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5147 | assert(FoundByLookup->getTemplatedDecl() && | 
|  | 5148 | "Found decl must have its templated decl set"); | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5149 | CXXRecordDecl *PrevTemplated = | 
|  | 5150 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); | 
|  | 5151 | if (ToTemplated != PrevTemplated) | 
|  | 5152 | ToTemplated->setPreviousDecl(PrevTemplated); | 
|  | 5153 | } | 
|  | 5154 |  | 
|  | 5155 | D2->setPreviousDecl(Recent); | 
|  | 5156 | } | 
|  | 5157 |  | 
|  | 5158 | if (LexicalDC != DC && IsFriend) | 
|  | 5159 | DC->makeDeclVisibleInContext(D2); | 
|  | 5160 |  | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5161 | if (FromTemplated->isCompleteDefinition() && | 
|  | 5162 | !ToTemplated->isCompleteDefinition()) { | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5163 | // FIXME: Import definition! | 
|  | 5164 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5165 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5166 | return D2; | 
|  | 5167 | } | 
|  | 5168 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5169 | ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5170 | ClassTemplateSpecializationDecl *D) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5171 | ClassTemplateDecl *ClassTemplate; | 
|  | 5172 | if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate())) | 
|  | 5173 | return std::move(Err); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5174 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5175 | // Import the context of this declaration. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5176 | DeclContext *DC, *LexicalDC; | 
|  | 5177 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | 
|  | 5178 | return std::move(Err); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5179 |  | 
|  | 5180 | // Import template arguments. | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5181 | SmallVector<TemplateArgument, 2> TemplateArgs; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5182 | if (Error Err = ImportTemplateArguments( | 
|  | 5183 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) | 
|  | 5184 | return std::move(Err); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5185 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5186 | // Try to find an existing specialization with these template arguments. | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5187 | void *InsertPos = nullptr; | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5188 | ClassTemplateSpecializationDecl *PrevDecl = nullptr; | 
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5189 | ClassTemplatePartialSpecializationDecl *PartialSpec = | 
|  | 5190 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D); | 
|  | 5191 | if (PartialSpec) | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5192 | PrevDecl = | 
|  | 5193 | ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos); | 
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5194 | else | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5195 | PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); | 
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5196 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5197 | if (PrevDecl) { | 
|  | 5198 | if (IsStructuralMatch(D, PrevDecl)) { | 
|  | 5199 | if (D->isThisDeclarationADefinition() && PrevDecl->getDefinition()) { | 
|  | 5200 | Importer.MapImported(D, PrevDecl->getDefinition()); | 
|  | 5201 | // Import those default field initializers which have been | 
|  | 5202 | // instantiated in the "From" context, but not in the "To" context. | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 5203 | for (auto *FromField : D->fields()) { | 
|  | 5204 | auto ToOrErr = import(FromField); | 
|  | 5205 | if (!ToOrErr) | 
|  | 5206 | return ToOrErr.takeError(); | 
|  | 5207 | } | 
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5208 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5209 | // Import those methods which have been instantiated in the | 
|  | 5210 | // "From" context, but not in the "To" context. | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 5211 | for (CXXMethodDecl *FromM : D->methods()) { | 
|  | 5212 | auto ToOrErr = import(FromM); | 
|  | 5213 | if (!ToOrErr) | 
|  | 5214 | return ToOrErr.takeError(); | 
|  | 5215 | } | 
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5216 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5217 | // TODO Import instantiated default arguments. | 
|  | 5218 | // TODO Import instantiated exception specifications. | 
|  | 5219 | // | 
|  | 5220 | // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint | 
|  | 5221 | // what else could be fused during an AST merge. | 
|  | 5222 | return PrevDecl; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5223 | } | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5224 | } else { // ODR violation. | 
|  | 5225 | // FIXME HandleNameConflict | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 5226 | return make_error<ImportError>(ImportError::NameConflict); | 
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5227 | } | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5228 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5229 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5230 | // Import the location of this declaration. | 
|  | 5231 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | 
|  | 5232 | if (!BeginLocOrErr) | 
|  | 5233 | return BeginLocOrErr.takeError(); | 
|  | 5234 | ExpectedSLoc IdLocOrErr = import(D->getLocation()); | 
|  | 5235 | if (!IdLocOrErr) | 
|  | 5236 | return IdLocOrErr.takeError(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5237 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5238 | // Create the specialization. | 
|  | 5239 | ClassTemplateSpecializationDecl *D2 = nullptr; | 
|  | 5240 | if (PartialSpec) { | 
|  | 5241 | // Import TemplateArgumentListInfo. | 
|  | 5242 | TemplateArgumentListInfo ToTAInfo; | 
|  | 5243 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); | 
|  | 5244 | if (Error Err = ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) | 
|  | 5245 | return std::move(Err); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5246 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5247 | QualType CanonInjType; | 
|  | 5248 | if (Error Err = importInto( | 
|  | 5249 | CanonInjType, PartialSpec->getInjectedSpecializationType())) | 
|  | 5250 | return std::move(Err); | 
|  | 5251 | CanonInjType = CanonInjType.getCanonicalType(); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5252 |  | 
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5253 | auto ToTPListOrErr = import(PartialSpec->getTemplateParameters()); | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5254 | if (!ToTPListOrErr) | 
|  | 5255 | return ToTPListOrErr.takeError(); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5256 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5257 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( | 
|  | 5258 | D2, D, Importer.getToContext(), D->getTagKind(), DC, | 
|  | 5259 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, ClassTemplate, | 
|  | 5260 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), | 
|  | 5261 | ToTAInfo, CanonInjType, | 
|  | 5262 | cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl))) | 
|  | 5263 | return D2; | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5264 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5265 | // Update InsertPos, because preceding import calls may have invalidated | 
|  | 5266 | // it by adding new specializations. | 
|  | 5267 | if (!ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos)) | 
|  | 5268 | // Add this partial specialization to the class template. | 
|  | 5269 | ClassTemplate->AddPartialSpecialization( | 
|  | 5270 | cast<ClassTemplatePartialSpecializationDecl>(D2), InsertPos); | 
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5271 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5272 | } else { // Not a partial specialization. | 
|  | 5273 | if (GetImportedOrCreateDecl( | 
|  | 5274 | D2, D, Importer.getToContext(), D->getTagKind(), DC, | 
|  | 5275 | *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs, | 
|  | 5276 | PrevDecl)) | 
|  | 5277 | return D2; | 
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5278 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5279 | // Update InsertPos, because preceding import calls may have invalidated | 
|  | 5280 | // it by adding new specializations. | 
|  | 5281 | if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos)) | 
|  | 5282 | // Add this specialization to the class template. | 
|  | 5283 | ClassTemplate->AddSpecialization(D2, InsertPos); | 
|  | 5284 | } | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5285 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5286 | D2->setSpecializationKind(D->getSpecializationKind()); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5287 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5288 | // Set the context of this specialization/instantiation. | 
|  | 5289 | D2->setLexicalDeclContext(LexicalDC); | 
|  | 5290 |  | 
|  | 5291 | // Add to the DC only if it was an explicit specialization/instantiation. | 
|  | 5292 | if (D2->isExplicitInstantiationOrSpecialization()) { | 
|  | 5293 | LexicalDC->addDeclInternal(D2); | 
|  | 5294 | } | 
|  | 5295 |  | 
|  | 5296 | // Import the qualifier, if any. | 
|  | 5297 | if (auto LocOrErr = import(D->getQualifierLoc())) | 
|  | 5298 | D2->setQualifierInfo(*LocOrErr); | 
|  | 5299 | else | 
|  | 5300 | return LocOrErr.takeError(); | 
|  | 5301 |  | 
|  | 5302 | if (auto *TSI = D->getTypeAsWritten()) { | 
|  | 5303 | if (auto TInfoOrErr = import(TSI)) | 
|  | 5304 | D2->setTypeAsWritten(*TInfoOrErr); | 
|  | 5305 | else | 
|  | 5306 | return TInfoOrErr.takeError(); | 
|  | 5307 |  | 
|  | 5308 | if (auto LocOrErr = import(D->getTemplateKeywordLoc())) | 
|  | 5309 | D2->setTemplateKeywordLoc(*LocOrErr); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5310 | else | 
|  | 5311 | return LocOrErr.takeError(); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5312 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5313 | if (auto LocOrErr = import(D->getExternLoc())) | 
|  | 5314 | D2->setExternLoc(*LocOrErr); | 
|  | 5315 | else | 
|  | 5316 | return LocOrErr.takeError(); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5317 | } | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5318 |  | 
|  | 5319 | if (D->getPointOfInstantiation().isValid()) { | 
|  | 5320 | if (auto POIOrErr = import(D->getPointOfInstantiation())) | 
|  | 5321 | D2->setPointOfInstantiation(*POIOrErr); | 
|  | 5322 | else | 
|  | 5323 | return POIOrErr.takeError(); | 
|  | 5324 | } | 
|  | 5325 |  | 
|  | 5326 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); | 
|  | 5327 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5328 | if (D->isCompleteDefinition()) | 
|  | 5329 | if (Error Err = ImportDefinition(D, D2)) | 
|  | 5330 | return std::move(Err); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5331 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5332 | return D2; | 
|  | 5333 | } | 
|  | 5334 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5335 | ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5336 | // If this variable has a definition in the translation unit we're coming | 
|  | 5337 | // from, | 
|  | 5338 | // but this particular declaration is not that definition, import the | 
|  | 5339 | // definition and map to that. | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5340 | auto *Definition = | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5341 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); | 
|  | 5342 | if (Definition && Definition != D->getTemplatedDecl()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5343 | if (ExpectedDecl ImportedDefOrErr = import( | 
|  | 5344 | Definition->getDescribedVarTemplate())) | 
|  | 5345 | return Importer.MapImported(D, *ImportedDefOrErr); | 
|  | 5346 | else | 
|  | 5347 | return ImportedDefOrErr.takeError(); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5348 | } | 
|  | 5349 |  | 
|  | 5350 | // Import the major distinguishing characteristics of this variable template. | 
|  | 5351 | DeclContext *DC, *LexicalDC; | 
|  | 5352 | DeclarationName Name; | 
|  | 5353 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5354 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5355 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 5356 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5357 | if (ToD) | 
|  | 5358 | return ToD; | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5359 |  | 
|  | 5360 | // We may already have a template of the same name; try to find and match it. | 
|  | 5361 | assert(!DC->isFunctionOrMethod() && | 
|  | 5362 | "Variable templates cannot be declared at function scope"); | 
|  | 5363 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5364 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5365 | for (auto *FoundDecl : FoundDecls) { | 
|  | 5366 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5367 | continue; | 
|  | 5368 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5369 | Decl *Found = FoundDecl; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5370 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5371 | if (IsStructuralMatch(D, FoundTemplate)) { | 
|  | 5372 | // The variable templates structurally match; call it the same template. | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5373 | Importer.MapImported(D->getTemplatedDecl(), | 
|  | 5374 | FoundTemplate->getTemplatedDecl()); | 
|  | 5375 | return Importer.MapImported(D, FoundTemplate); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5376 | } | 
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 5377 | ConflictingDecls.push_back(FoundDecl); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5378 | } | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5379 | } | 
|  | 5380 |  | 
|  | 5381 | if (!ConflictingDecls.empty()) { | 
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 5382 | ExpectedName NameOrErr = Importer.HandleNameConflict( | 
|  | 5383 | Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(), | 
|  | 5384 | ConflictingDecls.size()); | 
|  | 5385 | if (NameOrErr) | 
|  | 5386 | Name = NameOrErr.get(); | 
|  | 5387 | else | 
|  | 5388 | return NameOrErr.takeError(); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5389 | } | 
|  | 5390 |  | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5391 | VarDecl *DTemplated = D->getTemplatedDecl(); | 
|  | 5392 |  | 
|  | 5393 | // Import the type. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5394 | // FIXME: Value not used? | 
|  | 5395 | ExpectedType TypeOrErr = import(DTemplated->getType()); | 
|  | 5396 | if (!TypeOrErr) | 
|  | 5397 | return TypeOrErr.takeError(); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5398 |  | 
|  | 5399 | // Create the declaration that is being templated. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5400 | VarDecl *ToTemplated; | 
|  | 5401 | if (Error Err = importInto(ToTemplated, DTemplated)) | 
|  | 5402 | return std::move(Err); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5403 |  | 
|  | 5404 | // Create the variable template declaration itself. | 
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5405 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5406 | if (!TemplateParamsOrErr) | 
|  | 5407 | return TemplateParamsOrErr.takeError(); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5408 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5409 | VarTemplateDecl *ToVarTD; | 
|  | 5410 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5411 | Name, *TemplateParamsOrErr, ToTemplated)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5412 | return ToVarTD; | 
|  | 5413 |  | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5414 | ToTemplated->setDescribedVarTemplate(ToVarTD); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5415 |  | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5416 | ToVarTD->setAccess(D->getAccess()); | 
|  | 5417 | ToVarTD->setLexicalDeclContext(LexicalDC); | 
|  | 5418 | LexicalDC->addDeclInternal(ToVarTD); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5419 |  | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5420 | if (DTemplated->isThisDeclarationADefinition() && | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5421 | !ToTemplated->isThisDeclarationADefinition()) { | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5422 | // FIXME: Import definition! | 
|  | 5423 | } | 
|  | 5424 |  | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5425 | return ToVarTD; | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5426 | } | 
|  | 5427 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5428 | ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl( | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5429 | VarTemplateSpecializationDecl *D) { | 
|  | 5430 | // If this record has a definition in the translation unit we're coming from, | 
|  | 5431 | // but this particular declaration is not that definition, import the | 
|  | 5432 | // definition and map to that. | 
|  | 5433 | VarDecl *Definition = D->getDefinition(); | 
|  | 5434 | if (Definition && Definition != D) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5435 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) | 
|  | 5436 | return Importer.MapImported(D, *ImportedDefOrErr); | 
|  | 5437 | else | 
|  | 5438 | return ImportedDefOrErr.takeError(); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5439 | } | 
|  | 5440 |  | 
| Simon Pilgrim | 4c146ab | 2019-05-18 11:33:27 +0000 | [diff] [blame] | 5441 | VarTemplateDecl *VarTemplate = nullptr; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5442 | if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate())) | 
|  | 5443 | return std::move(Err); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5444 |  | 
|  | 5445 | // Import the context of this declaration. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5446 | DeclContext *DC, *LexicalDC; | 
|  | 5447 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | 
|  | 5448 | return std::move(Err); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5449 |  | 
|  | 5450 | // Import the location of this declaration. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5451 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | 
|  | 5452 | if (!BeginLocOrErr) | 
|  | 5453 | return BeginLocOrErr.takeError(); | 
|  | 5454 |  | 
|  | 5455 | auto IdLocOrErr = import(D->getLocation()); | 
|  | 5456 | if (!IdLocOrErr) | 
|  | 5457 | return IdLocOrErr.takeError(); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5458 |  | 
|  | 5459 | // Import template arguments. | 
|  | 5460 | SmallVector<TemplateArgument, 2> TemplateArgs; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5461 | if (Error Err = ImportTemplateArguments( | 
|  | 5462 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) | 
|  | 5463 | return std::move(Err); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5464 |  | 
|  | 5465 | // Try to find an existing specialization with these template arguments. | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5466 | void *InsertPos = nullptr; | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5467 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( | 
| Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 5468 | TemplateArgs, InsertPos); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5469 | if (D2) { | 
|  | 5470 | // We already have a variable template specialization with these template | 
|  | 5471 | // arguments. | 
|  | 5472 |  | 
|  | 5473 | // FIXME: Check for specialization vs. instantiation errors. | 
|  | 5474 |  | 
|  | 5475 | if (VarDecl *FoundDef = D2->getDefinition()) { | 
|  | 5476 | if (!D->isThisDeclarationADefinition() || | 
|  | 5477 | IsStructuralMatch(D, FoundDef)) { | 
|  | 5478 | // The record types structurally match, or the "from" translation | 
|  | 5479 | // unit only had a forward declaration anyway; call it the same | 
|  | 5480 | // variable. | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5481 | return Importer.MapImported(D, FoundDef); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5482 | } | 
|  | 5483 | } | 
|  | 5484 | } else { | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5485 | // Import the type. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5486 | QualType T; | 
|  | 5487 | if (Error Err = importInto(T, D->getType())) | 
|  | 5488 | return std::move(Err); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5489 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5490 | auto TInfoOrErr = import(D->getTypeSourceInfo()); | 
|  | 5491 | if (!TInfoOrErr) | 
|  | 5492 | return TInfoOrErr.takeError(); | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5493 |  | 
|  | 5494 | TemplateArgumentListInfo ToTAInfo; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5495 | if (Error Err = ImportTemplateArgumentListInfo( | 
|  | 5496 | D->getTemplateArgsInfo(), ToTAInfo)) | 
|  | 5497 | return std::move(Err); | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5498 |  | 
|  | 5499 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5500 | // Create a new specialization. | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5501 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { | 
|  | 5502 | // Import TemplateArgumentListInfo | 
|  | 5503 | TemplateArgumentListInfo ArgInfos; | 
|  | 5504 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); | 
|  | 5505 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5506 | if (Error Err = ImportTemplateArgumentListInfo( | 
|  | 5507 | *FromTAArgsAsWritten, ArgInfos)) | 
|  | 5508 | return std::move(Err); | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5509 |  | 
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5510 | auto ToTPListOrErr = import(FromPartial->getTemplateParameters()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5511 | if (!ToTPListOrErr) | 
|  | 5512 | return ToTPListOrErr.takeError(); | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5513 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5514 | PartVarSpecDecl *ToPartial; | 
|  | 5515 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5516 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, | 
|  | 5517 | VarTemplate, T, *TInfoOrErr, | 
|  | 5518 | D->getStorageClass(), TemplateArgs, ArgInfos)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5519 | return ToPartial; | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5520 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5521 | if (Expected<PartVarSpecDecl *> ToInstOrErr = import( | 
|  | 5522 | FromPartial->getInstantiatedFromMember())) | 
|  | 5523 | ToPartial->setInstantiatedFromMember(*ToInstOrErr); | 
|  | 5524 | else | 
|  | 5525 | return ToInstOrErr.takeError(); | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5526 |  | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5527 | if (FromPartial->isMemberSpecialization()) | 
|  | 5528 | ToPartial->setMemberSpecialization(); | 
|  | 5529 |  | 
|  | 5530 | D2 = ToPartial; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5531 |  | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5532 | } else { // Full specialization | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5533 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, | 
|  | 5534 | *BeginLocOrErr, *IdLocOrErr, VarTemplate, | 
|  | 5535 | T, *TInfoOrErr, | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5536 | D->getStorageClass(), TemplateArgs)) | 
|  | 5537 | return D2; | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5538 | } | 
|  | 5539 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5540 | if (D->getPointOfInstantiation().isValid()) { | 
|  | 5541 | if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation())) | 
|  | 5542 | D2->setPointOfInstantiation(*POIOrErr); | 
|  | 5543 | else | 
|  | 5544 | return POIOrErr.takeError(); | 
|  | 5545 | } | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5546 |  | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5547 | D2->setSpecializationKind(D->getSpecializationKind()); | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5548 | D2->setTemplateArgsInfo(ToTAInfo); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5549 |  | 
|  | 5550 | // Add this specialization to the class template. | 
|  | 5551 | VarTemplate->AddSpecialization(D2, InsertPos); | 
|  | 5552 |  | 
|  | 5553 | // Import the qualifier, if any. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5554 | if (auto LocOrErr = import(D->getQualifierLoc())) | 
|  | 5555 | D2->setQualifierInfo(*LocOrErr); | 
|  | 5556 | else | 
|  | 5557 | return LocOrErr.takeError(); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5558 |  | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5559 | if (D->isConstexpr()) | 
|  | 5560 | D2->setConstexpr(true); | 
|  | 5561 |  | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5562 | // Add the specialization to this context. | 
|  | 5563 | D2->setLexicalDeclContext(LexicalDC); | 
|  | 5564 | LexicalDC->addDeclInternal(D2); | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5565 |  | 
|  | 5566 | D2->setAccess(D->getAccess()); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5567 | } | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5568 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5569 | if (Error Err = ImportInitializer(D, D2)) | 
|  | 5570 | return std::move(Err); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5571 |  | 
|  | 5572 | return D2; | 
|  | 5573 | } | 
|  | 5574 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5575 | ExpectedDecl | 
|  | 5576 | ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5577 | DeclContext *DC, *LexicalDC; | 
|  | 5578 | DeclarationName Name; | 
|  | 5579 | SourceLocation Loc; | 
|  | 5580 | NamedDecl *ToD; | 
|  | 5581 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5582 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 5583 | return std::move(Err); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5584 |  | 
|  | 5585 | if (ToD) | 
|  | 5586 | return ToD; | 
|  | 5587 |  | 
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5588 | const FunctionTemplateDecl *FoundByLookup = nullptr; | 
|  | 5589 |  | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5590 | // Try to find a function in our own ("to") context with the same name, same | 
|  | 5591 | // type, and in the same context as the function we're importing. | 
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5592 | // FIXME Split this into a separate function. | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5593 | if (!LexicalDC->isFunctionOrMethod()) { | 
| Gabor Marton | e331e63 | 2019-02-18 13:09:27 +0000 | [diff] [blame] | 5594 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5595 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5596 | for (auto *FoundDecl : FoundDecls) { | 
|  | 5597 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5598 | continue; | 
|  | 5599 |  | 
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5600 | if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) { | 
| Balazs Keri | f8a89c8 | 2019-09-13 08:03:49 +0000 | [diff] [blame] | 5601 | if (!hasSameVisibilityContext(FoundTemplate, D)) | 
|  | 5602 | continue; | 
|  | 5603 | if (IsStructuralMatch(D, FoundTemplate)) { | 
|  | 5604 | FunctionTemplateDecl *TemplateWithDef = | 
|  | 5605 | getTemplateDefinition(FoundTemplate); | 
|  | 5606 | if (D->isThisDeclarationADefinition() && TemplateWithDef) | 
|  | 5607 | return Importer.MapImported(D, TemplateWithDef); | 
|  | 5608 |  | 
|  | 5609 | FoundByLookup = FoundTemplate; | 
|  | 5610 | break; | 
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5611 | // TODO: handle conflicting names | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5612 | } | 
|  | 5613 | } | 
|  | 5614 | } | 
|  | 5615 | } | 
|  | 5616 |  | 
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5617 | auto ParamsOrErr = import(D->getTemplateParameters()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5618 | if (!ParamsOrErr) | 
|  | 5619 | return ParamsOrErr.takeError(); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5620 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5621 | FunctionDecl *TemplatedFD; | 
|  | 5622 | if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl())) | 
|  | 5623 | return std::move(Err); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5624 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5625 | FunctionTemplateDecl *ToFunc; | 
|  | 5626 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5627 | *ParamsOrErr, TemplatedFD)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5628 | return ToFunc; | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5629 |  | 
|  | 5630 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); | 
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5631 |  | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5632 | ToFunc->setAccess(D->getAccess()); | 
|  | 5633 | ToFunc->setLexicalDeclContext(LexicalDC); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5634 | LexicalDC->addDeclInternal(ToFunc); | 
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5635 |  | 
|  | 5636 | if (FoundByLookup) { | 
|  | 5637 | auto *Recent = | 
|  | 5638 | const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl()); | 
|  | 5639 | if (!TemplatedFD->getPreviousDecl()) { | 
|  | 5640 | assert(FoundByLookup->getTemplatedDecl() && | 
|  | 5641 | "Found decl must have its templated decl set"); | 
|  | 5642 | auto *PrevTemplated = | 
|  | 5643 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); | 
|  | 5644 | if (TemplatedFD != PrevTemplated) | 
|  | 5645 | TemplatedFD->setPreviousDecl(PrevTemplated); | 
|  | 5646 | } | 
|  | 5647 | ToFunc->setPreviousDecl(Recent); | 
|  | 5648 | } | 
|  | 5649 |  | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5650 | return ToFunc; | 
|  | 5651 | } | 
|  | 5652 |  | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5653 | //---------------------------------------------------------------------------- | 
|  | 5654 | // Import Statements | 
|  | 5655 | //---------------------------------------------------------------------------- | 
|  | 5656 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5657 | ExpectedStmt ASTNodeImporter::VisitStmt(Stmt *S) { | 
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5658 | Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node) | 
|  | 5659 | << S->getStmtClassName(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5660 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5661 | } | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5662 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5663 |  | 
|  | 5664 | ExpectedStmt ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 5665 | if (Importer.returnWithErrorInTest()) | 
|  | 5666 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5667 | SmallVector<IdentifierInfo *, 4> Names; | 
|  | 5668 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { | 
|  | 5669 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); | 
| Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5670 | // ToII is nullptr when no symbolic name is given for output operand | 
|  | 5671 | // see ParseStmtAsm::ParseAsmOperandsOpt | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5672 | Names.push_back(ToII); | 
|  | 5673 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5674 |  | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5675 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { | 
|  | 5676 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); | 
| Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5677 | // ToII is nullptr when no symbolic name is given for input operand | 
|  | 5678 | // see ParseStmtAsm::ParseAsmOperandsOpt | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5679 | Names.push_back(ToII); | 
|  | 5680 | } | 
|  | 5681 |  | 
|  | 5682 | SmallVector<StringLiteral *, 4> Clobbers; | 
|  | 5683 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5684 | if (auto ClobberOrErr = import(S->getClobberStringLiteral(I))) | 
|  | 5685 | Clobbers.push_back(*ClobberOrErr); | 
|  | 5686 | else | 
|  | 5687 | return ClobberOrErr.takeError(); | 
|  | 5688 |  | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5689 | } | 
|  | 5690 |  | 
|  | 5691 | SmallVector<StringLiteral *, 4> Constraints; | 
|  | 5692 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5693 | if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I))) | 
|  | 5694 | Constraints.push_back(*OutputOrErr); | 
|  | 5695 | else | 
|  | 5696 | return OutputOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5697 | } | 
|  | 5698 |  | 
|  | 5699 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5700 | if (auto InputOrErr = import(S->getInputConstraintLiteral(I))) | 
|  | 5701 | Constraints.push_back(*InputOrErr); | 
|  | 5702 | else | 
|  | 5703 | return InputOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5704 | } | 
|  | 5705 |  | 
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5706 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs() + | 
|  | 5707 | S->getNumLabels()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5708 | if (Error Err = ImportContainerChecked(S->outputs(), Exprs)) | 
|  | 5709 | return std::move(Err); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5710 |  | 
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5711 | if (Error Err = | 
|  | 5712 | ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs())) | 
|  | 5713 | return std::move(Err); | 
|  | 5714 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5715 | if (Error Err = ImportArrayChecked( | 
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5716 | S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs())) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5717 | return std::move(Err); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5718 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5719 | ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc()); | 
|  | 5720 | if (!AsmLocOrErr) | 
|  | 5721 | return AsmLocOrErr.takeError(); | 
|  | 5722 | auto AsmStrOrErr = import(S->getAsmString()); | 
|  | 5723 | if (!AsmStrOrErr) | 
|  | 5724 | return AsmStrOrErr.takeError(); | 
|  | 5725 | ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc()); | 
|  | 5726 | if (!RParenLocOrErr) | 
|  | 5727 | return RParenLocOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5728 |  | 
|  | 5729 | return new (Importer.getToContext()) GCCAsmStmt( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5730 | Importer.getToContext(), | 
|  | 5731 | *AsmLocOrErr, | 
|  | 5732 | S->isSimple(), | 
|  | 5733 | S->isVolatile(), | 
|  | 5734 | S->getNumOutputs(), | 
|  | 5735 | S->getNumInputs(), | 
|  | 5736 | Names.data(), | 
|  | 5737 | Constraints.data(), | 
|  | 5738 | Exprs.data(), | 
|  | 5739 | *AsmStrOrErr, | 
|  | 5740 | S->getNumClobbers(), | 
|  | 5741 | Clobbers.data(), | 
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5742 | S->getNumLabels(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5743 | *RParenLocOrErr); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5744 | } | 
|  | 5745 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5746 | ExpectedStmt ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { | 
|  | 5747 | auto Imp = importSeq(S->getDeclGroup(), S->getBeginLoc(), S->getEndLoc()); | 
|  | 5748 | if (!Imp) | 
|  | 5749 | return Imp.takeError(); | 
|  | 5750 |  | 
|  | 5751 | DeclGroupRef ToDG; | 
|  | 5752 | SourceLocation ToBeginLoc, ToEndLoc; | 
|  | 5753 | std::tie(ToDG, ToBeginLoc, ToEndLoc) = *Imp; | 
|  | 5754 |  | 
|  | 5755 | return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5756 | } | 
|  | 5757 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5758 | ExpectedStmt ASTNodeImporter::VisitNullStmt(NullStmt *S) { | 
|  | 5759 | ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc()); | 
|  | 5760 | if (!ToSemiLocOrErr) | 
|  | 5761 | return ToSemiLocOrErr.takeError(); | 
|  | 5762 | return new (Importer.getToContext()) NullStmt( | 
|  | 5763 | *ToSemiLocOrErr, S->hasLeadingEmptyMacro()); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5764 | } | 
|  | 5765 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5766 | ExpectedStmt ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5767 | SmallVector<Stmt *, 8> ToStmts(S->size()); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5768 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5769 | if (Error Err = ImportContainerChecked(S->body(), ToStmts)) | 
|  | 5770 | return std::move(Err); | 
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5771 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5772 | ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc()); | 
|  | 5773 | if (!ToLBracLocOrErr) | 
|  | 5774 | return ToLBracLocOrErr.takeError(); | 
|  | 5775 |  | 
|  | 5776 | ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc()); | 
|  | 5777 | if (!ToRBracLocOrErr) | 
|  | 5778 | return ToRBracLocOrErr.takeError(); | 
|  | 5779 |  | 
|  | 5780 | return CompoundStmt::Create( | 
|  | 5781 | Importer.getToContext(), ToStmts, | 
|  | 5782 | *ToLBracLocOrErr, *ToRBracLocOrErr); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5783 | } | 
|  | 5784 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5785 | ExpectedStmt ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { | 
|  | 5786 | auto Imp = importSeq( | 
|  | 5787 | S->getLHS(), S->getRHS(), S->getSubStmt(), S->getCaseLoc(), | 
|  | 5788 | S->getEllipsisLoc(), S->getColonLoc()); | 
|  | 5789 | if (!Imp) | 
|  | 5790 | return Imp.takeError(); | 
|  | 5791 |  | 
|  | 5792 | Expr *ToLHS, *ToRHS; | 
|  | 5793 | Stmt *ToSubStmt; | 
|  | 5794 | SourceLocation ToCaseLoc, ToEllipsisLoc, ToColonLoc; | 
|  | 5795 | std::tie(ToLHS, ToRHS, ToSubStmt, ToCaseLoc, ToEllipsisLoc, ToColonLoc) = | 
|  | 5796 | *Imp; | 
|  | 5797 |  | 
| Bruno Ricci | 5b3057175 | 2018-10-28 12:30:53 +0000 | [diff] [blame] | 5798 | auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS, | 
|  | 5799 | ToCaseLoc, ToEllipsisLoc, ToColonLoc); | 
| Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5800 | ToStmt->setSubStmt(ToSubStmt); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5801 |  | 
| Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5802 | return ToStmt; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5803 | } | 
|  | 5804 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5805 | ExpectedStmt ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { | 
|  | 5806 | auto Imp = importSeq(S->getDefaultLoc(), S->getColonLoc(), S->getSubStmt()); | 
|  | 5807 | if (!Imp) | 
|  | 5808 | return Imp.takeError(); | 
|  | 5809 |  | 
|  | 5810 | SourceLocation ToDefaultLoc, ToColonLoc; | 
|  | 5811 | Stmt *ToSubStmt; | 
|  | 5812 | std::tie(ToDefaultLoc, ToColonLoc, ToSubStmt) = *Imp; | 
|  | 5813 |  | 
|  | 5814 | return new (Importer.getToContext()) DefaultStmt( | 
|  | 5815 | ToDefaultLoc, ToColonLoc, ToSubStmt); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5816 | } | 
|  | 5817 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5818 | ExpectedStmt ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { | 
|  | 5819 | auto Imp = importSeq(S->getIdentLoc(), S->getDecl(), S->getSubStmt()); | 
|  | 5820 | if (!Imp) | 
|  | 5821 | return Imp.takeError(); | 
|  | 5822 |  | 
|  | 5823 | SourceLocation ToIdentLoc; | 
|  | 5824 | LabelDecl *ToLabelDecl; | 
|  | 5825 | Stmt *ToSubStmt; | 
|  | 5826 | std::tie(ToIdentLoc, ToLabelDecl, ToSubStmt) = *Imp; | 
|  | 5827 |  | 
|  | 5828 | return new (Importer.getToContext()) LabelStmt( | 
|  | 5829 | ToIdentLoc, ToLabelDecl, ToSubStmt); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5830 | } | 
|  | 5831 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5832 | ExpectedStmt ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { | 
|  | 5833 | ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc()); | 
|  | 5834 | if (!ToAttrLocOrErr) | 
|  | 5835 | return ToAttrLocOrErr.takeError(); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5836 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); | 
|  | 5837 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5838 | if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs)) | 
|  | 5839 | return std::move(Err); | 
|  | 5840 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); | 
|  | 5841 | if (!ToSubStmtOrErr) | 
|  | 5842 | return ToSubStmtOrErr.takeError(); | 
|  | 5843 |  | 
|  | 5844 | return AttributedStmt::Create( | 
|  | 5845 | Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5846 | } | 
|  | 5847 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5848 | ExpectedStmt ASTNodeImporter::VisitIfStmt(IfStmt *S) { | 
|  | 5849 | auto Imp = importSeq( | 
|  | 5850 | S->getIfLoc(), S->getInit(), S->getConditionVariable(), S->getCond(), | 
|  | 5851 | S->getThen(), S->getElseLoc(), S->getElse()); | 
|  | 5852 | if (!Imp) | 
|  | 5853 | return Imp.takeError(); | 
|  | 5854 |  | 
|  | 5855 | SourceLocation ToIfLoc, ToElseLoc; | 
|  | 5856 | Stmt *ToInit, *ToThen, *ToElse; | 
|  | 5857 | VarDecl *ToConditionVariable; | 
|  | 5858 | Expr *ToCond; | 
|  | 5859 | std::tie( | 
|  | 5860 | ToIfLoc, ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, ToElse) = | 
|  | 5861 | *Imp; | 
|  | 5862 |  | 
| Bruno Ricci | b1cc94b | 2018-10-27 21:12:20 +0000 | [diff] [blame] | 5863 | return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->isConstexpr(), | 
|  | 5864 | ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, | 
|  | 5865 | ToElse); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5866 | } | 
|  | 5867 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5868 | ExpectedStmt ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { | 
|  | 5869 | auto Imp = importSeq( | 
|  | 5870 | S->getInit(), S->getConditionVariable(), S->getCond(), | 
|  | 5871 | S->getBody(), S->getSwitchLoc()); | 
|  | 5872 | if (!Imp) | 
|  | 5873 | return Imp.takeError(); | 
|  | 5874 |  | 
|  | 5875 | Stmt *ToInit, *ToBody; | 
|  | 5876 | VarDecl *ToConditionVariable; | 
|  | 5877 | Expr *ToCond; | 
|  | 5878 | SourceLocation ToSwitchLoc; | 
|  | 5879 | std::tie(ToInit, ToConditionVariable, ToCond, ToBody, ToSwitchLoc) = *Imp; | 
|  | 5880 |  | 
| Bruno Ricci | e2806f8 | 2018-10-29 16:12:37 +0000 | [diff] [blame] | 5881 | auto *ToStmt = SwitchStmt::Create(Importer.getToContext(), ToInit, | 
|  | 5882 | ToConditionVariable, ToCond); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5883 | ToStmt->setBody(ToBody); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5884 | ToStmt->setSwitchLoc(ToSwitchLoc); | 
|  | 5885 |  | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5886 | // Now we have to re-chain the cases. | 
|  | 5887 | SwitchCase *LastChainedSwitchCase = nullptr; | 
|  | 5888 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; | 
|  | 5889 | SC = SC->getNextSwitchCase()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5890 | Expected<SwitchCase *> ToSCOrErr = import(SC); | 
|  | 5891 | if (!ToSCOrErr) | 
|  | 5892 | return ToSCOrErr.takeError(); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5893 | if (LastChainedSwitchCase) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5894 | LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5895 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5896 | ToStmt->setSwitchCaseList(*ToSCOrErr); | 
|  | 5897 | LastChainedSwitchCase = *ToSCOrErr; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5898 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5899 |  | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5900 | return ToStmt; | 
|  | 5901 | } | 
|  | 5902 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5903 | ExpectedStmt ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { | 
|  | 5904 | auto Imp = importSeq( | 
|  | 5905 | S->getConditionVariable(), S->getCond(), S->getBody(), S->getWhileLoc()); | 
|  | 5906 | if (!Imp) | 
|  | 5907 | return Imp.takeError(); | 
|  | 5908 |  | 
|  | 5909 | VarDecl *ToConditionVariable; | 
|  | 5910 | Expr *ToCond; | 
|  | 5911 | Stmt *ToBody; | 
|  | 5912 | SourceLocation ToWhileLoc; | 
|  | 5913 | std::tie(ToConditionVariable, ToCond, ToBody, ToWhileLoc) = *Imp; | 
|  | 5914 |  | 
| Bruno Ricci | bacf751 | 2018-10-30 13:42:41 +0000 | [diff] [blame] | 5915 | return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond, | 
|  | 5916 | ToBody, ToWhileLoc); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5917 | } | 
|  | 5918 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5919 | ExpectedStmt ASTNodeImporter::VisitDoStmt(DoStmt *S) { | 
|  | 5920 | auto Imp = importSeq( | 
|  | 5921 | S->getBody(), S->getCond(), S->getDoLoc(), S->getWhileLoc(), | 
|  | 5922 | S->getRParenLoc()); | 
|  | 5923 | if (!Imp) | 
|  | 5924 | return Imp.takeError(); | 
|  | 5925 |  | 
|  | 5926 | Stmt *ToBody; | 
|  | 5927 | Expr *ToCond; | 
|  | 5928 | SourceLocation ToDoLoc, ToWhileLoc, ToRParenLoc; | 
|  | 5929 | std::tie(ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc) = *Imp; | 
|  | 5930 |  | 
|  | 5931 | return new (Importer.getToContext()) DoStmt( | 
|  | 5932 | ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5933 | } | 
|  | 5934 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5935 | ExpectedStmt ASTNodeImporter::VisitForStmt(ForStmt *S) { | 
|  | 5936 | auto Imp = importSeq( | 
|  | 5937 | S->getInit(), S->getCond(), S->getConditionVariable(), S->getInc(), | 
|  | 5938 | S->getBody(), S->getForLoc(), S->getLParenLoc(), S->getRParenLoc()); | 
|  | 5939 | if (!Imp) | 
|  | 5940 | return Imp.takeError(); | 
|  | 5941 |  | 
|  | 5942 | Stmt *ToInit; | 
|  | 5943 | Expr *ToCond, *ToInc; | 
|  | 5944 | VarDecl *ToConditionVariable; | 
|  | 5945 | Stmt *ToBody; | 
|  | 5946 | SourceLocation ToForLoc, ToLParenLoc, ToRParenLoc; | 
|  | 5947 | std::tie( | 
|  | 5948 | ToInit, ToCond, ToConditionVariable,  ToInc, ToBody, ToForLoc, | 
|  | 5949 | ToLParenLoc, ToRParenLoc) = *Imp; | 
|  | 5950 |  | 
|  | 5951 | return new (Importer.getToContext()) ForStmt( | 
|  | 5952 | Importer.getToContext(), | 
|  | 5953 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc, | 
|  | 5954 | ToRParenLoc); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5955 | } | 
|  | 5956 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5957 | ExpectedStmt ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { | 
|  | 5958 | auto Imp = importSeq(S->getLabel(), S->getGotoLoc(), S->getLabelLoc()); | 
|  | 5959 | if (!Imp) | 
|  | 5960 | return Imp.takeError(); | 
|  | 5961 |  | 
|  | 5962 | LabelDecl *ToLabel; | 
|  | 5963 | SourceLocation ToGotoLoc, ToLabelLoc; | 
|  | 5964 | std::tie(ToLabel, ToGotoLoc, ToLabelLoc) = *Imp; | 
|  | 5965 |  | 
|  | 5966 | return new (Importer.getToContext()) GotoStmt( | 
|  | 5967 | ToLabel, ToGotoLoc, ToLabelLoc); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5968 | } | 
|  | 5969 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5970 | ExpectedStmt ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { | 
|  | 5971 | auto Imp = importSeq(S->getGotoLoc(), S->getStarLoc(), S->getTarget()); | 
|  | 5972 | if (!Imp) | 
|  | 5973 | return Imp.takeError(); | 
|  | 5974 |  | 
|  | 5975 | SourceLocation ToGotoLoc, ToStarLoc; | 
|  | 5976 | Expr *ToTarget; | 
|  | 5977 | std::tie(ToGotoLoc, ToStarLoc, ToTarget) = *Imp; | 
|  | 5978 |  | 
|  | 5979 | return new (Importer.getToContext()) IndirectGotoStmt( | 
|  | 5980 | ToGotoLoc, ToStarLoc, ToTarget); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5981 | } | 
|  | 5982 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5983 | ExpectedStmt ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { | 
|  | 5984 | ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc()); | 
|  | 5985 | if (!ToContinueLocOrErr) | 
|  | 5986 | return ToContinueLocOrErr.takeError(); | 
|  | 5987 | return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5988 | } | 
|  | 5989 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5990 | ExpectedStmt ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { | 
|  | 5991 | auto ToBreakLocOrErr = import(S->getBreakLoc()); | 
|  | 5992 | if (!ToBreakLocOrErr) | 
|  | 5993 | return ToBreakLocOrErr.takeError(); | 
|  | 5994 | return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5995 | } | 
|  | 5996 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5997 | ExpectedStmt ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { | 
|  | 5998 | auto Imp = importSeq( | 
|  | 5999 | S->getReturnLoc(), S->getRetValue(), S->getNRVOCandidate()); | 
|  | 6000 | if (!Imp) | 
|  | 6001 | return Imp.takeError(); | 
|  | 6002 |  | 
|  | 6003 | SourceLocation ToReturnLoc; | 
|  | 6004 | Expr *ToRetValue; | 
|  | 6005 | const VarDecl *ToNRVOCandidate; | 
|  | 6006 | std::tie(ToReturnLoc, ToRetValue, ToNRVOCandidate) = *Imp; | 
|  | 6007 |  | 
| Bruno Ricci | 023b1d1 | 2018-10-30 14:40:49 +0000 | [diff] [blame] | 6008 | return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue, | 
|  | 6009 | ToNRVOCandidate); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6010 | } | 
|  | 6011 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6012 | ExpectedStmt ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { | 
|  | 6013 | auto Imp = importSeq( | 
|  | 6014 | S->getCatchLoc(), S->getExceptionDecl(), S->getHandlerBlock()); | 
|  | 6015 | if (!Imp) | 
|  | 6016 | return Imp.takeError(); | 
|  | 6017 |  | 
|  | 6018 | SourceLocation ToCatchLoc; | 
|  | 6019 | VarDecl *ToExceptionDecl; | 
|  | 6020 | Stmt *ToHandlerBlock; | 
|  | 6021 | std::tie(ToCatchLoc, ToExceptionDecl, ToHandlerBlock) = *Imp; | 
|  | 6022 |  | 
|  | 6023 | return new (Importer.getToContext()) CXXCatchStmt ( | 
|  | 6024 | ToCatchLoc, ToExceptionDecl, ToHandlerBlock); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6025 | } | 
|  | 6026 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6027 | ExpectedStmt ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { | 
|  | 6028 | ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc()); | 
|  | 6029 | if (!ToTryLocOrErr) | 
|  | 6030 | return ToTryLocOrErr.takeError(); | 
|  | 6031 |  | 
|  | 6032 | ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock()); | 
|  | 6033 | if (!ToTryBlockOrErr) | 
|  | 6034 | return ToTryBlockOrErr.takeError(); | 
|  | 6035 |  | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6036 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); | 
|  | 6037 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { | 
|  | 6038 | CXXCatchStmt *FromHandler = S->getHandler(HI); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6039 | if (auto ToHandlerOrErr = import(FromHandler)) | 
|  | 6040 | ToHandlers[HI] = *ToHandlerOrErr; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6041 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6042 | return ToHandlerOrErr.takeError(); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6043 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6044 |  | 
|  | 6045 | return CXXTryStmt::Create( | 
|  | 6046 | Importer.getToContext(), *ToTryLocOrErr,*ToTryBlockOrErr, ToHandlers); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6047 | } | 
|  | 6048 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6049 | ExpectedStmt ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { | 
|  | 6050 | auto Imp1 = importSeq( | 
|  | 6051 | S->getInit(), S->getRangeStmt(), S->getBeginStmt(), S->getEndStmt(), | 
|  | 6052 | S->getCond(), S->getInc(), S->getLoopVarStmt(), S->getBody()); | 
|  | 6053 | if (!Imp1) | 
|  | 6054 | return Imp1.takeError(); | 
|  | 6055 | auto Imp2 = importSeq( | 
|  | 6056 | S->getForLoc(), S->getCoawaitLoc(), S->getColonLoc(), S->getRParenLoc()); | 
|  | 6057 | if (!Imp2) | 
|  | 6058 | return Imp2.takeError(); | 
|  | 6059 |  | 
|  | 6060 | DeclStmt *ToRangeStmt, *ToBeginStmt, *ToEndStmt, *ToLoopVarStmt; | 
|  | 6061 | Expr *ToCond, *ToInc; | 
|  | 6062 | Stmt *ToInit, *ToBody; | 
|  | 6063 | std::tie( | 
|  | 6064 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, | 
|  | 6065 | ToBody) = *Imp1; | 
|  | 6066 | SourceLocation ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc; | 
|  | 6067 | std::tie(ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc) = *Imp2; | 
|  | 6068 |  | 
|  | 6069 | return new (Importer.getToContext()) CXXForRangeStmt( | 
|  | 6070 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, | 
|  | 6071 | ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6072 | } | 
|  | 6073 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6074 | ExpectedStmt | 
|  | 6075 | ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { | 
|  | 6076 | auto Imp = importSeq( | 
|  | 6077 | S->getElement(), S->getCollection(), S->getBody(), | 
|  | 6078 | S->getForLoc(), S->getRParenLoc()); | 
|  | 6079 | if (!Imp) | 
|  | 6080 | return Imp.takeError(); | 
|  | 6081 |  | 
|  | 6082 | Stmt *ToElement, *ToBody; | 
|  | 6083 | Expr *ToCollection; | 
|  | 6084 | SourceLocation ToForLoc, ToRParenLoc; | 
|  | 6085 | std::tie(ToElement, ToCollection, ToBody, ToForLoc, ToRParenLoc) = *Imp; | 
|  | 6086 |  | 
|  | 6087 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement, | 
|  | 6088 | ToCollection, | 
|  | 6089 | ToBody, | 
|  | 6090 | ToForLoc, | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6091 | ToRParenLoc); | 
|  | 6092 | } | 
|  | 6093 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6094 | ExpectedStmt ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { | 
|  | 6095 | auto Imp = importSeq( | 
|  | 6096 | S->getAtCatchLoc(), S->getRParenLoc(), S->getCatchParamDecl(), | 
|  | 6097 | S->getCatchBody()); | 
|  | 6098 | if (!Imp) | 
|  | 6099 | return Imp.takeError(); | 
|  | 6100 |  | 
|  | 6101 | SourceLocation ToAtCatchLoc, ToRParenLoc; | 
|  | 6102 | VarDecl *ToCatchParamDecl; | 
|  | 6103 | Stmt *ToCatchBody; | 
|  | 6104 | std::tie(ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody) = *Imp; | 
|  | 6105 |  | 
|  | 6106 | return new (Importer.getToContext()) ObjCAtCatchStmt ( | 
|  | 6107 | ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6108 | } | 
|  | 6109 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6110 | ExpectedStmt ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { | 
|  | 6111 | ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc()); | 
|  | 6112 | if (!ToAtFinallyLocOrErr) | 
|  | 6113 | return ToAtFinallyLocOrErr.takeError(); | 
|  | 6114 | ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody()); | 
|  | 6115 | if (!ToAtFinallyStmtOrErr) | 
|  | 6116 | return ToAtFinallyStmtOrErr.takeError(); | 
|  | 6117 | return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr, | 
|  | 6118 | *ToAtFinallyStmtOrErr); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6119 | } | 
|  | 6120 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6121 | ExpectedStmt ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { | 
|  | 6122 | auto Imp = importSeq( | 
|  | 6123 | S->getAtTryLoc(), S->getTryBody(), S->getFinallyStmt()); | 
|  | 6124 | if (!Imp) | 
|  | 6125 | return Imp.takeError(); | 
|  | 6126 |  | 
|  | 6127 | SourceLocation ToAtTryLoc; | 
|  | 6128 | Stmt *ToTryBody, *ToFinallyStmt; | 
|  | 6129 | std::tie(ToAtTryLoc, ToTryBody, ToFinallyStmt) = *Imp; | 
|  | 6130 |  | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6131 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); | 
|  | 6132 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { | 
|  | 6133 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6134 | if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt)) | 
|  | 6135 | ToCatchStmts[CI] = *ToCatchStmtOrErr; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6136 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6137 | return ToCatchStmtOrErr.takeError(); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6138 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6139 |  | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6140 | return ObjCAtTryStmt::Create(Importer.getToContext(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6141 | ToAtTryLoc, ToTryBody, | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6142 | ToCatchStmts.begin(), ToCatchStmts.size(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6143 | ToFinallyStmt); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6144 | } | 
|  | 6145 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6146 | ExpectedStmt ASTNodeImporter::VisitObjCAtSynchronizedStmt | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6147 | (ObjCAtSynchronizedStmt *S) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6148 | auto Imp = importSeq( | 
|  | 6149 | S->getAtSynchronizedLoc(), S->getSynchExpr(), S->getSynchBody()); | 
|  | 6150 | if (!Imp) | 
|  | 6151 | return Imp.takeError(); | 
|  | 6152 |  | 
|  | 6153 | SourceLocation ToAtSynchronizedLoc; | 
|  | 6154 | Expr *ToSynchExpr; | 
|  | 6155 | Stmt *ToSynchBody; | 
|  | 6156 | std::tie(ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody) = *Imp; | 
|  | 6157 |  | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6158 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( | 
|  | 6159 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); | 
|  | 6160 | } | 
|  | 6161 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6162 | ExpectedStmt ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { | 
|  | 6163 | ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc()); | 
|  | 6164 | if (!ToThrowLocOrErr) | 
|  | 6165 | return ToThrowLocOrErr.takeError(); | 
|  | 6166 | ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr()); | 
|  | 6167 | if (!ToThrowExprOrErr) | 
|  | 6168 | return ToThrowExprOrErr.takeError(); | 
|  | 6169 | return new (Importer.getToContext()) ObjCAtThrowStmt( | 
|  | 6170 | *ToThrowLocOrErr, *ToThrowExprOrErr); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6171 | } | 
|  | 6172 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6173 | ExpectedStmt ASTNodeImporter::VisitObjCAutoreleasePoolStmt( | 
|  | 6174 | ObjCAutoreleasePoolStmt *S) { | 
|  | 6175 | ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc()); | 
|  | 6176 | if (!ToAtLocOrErr) | 
|  | 6177 | return ToAtLocOrErr.takeError(); | 
|  | 6178 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); | 
|  | 6179 | if (!ToSubStmtOrErr) | 
|  | 6180 | return ToSubStmtOrErr.takeError(); | 
|  | 6181 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr, | 
|  | 6182 | *ToSubStmtOrErr); | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6183 | } | 
|  | 6184 |  | 
|  | 6185 | //---------------------------------------------------------------------------- | 
|  | 6186 | // Import Expressions | 
|  | 6187 | //---------------------------------------------------------------------------- | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6188 | ExpectedStmt ASTNodeImporter::VisitExpr(Expr *E) { | 
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6189 | Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node) | 
|  | 6190 | << E->getStmtClassName(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6191 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6192 | } | 
|  | 6193 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6194 | ExpectedStmt ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { | 
|  | 6195 | auto Imp = importSeq( | 
|  | 6196 | E->getBuiltinLoc(), E->getSubExpr(), E->getWrittenTypeInfo(), | 
|  | 6197 | E->getRParenLoc(), E->getType()); | 
|  | 6198 | if (!Imp) | 
|  | 6199 | return Imp.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6200 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6201 | SourceLocation ToBuiltinLoc, ToRParenLoc; | 
|  | 6202 | Expr *ToSubExpr; | 
|  | 6203 | TypeSourceInfo *ToWrittenTypeInfo; | 
|  | 6204 | QualType ToType; | 
|  | 6205 | std::tie(ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType) = | 
|  | 6206 | *Imp; | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6207 |  | 
|  | 6208 | return new (Importer.getToContext()) VAArgExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6209 | ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType, | 
|  | 6210 | E->isMicrosoftABI()); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6211 | } | 
|  | 6212 |  | 
| Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 6213 | ExpectedStmt ASTNodeImporter::VisitChooseExpr(ChooseExpr *E) { | 
|  | 6214 | auto Imp = importSeq(E->getCond(), E->getLHS(), E->getRHS(), | 
|  | 6215 | E->getBuiltinLoc(), E->getRParenLoc(), E->getType()); | 
|  | 6216 | if (!Imp) | 
|  | 6217 | return Imp.takeError(); | 
|  | 6218 |  | 
|  | 6219 | Expr *ToCond; | 
|  | 6220 | Expr *ToLHS; | 
|  | 6221 | Expr *ToRHS; | 
|  | 6222 | SourceLocation ToBuiltinLoc, ToRParenLoc; | 
|  | 6223 | QualType ToType; | 
|  | 6224 | std::tie(ToCond, ToLHS, ToRHS, ToBuiltinLoc, ToRParenLoc, ToType) = *Imp; | 
|  | 6225 |  | 
|  | 6226 | ExprValueKind VK = E->getValueKind(); | 
|  | 6227 | ExprObjectKind OK = E->getObjectKind(); | 
|  | 6228 |  | 
|  | 6229 | bool TypeDependent = ToCond->isTypeDependent(); | 
|  | 6230 | bool ValueDependent = ToCond->isValueDependent(); | 
|  | 6231 |  | 
|  | 6232 | // The value of CondIsTrue only matters if the value is not | 
|  | 6233 | // condition-dependent. | 
|  | 6234 | bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue(); | 
|  | 6235 |  | 
|  | 6236 | return new (Importer.getToContext()) | 
|  | 6237 | ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK, | 
|  | 6238 | ToRParenLoc, CondIsTrue, TypeDependent, ValueDependent); | 
|  | 6239 | } | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6240 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6241 | ExpectedStmt ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { | 
|  | 6242 | ExpectedType TypeOrErr = import(E->getType()); | 
|  | 6243 | if (!TypeOrErr) | 
|  | 6244 | return TypeOrErr.takeError(); | 
|  | 6245 |  | 
|  | 6246 | ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc()); | 
|  | 6247 | if (!BeginLocOrErr) | 
|  | 6248 | return BeginLocOrErr.takeError(); | 
|  | 6249 |  | 
|  | 6250 | return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6251 | } | 
|  | 6252 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6253 | ExpectedStmt ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { | 
|  | 6254 | auto Imp = importSeq( | 
|  | 6255 | E->getBeginLoc(), E->getType(), E->getFunctionName()); | 
|  | 6256 | if (!Imp) | 
|  | 6257 | return Imp.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6258 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6259 | SourceLocation ToBeginLoc; | 
|  | 6260 | QualType ToType; | 
|  | 6261 | StringLiteral *ToFunctionName; | 
|  | 6262 | std::tie(ToBeginLoc, ToType, ToFunctionName) = *Imp; | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6263 |  | 
| Bruno Ricci | 17ff026 | 2018-10-27 19:21:19 +0000 | [diff] [blame] | 6264 | return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType, | 
|  | 6265 | E->getIdentKind(), ToFunctionName); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6266 | } | 
|  | 6267 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6268 | ExpectedStmt ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { | 
|  | 6269 | auto Imp = importSeq( | 
|  | 6270 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDecl(), | 
|  | 6271 | E->getLocation(), E->getType()); | 
|  | 6272 | if (!Imp) | 
|  | 6273 | return Imp.takeError(); | 
| Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6274 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6275 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 6276 | SourceLocation ToTemplateKeywordLoc, ToLocation; | 
|  | 6277 | ValueDecl *ToDecl; | 
|  | 6278 | QualType ToType; | 
|  | 6279 | std::tie(ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, ToLocation, ToType) = | 
|  | 6280 | *Imp; | 
|  | 6281 |  | 
|  | 6282 | NamedDecl *ToFoundD = nullptr; | 
| Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6283 | if (E->getDecl() != E->getFoundDecl()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6284 | auto FoundDOrErr = import(E->getFoundDecl()); | 
|  | 6285 | if (!FoundDOrErr) | 
|  | 6286 | return FoundDOrErr.takeError(); | 
|  | 6287 | ToFoundD = *FoundDOrErr; | 
| Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6288 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6289 |  | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6290 | TemplateArgumentListInfo ToTAInfo; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6291 | TemplateArgumentListInfo *ToResInfo = nullptr; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6292 | if (E->hasExplicitTemplateArgs()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6293 | if (Error Err = | 
|  | 6294 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) | 
|  | 6295 | return std::move(Err); | 
|  | 6296 | ToResInfo = &ToTAInfo; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6297 | } | 
|  | 6298 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6299 | auto *ToE = DeclRefExpr::Create( | 
|  | 6300 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, | 
|  | 6301 | E->refersToEnclosingVariableOrCapture(), ToLocation, ToType, | 
| Richard Smith | 715f7a1 | 2019-06-11 17:50:32 +0000 | [diff] [blame] | 6302 | E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse()); | 
| Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 6303 | if (E->hadMultipleCandidates()) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6304 | ToE->setHadMultipleCandidates(true); | 
|  | 6305 | return ToE; | 
| Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 6306 | } | 
|  | 6307 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6308 | ExpectedStmt ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { | 
|  | 6309 | ExpectedType TypeOrErr = import(E->getType()); | 
|  | 6310 | if (!TypeOrErr) | 
|  | 6311 | return TypeOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6312 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6313 | return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6314 | } | 
|  | 6315 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6316 | ExpectedStmt ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { | 
|  | 6317 | ExpectedExpr ToInitOrErr = import(E->getInit()); | 
|  | 6318 | if (!ToInitOrErr) | 
|  | 6319 | return ToInitOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6320 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6321 | ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc()); | 
|  | 6322 | if (!ToEqualOrColonLocOrErr) | 
|  | 6323 | return ToEqualOrColonLocOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6324 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6325 | SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6326 | // List elements from the second, the first is Init itself | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6327 | for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) { | 
|  | 6328 | if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I))) | 
|  | 6329 | ToIndexExprs[I - 1] = *ToArgOrErr; | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6330 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6331 | return ToArgOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6332 | } | 
|  | 6333 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6334 | SmallVector<Designator, 4> ToDesignators(E->size()); | 
|  | 6335 | if (Error Err = ImportContainerChecked(E->designators(), ToDesignators)) | 
|  | 6336 | return std::move(Err); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6337 |  | 
|  | 6338 | return DesignatedInitExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6339 | Importer.getToContext(), ToDesignators, | 
|  | 6340 | ToIndexExprs, *ToEqualOrColonLocOrErr, | 
|  | 6341 | E->usesGNUSyntax(), *ToInitOrErr); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6342 | } | 
|  | 6343 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6344 | ExpectedStmt | 
|  | 6345 | ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { | 
|  | 6346 | ExpectedType ToTypeOrErr = import(E->getType()); | 
|  | 6347 | if (!ToTypeOrErr) | 
|  | 6348 | return ToTypeOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6349 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6350 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | 
|  | 6351 | if (!ToLocationOrErr) | 
|  | 6352 | return ToLocationOrErr.takeError(); | 
|  | 6353 |  | 
|  | 6354 | return new (Importer.getToContext()) CXXNullPtrLiteralExpr( | 
|  | 6355 | *ToTypeOrErr, *ToLocationOrErr); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6356 | } | 
|  | 6357 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6358 | ExpectedStmt ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { | 
|  | 6359 | ExpectedType ToTypeOrErr = import(E->getType()); | 
|  | 6360 | if (!ToTypeOrErr) | 
|  | 6361 | return ToTypeOrErr.takeError(); | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6362 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6363 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | 
|  | 6364 | if (!ToLocationOrErr) | 
|  | 6365 | return ToLocationOrErr.takeError(); | 
|  | 6366 |  | 
|  | 6367 | return IntegerLiteral::Create( | 
|  | 6368 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr); | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6369 | } | 
|  | 6370 |  | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6371 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6372 | ExpectedStmt ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { | 
|  | 6373 | ExpectedType ToTypeOrErr = import(E->getType()); | 
|  | 6374 | if (!ToTypeOrErr) | 
|  | 6375 | return ToTypeOrErr.takeError(); | 
|  | 6376 |  | 
|  | 6377 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | 
|  | 6378 | if (!ToLocationOrErr) | 
|  | 6379 | return ToLocationOrErr.takeError(); | 
|  | 6380 |  | 
|  | 6381 | return FloatingLiteral::Create( | 
|  | 6382 | Importer.getToContext(), E->getValue(), E->isExact(), | 
|  | 6383 | *ToTypeOrErr, *ToLocationOrErr); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6384 | } | 
|  | 6385 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6386 | ExpectedStmt ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) { | 
|  | 6387 | auto ToTypeOrErr = import(E->getType()); | 
|  | 6388 | if (!ToTypeOrErr) | 
|  | 6389 | return ToTypeOrErr.takeError(); | 
| Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6390 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6391 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | 
|  | 6392 | if (!ToSubExprOrErr) | 
|  | 6393 | return ToSubExprOrErr.takeError(); | 
| Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6394 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6395 | return new (Importer.getToContext()) ImaginaryLiteral( | 
|  | 6396 | *ToSubExprOrErr, *ToTypeOrErr); | 
| Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6397 | } | 
|  | 6398 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6399 | ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { | 
|  | 6400 | ExpectedType ToTypeOrErr = import(E->getType()); | 
|  | 6401 | if (!ToTypeOrErr) | 
|  | 6402 | return ToTypeOrErr.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6403 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6404 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | 
|  | 6405 | if (!ToLocationOrErr) | 
|  | 6406 | return ToLocationOrErr.takeError(); | 
|  | 6407 |  | 
|  | 6408 | return new (Importer.getToContext()) CharacterLiteral( | 
|  | 6409 | E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr); | 
| Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 6410 | } | 
|  | 6411 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6412 | ExpectedStmt ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { | 
|  | 6413 | ExpectedType ToTypeOrErr = import(E->getType()); | 
|  | 6414 | if (!ToTypeOrErr) | 
|  | 6415 | return ToTypeOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6416 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6417 | SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated()); | 
|  | 6418 | if (Error Err = ImportArrayChecked( | 
|  | 6419 | E->tokloc_begin(), E->tokloc_end(), ToLocations.begin())) | 
|  | 6420 | return std::move(Err); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6421 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6422 | return StringLiteral::Create( | 
|  | 6423 | Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(), | 
|  | 6424 | *ToTypeOrErr, ToLocations.data(), ToLocations.size()); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6425 | } | 
|  | 6426 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6427 | ExpectedStmt ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { | 
|  | 6428 | auto Imp = importSeq( | 
|  | 6429 | E->getLParenLoc(), E->getTypeSourceInfo(), E->getType(), | 
|  | 6430 | E->getInitializer()); | 
|  | 6431 | if (!Imp) | 
|  | 6432 | return Imp.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6433 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6434 | SourceLocation ToLParenLoc; | 
|  | 6435 | TypeSourceInfo *ToTypeSourceInfo; | 
|  | 6436 | QualType ToType; | 
|  | 6437 | Expr *ToInitializer; | 
|  | 6438 | std::tie(ToLParenLoc, ToTypeSourceInfo, ToType, ToInitializer) = *Imp; | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6439 |  | 
|  | 6440 | return new (Importer.getToContext()) CompoundLiteralExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6441 | ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(), | 
|  | 6442 | ToInitializer, E->isFileScope()); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6443 | } | 
|  | 6444 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6445 | ExpectedStmt ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { | 
|  | 6446 | auto Imp = importSeq( | 
|  | 6447 | E->getBuiltinLoc(), E->getType(), E->getRParenLoc()); | 
|  | 6448 | if (!Imp) | 
|  | 6449 | return Imp.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6450 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6451 | SourceLocation ToBuiltinLoc, ToRParenLoc; | 
|  | 6452 | QualType ToType; | 
|  | 6453 | std::tie(ToBuiltinLoc, ToType, ToRParenLoc) = *Imp; | 
|  | 6454 |  | 
|  | 6455 | SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs()); | 
|  | 6456 | if (Error Err = ImportArrayChecked( | 
|  | 6457 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), | 
|  | 6458 | ToExprs.begin())) | 
|  | 6459 | return std::move(Err); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6460 |  | 
|  | 6461 | return new (Importer.getToContext()) AtomicExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6462 | ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6463 | } | 
|  | 6464 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6465 | ExpectedStmt ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { | 
|  | 6466 | auto Imp = importSeq( | 
|  | 6467 | E->getAmpAmpLoc(), E->getLabelLoc(), E->getLabel(), E->getType()); | 
|  | 6468 | if (!Imp) | 
|  | 6469 | return Imp.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6470 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6471 | SourceLocation ToAmpAmpLoc, ToLabelLoc; | 
|  | 6472 | LabelDecl *ToLabel; | 
|  | 6473 | QualType ToType; | 
|  | 6474 | std::tie(ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType) = *Imp; | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6475 |  | 
|  | 6476 | return new (Importer.getToContext()) AddrLabelExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6477 | ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6478 | } | 
|  | 6479 |  | 
| Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6480 | ExpectedStmt ASTNodeImporter::VisitConstantExpr(ConstantExpr *E) { | 
|  | 6481 | auto Imp = importSeq(E->getSubExpr()); | 
|  | 6482 | if (!Imp) | 
|  | 6483 | return Imp.takeError(); | 
|  | 6484 |  | 
|  | 6485 | Expr *ToSubExpr; | 
|  | 6486 | std::tie(ToSubExpr) = *Imp; | 
|  | 6487 |  | 
| Gauthier Harnisch | 83c7b61 | 2019-06-15 10:24:47 +0000 | [diff] [blame] | 6488 | // TODO : Handle APValue::ValueKind that require importing. | 
|  | 6489 | APValue::ValueKind Kind = E->getResultAPValueKind(); | 
|  | 6490 | if (Kind == APValue::Int || Kind == APValue::Float || | 
|  | 6491 | Kind == APValue::FixedPoint || Kind == APValue::ComplexFloat || | 
|  | 6492 | Kind == APValue::ComplexInt) | 
|  | 6493 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, | 
|  | 6494 | E->getAPValueResult()); | 
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 6495 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr); | 
| Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6496 | } | 
|  | 6497 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6498 | ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) { | 
|  | 6499 | auto Imp = importSeq(E->getLParen(), E->getRParen(), E->getSubExpr()); | 
|  | 6500 | if (!Imp) | 
|  | 6501 | return Imp.takeError(); | 
|  | 6502 |  | 
|  | 6503 | SourceLocation ToLParen, ToRParen; | 
|  | 6504 | Expr *ToSubExpr; | 
|  | 6505 | std::tie(ToLParen, ToRParen, ToSubExpr) = *Imp; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6506 |  | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6507 | return new (Importer.getToContext()) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6508 | ParenExpr(ToLParen, ToRParen, ToSubExpr); | 
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6509 | } | 
|  | 6510 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6511 | ExpectedStmt ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { | 
|  | 6512 | SmallVector<Expr *, 4> ToExprs(E->getNumExprs()); | 
|  | 6513 | if (Error Err = ImportContainerChecked(E->exprs(), ToExprs)) | 
|  | 6514 | return std::move(Err); | 
|  | 6515 |  | 
|  | 6516 | ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc()); | 
|  | 6517 | if (!ToLParenLocOrErr) | 
|  | 6518 | return ToLParenLocOrErr.takeError(); | 
|  | 6519 |  | 
|  | 6520 | ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc()); | 
|  | 6521 | if (!ToRParenLocOrErr) | 
|  | 6522 | return ToRParenLocOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6523 |  | 
| Bruno Ricci | f49e1ca | 2018-11-20 16:20:40 +0000 | [diff] [blame] | 6524 | return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr, | 
|  | 6525 | ToExprs, *ToRParenLocOrErr); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6526 | } | 
|  | 6527 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6528 | ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { | 
|  | 6529 | auto Imp = importSeq( | 
|  | 6530 | E->getSubStmt(), E->getType(), E->getLParenLoc(), E->getRParenLoc()); | 
|  | 6531 | if (!Imp) | 
|  | 6532 | return Imp.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6533 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6534 | CompoundStmt *ToSubStmt; | 
|  | 6535 | QualType ToType; | 
|  | 6536 | SourceLocation ToLParenLoc, ToRParenLoc; | 
|  | 6537 | std::tie(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc) = *Imp; | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6538 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6539 | return new (Importer.getToContext()) StmtExpr( | 
|  | 6540 | ToSubStmt, ToType, ToLParenLoc, ToRParenLoc); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6541 | } | 
|  | 6542 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6543 | ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { | 
|  | 6544 | auto Imp = importSeq( | 
|  | 6545 | E->getSubExpr(), E->getType(), E->getOperatorLoc()); | 
|  | 6546 | if (!Imp) | 
|  | 6547 | return Imp.takeError(); | 
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6548 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6549 | Expr *ToSubExpr; | 
|  | 6550 | QualType ToType; | 
|  | 6551 | SourceLocation ToOperatorLoc; | 
|  | 6552 | std::tie(ToSubExpr, ToType, ToOperatorLoc) = *Imp; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6553 |  | 
| Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6554 | return new (Importer.getToContext()) UnaryOperator( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6555 | ToSubExpr, E->getOpcode(), ToType, E->getValueKind(), E->getObjectKind(), | 
|  | 6556 | ToOperatorLoc, E->canOverflow()); | 
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6557 | } | 
|  | 6558 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6559 | ExpectedStmt | 
| Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6560 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6561 | auto Imp = importSeq(E->getType(), E->getOperatorLoc(), E->getRParenLoc()); | 
|  | 6562 | if (!Imp) | 
|  | 6563 | return Imp.takeError(); | 
|  | 6564 |  | 
|  | 6565 | QualType ToType; | 
|  | 6566 | SourceLocation ToOperatorLoc, ToRParenLoc; | 
|  | 6567 | std::tie(ToType, ToOperatorLoc, ToRParenLoc) = *Imp; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6568 |  | 
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6569 | if (E->isArgumentType()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6570 | Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr = | 
|  | 6571 | import(E->getArgumentTypeInfo()); | 
|  | 6572 | if (!ToArgumentTypeInfoOrErr) | 
|  | 6573 | return ToArgumentTypeInfoOrErr.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6574 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6575 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( | 
|  | 6576 | E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc, | 
|  | 6577 | ToRParenLoc); | 
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6578 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6579 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6580 | ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr()); | 
|  | 6581 | if (!ToArgumentExprOrErr) | 
|  | 6582 | return ToArgumentExprOrErr.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6583 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6584 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( | 
|  | 6585 | E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc); | 
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6586 | } | 
|  | 6587 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6588 | ExpectedStmt ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { | 
|  | 6589 | auto Imp = importSeq( | 
|  | 6590 | E->getLHS(), E->getRHS(), E->getType(), E->getOperatorLoc()); | 
|  | 6591 | if (!Imp) | 
|  | 6592 | return Imp.takeError(); | 
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6593 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6594 | Expr *ToLHS, *ToRHS; | 
|  | 6595 | QualType ToType; | 
|  | 6596 | SourceLocation  ToOperatorLoc; | 
|  | 6597 | std::tie(ToLHS, ToRHS, ToType, ToOperatorLoc) = *Imp; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6598 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6599 | return new (Importer.getToContext()) BinaryOperator( | 
|  | 6600 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), | 
|  | 6601 | E->getObjectKind(), ToOperatorLoc, E->getFPFeatures()); | 
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6602 | } | 
|  | 6603 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6604 | ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { | 
|  | 6605 | auto Imp = importSeq( | 
|  | 6606 | E->getCond(), E->getQuestionLoc(), E->getLHS(), E->getColonLoc(), | 
|  | 6607 | E->getRHS(), E->getType()); | 
|  | 6608 | if (!Imp) | 
|  | 6609 | return Imp.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6610 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6611 | Expr *ToCond, *ToLHS, *ToRHS; | 
|  | 6612 | SourceLocation ToQuestionLoc, ToColonLoc; | 
|  | 6613 | QualType ToType; | 
|  | 6614 | std::tie(ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType) = *Imp; | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6615 |  | 
|  | 6616 | return new (Importer.getToContext()) ConditionalOperator( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6617 | ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType, | 
|  | 6618 | E->getValueKind(), E->getObjectKind()); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6619 | } | 
|  | 6620 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6621 | ExpectedStmt ASTNodeImporter::VisitBinaryConditionalOperator( | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6622 | BinaryConditionalOperator *E) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6623 | auto Imp = importSeq( | 
|  | 6624 | E->getCommon(), E->getOpaqueValue(), E->getCond(), E->getTrueExpr(), | 
|  | 6625 | E->getFalseExpr(), E->getQuestionLoc(), E->getColonLoc(), E->getType()); | 
|  | 6626 | if (!Imp) | 
|  | 6627 | return Imp.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6628 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6629 | Expr *ToCommon, *ToCond, *ToTrueExpr, *ToFalseExpr; | 
|  | 6630 | OpaqueValueExpr *ToOpaqueValue; | 
|  | 6631 | SourceLocation ToQuestionLoc, ToColonLoc; | 
|  | 6632 | QualType ToType; | 
|  | 6633 | std::tie( | 
|  | 6634 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, ToQuestionLoc, | 
|  | 6635 | ToColonLoc, ToType) = *Imp; | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6636 |  | 
|  | 6637 | return new (Importer.getToContext()) BinaryConditionalOperator( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6638 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, | 
|  | 6639 | ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(), | 
|  | 6640 | E->getObjectKind()); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6641 | } | 
|  | 6642 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6643 | ExpectedStmt ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { | 
|  | 6644 | auto Imp = importSeq( | 
|  | 6645 | E->getBeginLoc(), E->getQueriedTypeSourceInfo(), | 
|  | 6646 | E->getDimensionExpression(), E->getEndLoc(), E->getType()); | 
|  | 6647 | if (!Imp) | 
|  | 6648 | return Imp.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6649 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6650 | SourceLocation ToBeginLoc, ToEndLoc; | 
|  | 6651 | TypeSourceInfo *ToQueriedTypeSourceInfo; | 
|  | 6652 | Expr *ToDimensionExpression; | 
|  | 6653 | QualType ToType; | 
|  | 6654 | std::tie( | 
|  | 6655 | ToBeginLoc, ToQueriedTypeSourceInfo, ToDimensionExpression, ToEndLoc, | 
|  | 6656 | ToType) = *Imp; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6657 |  | 
|  | 6658 | return new (Importer.getToContext()) ArrayTypeTraitExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6659 | ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(), | 
|  | 6660 | ToDimensionExpression, ToEndLoc, ToType); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6661 | } | 
|  | 6662 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6663 | ExpectedStmt ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { | 
|  | 6664 | auto Imp = importSeq( | 
|  | 6665 | E->getBeginLoc(), E->getQueriedExpression(), E->getEndLoc(), E->getType()); | 
|  | 6666 | if (!Imp) | 
|  | 6667 | return Imp.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6668 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6669 | SourceLocation ToBeginLoc, ToEndLoc; | 
|  | 6670 | Expr *ToQueriedExpression; | 
|  | 6671 | QualType ToType; | 
|  | 6672 | std::tie(ToBeginLoc, ToQueriedExpression, ToEndLoc, ToType) = *Imp; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6673 |  | 
|  | 6674 | return new (Importer.getToContext()) ExpressionTraitExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6675 | ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(), | 
|  | 6676 | ToEndLoc, ToType); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6677 | } | 
|  | 6678 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6679 | ExpectedStmt ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { | 
|  | 6680 | auto Imp = importSeq( | 
|  | 6681 | E->getLocation(), E->getType(), E->getSourceExpr()); | 
|  | 6682 | if (!Imp) | 
|  | 6683 | return Imp.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6684 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6685 | SourceLocation ToLocation; | 
|  | 6686 | QualType ToType; | 
|  | 6687 | Expr *ToSourceExpr; | 
|  | 6688 | std::tie(ToLocation, ToType, ToSourceExpr) = *Imp; | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6689 |  | 
|  | 6690 | return new (Importer.getToContext()) OpaqueValueExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6691 | ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6692 | } | 
|  | 6693 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6694 | ExpectedStmt ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { | 
|  | 6695 | auto Imp = importSeq( | 
|  | 6696 | E->getLHS(), E->getRHS(), E->getType(), E->getRBracketLoc()); | 
|  | 6697 | if (!Imp) | 
|  | 6698 | return Imp.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6699 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6700 | Expr *ToLHS, *ToRHS; | 
|  | 6701 | SourceLocation ToRBracketLoc; | 
|  | 6702 | QualType ToType; | 
|  | 6703 | std::tie(ToLHS, ToRHS, ToType, ToRBracketLoc) = *Imp; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6704 |  | 
|  | 6705 | return new (Importer.getToContext()) ArraySubscriptExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6706 | ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(), | 
|  | 6707 | ToRBracketLoc); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6708 | } | 
|  | 6709 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6710 | ExpectedStmt | 
|  | 6711 | ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { | 
|  | 6712 | auto Imp = importSeq( | 
|  | 6713 | E->getLHS(), E->getRHS(), E->getType(), E->getComputationLHSType(), | 
|  | 6714 | E->getComputationResultType(), E->getOperatorLoc()); | 
|  | 6715 | if (!Imp) | 
|  | 6716 | return Imp.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6717 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6718 | Expr *ToLHS, *ToRHS; | 
|  | 6719 | QualType ToType, ToComputationLHSType, ToComputationResultType; | 
|  | 6720 | SourceLocation ToOperatorLoc; | 
|  | 6721 | std::tie(ToLHS, ToRHS, ToType, ToComputationLHSType, ToComputationResultType, | 
|  | 6722 | ToOperatorLoc) = *Imp; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6723 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6724 | return new (Importer.getToContext()) CompoundAssignOperator( | 
|  | 6725 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), | 
|  | 6726 | E->getObjectKind(), ToComputationLHSType, ToComputationResultType, | 
|  | 6727 | ToOperatorLoc, E->getFPFeatures()); | 
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6728 | } | 
|  | 6729 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6730 | Expected<CXXCastPath> | 
|  | 6731 | ASTNodeImporter::ImportCastPath(CastExpr *CE) { | 
|  | 6732 | CXXCastPath Path; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6733 | for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6734 | if (auto SpecOrErr = import(*I)) | 
|  | 6735 | Path.push_back(*SpecOrErr); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6736 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6737 | return SpecOrErr.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6738 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6739 | return Path; | 
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6740 | } | 
|  | 6741 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6742 | ExpectedStmt ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { | 
|  | 6743 | ExpectedType ToTypeOrErr = import(E->getType()); | 
|  | 6744 | if (!ToTypeOrErr) | 
|  | 6745 | return ToTypeOrErr.takeError(); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6746 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6747 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | 
|  | 6748 | if (!ToSubExprOrErr) | 
|  | 6749 | return ToSubExprOrErr.takeError(); | 
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6750 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6751 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); | 
|  | 6752 | if (!ToBasePathOrErr) | 
|  | 6753 | return ToBasePathOrErr.takeError(); | 
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6754 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6755 | return ImplicitCastExpr::Create( | 
|  | 6756 | Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr, | 
|  | 6757 | &(*ToBasePathOrErr), E->getValueKind()); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6758 | } | 
|  | 6759 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6760 | ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { | 
|  | 6761 | auto Imp1 = importSeq( | 
|  | 6762 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten()); | 
|  | 6763 | if (!Imp1) | 
|  | 6764 | return Imp1.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6765 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6766 | QualType ToType; | 
|  | 6767 | Expr *ToSubExpr; | 
|  | 6768 | TypeSourceInfo *ToTypeInfoAsWritten; | 
|  | 6769 | std::tie(ToType, ToSubExpr, ToTypeInfoAsWritten) = *Imp1; | 
| Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6770 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6771 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); | 
|  | 6772 | if (!ToBasePathOrErr) | 
|  | 6773 | return ToBasePathOrErr.takeError(); | 
|  | 6774 | CXXCastPath *ToBasePath = &(*ToBasePathOrErr); | 
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6775 |  | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6776 | switch (E->getStmtClass()) { | 
|  | 6777 | case Stmt::CStyleCastExprClass: { | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6778 | auto *CCE = cast<CStyleCastExpr>(E); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6779 | ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc()); | 
|  | 6780 | if (!ToLParenLocOrErr) | 
|  | 6781 | return ToLParenLocOrErr.takeError(); | 
|  | 6782 | ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc()); | 
|  | 6783 | if (!ToRParenLocOrErr) | 
|  | 6784 | return ToRParenLocOrErr.takeError(); | 
|  | 6785 | return CStyleCastExpr::Create( | 
|  | 6786 | Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(), | 
|  | 6787 | ToSubExpr, ToBasePath, ToTypeInfoAsWritten, *ToLParenLocOrErr, | 
|  | 6788 | *ToRParenLocOrErr); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6789 | } | 
|  | 6790 |  | 
|  | 6791 | case Stmt::CXXFunctionalCastExprClass: { | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6792 | auto *FCE = cast<CXXFunctionalCastExpr>(E); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6793 | ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc()); | 
|  | 6794 | if (!ToLParenLocOrErr) | 
|  | 6795 | return ToLParenLocOrErr.takeError(); | 
|  | 6796 | ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc()); | 
|  | 6797 | if (!ToRParenLocOrErr) | 
|  | 6798 | return ToRParenLocOrErr.takeError(); | 
|  | 6799 | return CXXFunctionalCastExpr::Create( | 
|  | 6800 | Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten, | 
|  | 6801 | E->getCastKind(), ToSubExpr, ToBasePath, *ToLParenLocOrErr, | 
|  | 6802 | *ToRParenLocOrErr); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6803 | } | 
|  | 6804 |  | 
|  | 6805 | case Stmt::ObjCBridgedCastExprClass: { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6806 | auto *OCE = cast<ObjCBridgedCastExpr>(E); | 
|  | 6807 | ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc()); | 
|  | 6808 | if (!ToLParenLocOrErr) | 
|  | 6809 | return ToLParenLocOrErr.takeError(); | 
|  | 6810 | ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc()); | 
|  | 6811 | if (!ToBridgeKeywordLocOrErr) | 
|  | 6812 | return ToBridgeKeywordLocOrErr.takeError(); | 
|  | 6813 | return new (Importer.getToContext()) ObjCBridgedCastExpr( | 
|  | 6814 | *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), | 
|  | 6815 | *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6816 | } | 
|  | 6817 | default: | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6818 | llvm_unreachable("Cast expression of unsupported type!"); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6819 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6820 | } | 
|  | 6821 | } | 
|  | 6822 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6823 | ExpectedStmt ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *E) { | 
|  | 6824 | SmallVector<OffsetOfNode, 4> ToNodes; | 
|  | 6825 | for (int I = 0, N = E->getNumComponents(); I < N; ++I) { | 
|  | 6826 | const OffsetOfNode &FromNode = E->getComponent(I); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6827 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6828 | SourceLocation ToBeginLoc, ToEndLoc; | 
|  | 6829 | if (FromNode.getKind() != OffsetOfNode::Base) { | 
|  | 6830 | auto Imp = importSeq(FromNode.getBeginLoc(), FromNode.getEndLoc()); | 
|  | 6831 | if (!Imp) | 
|  | 6832 | return Imp.takeError(); | 
|  | 6833 | std::tie(ToBeginLoc, ToEndLoc) = *Imp; | 
|  | 6834 | } | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6835 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6836 | switch (FromNode.getKind()) { | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6837 | case OffsetOfNode::Array: | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6838 | ToNodes.push_back( | 
|  | 6839 | OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc)); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6840 | break; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6841 | case OffsetOfNode::Base: { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6842 | auto ToBSOrErr = import(FromNode.getBase()); | 
|  | 6843 | if (!ToBSOrErr) | 
|  | 6844 | return ToBSOrErr.takeError(); | 
|  | 6845 | ToNodes.push_back(OffsetOfNode(*ToBSOrErr)); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6846 | break; | 
|  | 6847 | } | 
|  | 6848 | case OffsetOfNode::Field: { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6849 | auto ToFieldOrErr = import(FromNode.getField()); | 
|  | 6850 | if (!ToFieldOrErr) | 
|  | 6851 | return ToFieldOrErr.takeError(); | 
|  | 6852 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc)); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6853 | break; | 
|  | 6854 | } | 
|  | 6855 | case OffsetOfNode::Identifier: { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6856 | IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName()); | 
|  | 6857 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc)); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6858 | break; | 
|  | 6859 | } | 
|  | 6860 | } | 
|  | 6861 | } | 
|  | 6862 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6863 | SmallVector<Expr *, 4> ToExprs(E->getNumExpressions()); | 
|  | 6864 | for (int I = 0, N = E->getNumExpressions(); I < N; ++I) { | 
|  | 6865 | ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I)); | 
|  | 6866 | if (!ToIndexExprOrErr) | 
|  | 6867 | return ToIndexExprOrErr.takeError(); | 
|  | 6868 | ToExprs[I] = *ToIndexExprOrErr; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6869 | } | 
|  | 6870 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6871 | auto Imp = importSeq( | 
|  | 6872 | E->getType(), E->getTypeSourceInfo(), E->getOperatorLoc(), | 
|  | 6873 | E->getRParenLoc()); | 
|  | 6874 | if (!Imp) | 
|  | 6875 | return Imp.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6876 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6877 | QualType ToType; | 
|  | 6878 | TypeSourceInfo *ToTypeSourceInfo; | 
|  | 6879 | SourceLocation ToOperatorLoc, ToRParenLoc; | 
|  | 6880 | std::tie(ToType, ToTypeSourceInfo, ToOperatorLoc, ToRParenLoc) = *Imp; | 
|  | 6881 |  | 
|  | 6882 | return OffsetOfExpr::Create( | 
|  | 6883 | Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes, | 
|  | 6884 | ToExprs, ToRParenLoc); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6885 | } | 
|  | 6886 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6887 | ExpectedStmt ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { | 
|  | 6888 | auto Imp = importSeq( | 
|  | 6889 | E->getType(), E->getOperand(), E->getBeginLoc(), E->getEndLoc()); | 
|  | 6890 | if (!Imp) | 
|  | 6891 | return Imp.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6892 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6893 | QualType ToType; | 
|  | 6894 | Expr *ToOperand; | 
|  | 6895 | SourceLocation ToBeginLoc, ToEndLoc; | 
|  | 6896 | std::tie(ToType, ToOperand, ToBeginLoc, ToEndLoc) = *Imp; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6897 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6898 | CanThrowResult ToCanThrow; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6899 | if (E->isValueDependent()) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6900 | ToCanThrow = CT_Dependent; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6901 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6902 | ToCanThrow = E->getValue() ? CT_Can : CT_Cannot; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6903 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6904 | return new (Importer.getToContext()) CXXNoexceptExpr( | 
|  | 6905 | ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6906 | } | 
|  | 6907 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6908 | ExpectedStmt ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { | 
|  | 6909 | auto Imp = importSeq(E->getSubExpr(), E->getType(), E->getThrowLoc()); | 
|  | 6910 | if (!Imp) | 
|  | 6911 | return Imp.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6912 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6913 | Expr *ToSubExpr; | 
|  | 6914 | QualType ToType; | 
|  | 6915 | SourceLocation ToThrowLoc; | 
|  | 6916 | std::tie(ToSubExpr, ToType, ToThrowLoc) = *Imp; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6917 |  | 
|  | 6918 | return new (Importer.getToContext()) CXXThrowExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6919 | ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope()); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6920 | } | 
|  | 6921 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6922 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { | 
|  | 6923 | ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation()); | 
|  | 6924 | if (!ToUsedLocOrErr) | 
|  | 6925 | return ToUsedLocOrErr.takeError(); | 
|  | 6926 |  | 
|  | 6927 | auto ToParamOrErr = import(E->getParam()); | 
|  | 6928 | if (!ToParamOrErr) | 
|  | 6929 | return ToParamOrErr.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6930 |  | 
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 6931 | auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext()); | 
|  | 6932 | if (!UsedContextOrErr) | 
|  | 6933 | return UsedContextOrErr.takeError(); | 
|  | 6934 |  | 
| Balazs Keri | c509594 | 2019-08-14 09:41:39 +0000 | [diff] [blame] | 6935 | // Import the default arg if it was not imported yet. | 
|  | 6936 | // This is needed because it can happen that during the import of the | 
|  | 6937 | // default expression (from VisitParmVarDecl) the same ParmVarDecl is | 
|  | 6938 | // encountered here. The default argument for a ParmVarDecl is set in the | 
|  | 6939 | // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here, | 
|  | 6940 | // see VisitParmVarDecl). | 
|  | 6941 | ParmVarDecl *ToParam = *ToParamOrErr; | 
|  | 6942 | if (!ToParam->getDefaultArg()) { | 
|  | 6943 | Optional<ParmVarDecl *> FromParam = Importer.getImportedFromDecl(ToParam); | 
|  | 6944 | assert(FromParam && "ParmVarDecl was not imported?"); | 
|  | 6945 |  | 
|  | 6946 | if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam)) | 
|  | 6947 | return std::move(Err); | 
|  | 6948 | } | 
|  | 6949 |  | 
|  | 6950 | return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr, | 
|  | 6951 | *ToParamOrErr, *UsedContextOrErr); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6952 | } | 
|  | 6953 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6954 | ExpectedStmt | 
|  | 6955 | ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { | 
|  | 6956 | auto Imp = importSeq( | 
|  | 6957 | E->getType(), E->getTypeSourceInfo(), E->getRParenLoc()); | 
|  | 6958 | if (!Imp) | 
|  | 6959 | return Imp.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6960 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6961 | QualType ToType; | 
|  | 6962 | TypeSourceInfo *ToTypeSourceInfo; | 
|  | 6963 | SourceLocation ToRParenLoc; | 
|  | 6964 | std::tie(ToType, ToTypeSourceInfo, ToRParenLoc) = *Imp; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6965 |  | 
|  | 6966 | return new (Importer.getToContext()) CXXScalarValueInitExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6967 | ToType, ToTypeSourceInfo, ToRParenLoc); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6968 | } | 
|  | 6969 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6970 | ExpectedStmt | 
|  | 6971 | ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { | 
|  | 6972 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | 
|  | 6973 | if (!ToSubExprOrErr) | 
|  | 6974 | return ToSubExprOrErr.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6975 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6976 | auto ToDtorOrErr = import(E->getTemporary()->getDestructor()); | 
|  | 6977 | if (!ToDtorOrErr) | 
|  | 6978 | return ToDtorOrErr.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6979 |  | 
|  | 6980 | ASTContext &ToCtx = Importer.getToContext(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6981 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr); | 
|  | 6982 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6983 | } | 
|  | 6984 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6985 | ExpectedStmt | 
|  | 6986 | ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { | 
|  | 6987 | auto Imp = importSeq( | 
|  | 6988 | E->getConstructor(), E->getType(), E->getTypeSourceInfo(), | 
|  | 6989 | E->getParenOrBraceRange()); | 
|  | 6990 | if (!Imp) | 
|  | 6991 | return Imp.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6992 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6993 | CXXConstructorDecl *ToConstructor; | 
|  | 6994 | QualType ToType; | 
|  | 6995 | TypeSourceInfo *ToTypeSourceInfo; | 
|  | 6996 | SourceRange ToParenOrBraceRange; | 
|  | 6997 | std::tie(ToConstructor, ToType, ToTypeSourceInfo, ToParenOrBraceRange) = *Imp; | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6998 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6999 | SmallVector<Expr *, 8> ToArgs(E->getNumArgs()); | 
|  | 7000 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | 
|  | 7001 | return std::move(Err); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7002 |  | 
| Bruno Ricci | ddb8f6b | 2018-12-22 14:39:30 +0000 | [diff] [blame] | 7003 | return CXXTemporaryObjectExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7004 | Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs, | 
|  | 7005 | ToParenOrBraceRange, E->hadMultipleCandidates(), | 
|  | 7006 | E->isListInitialization(), E->isStdInitListInitialization(), | 
|  | 7007 | E->requiresZeroInitialization()); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7008 | } | 
|  | 7009 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7010 | ExpectedStmt | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7011 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7012 | auto Imp = importSeq( | 
|  | 7013 | E->getType(), E->GetTemporaryExpr(), E->getExtendingDecl()); | 
|  | 7014 | if (!Imp) | 
|  | 7015 | return Imp.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7016 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7017 | QualType ToType; | 
|  | 7018 | Expr *ToTemporaryExpr; | 
|  | 7019 | const ValueDecl *ToExtendingDecl; | 
|  | 7020 | std::tie(ToType, ToTemporaryExpr, ToExtendingDecl) = *Imp; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7021 |  | 
|  | 7022 | auto *ToMTE =  new (Importer.getToContext()) MaterializeTemporaryExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7023 | ToType, ToTemporaryExpr, E->isBoundToLvalueReference()); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7024 |  | 
|  | 7025 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7026 | ToMTE->setExtendingDecl(ToExtendingDecl, E->getManglingNumber()); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7027 | return ToMTE; | 
|  | 7028 | } | 
|  | 7029 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7030 | ExpectedStmt ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { | 
|  | 7031 | auto Imp = importSeq( | 
|  | 7032 | E->getType(), E->getPattern(), E->getEllipsisLoc()); | 
|  | 7033 | if (!Imp) | 
|  | 7034 | return Imp.takeError(); | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 7035 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7036 | QualType ToType; | 
|  | 7037 | Expr *ToPattern; | 
|  | 7038 | SourceLocation ToEllipsisLoc; | 
|  | 7039 | std::tie(ToType, ToPattern, ToEllipsisLoc) = *Imp; | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 7040 |  | 
|  | 7041 | return new (Importer.getToContext()) PackExpansionExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7042 | ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions()); | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 7043 | } | 
|  | 7044 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7045 | ExpectedStmt ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { | 
|  | 7046 | auto Imp = importSeq( | 
|  | 7047 | E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc()); | 
|  | 7048 | if (!Imp) | 
|  | 7049 | return Imp.takeError(); | 
|  | 7050 |  | 
|  | 7051 | SourceLocation ToOperatorLoc, ToPackLoc, ToRParenLoc; | 
|  | 7052 | NamedDecl *ToPack; | 
|  | 7053 | std::tie(ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc) = *Imp; | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7054 |  | 
|  | 7055 | Optional<unsigned> Length; | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7056 | if (!E->isValueDependent()) | 
|  | 7057 | Length = E->getPackLength(); | 
|  | 7058 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7059 | SmallVector<TemplateArgument, 8> ToPartialArguments; | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7060 | if (E->isPartiallySubstituted()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7061 | if (Error Err = ImportTemplateArguments( | 
|  | 7062 | E->getPartialArguments().data(), | 
|  | 7063 | E->getPartialArguments().size(), | 
|  | 7064 | ToPartialArguments)) | 
|  | 7065 | return std::move(Err); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7066 | } | 
|  | 7067 |  | 
|  | 7068 | return SizeOfPackExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7069 | Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc, | 
|  | 7070 | Length, ToPartialArguments); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7071 | } | 
|  | 7072 |  | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7073 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7074 | ExpectedStmt ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) { | 
|  | 7075 | auto Imp = importSeq( | 
|  | 7076 | E->getOperatorNew(), E->getOperatorDelete(), E->getTypeIdParens(), | 
|  | 7077 | E->getArraySize(), E->getInitializer(), E->getType(), | 
|  | 7078 | E->getAllocatedTypeSourceInfo(), E->getSourceRange(), | 
|  | 7079 | E->getDirectInitRange()); | 
|  | 7080 | if (!Imp) | 
|  | 7081 | return Imp.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7082 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7083 | FunctionDecl *ToOperatorNew, *ToOperatorDelete; | 
|  | 7084 | SourceRange ToTypeIdParens, ToSourceRange, ToDirectInitRange; | 
| Richard Smith | b9fb121 | 2019-05-06 03:47:15 +0000 | [diff] [blame] | 7085 | Optional<Expr *> ToArraySize; | 
|  | 7086 | Expr *ToInitializer; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7087 | QualType ToType; | 
|  | 7088 | TypeSourceInfo *ToAllocatedTypeSourceInfo; | 
|  | 7089 | std::tie( | 
|  | 7090 | ToOperatorNew, ToOperatorDelete, ToTypeIdParens, ToArraySize, ToInitializer, | 
|  | 7091 | ToType, ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange) = *Imp; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7092 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7093 | SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs()); | 
|  | 7094 | if (Error Err = | 
|  | 7095 | ImportContainerChecked(E->placement_arguments(), ToPlacementArgs)) | 
|  | 7096 | return std::move(Err); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7097 |  | 
| Bruno Ricci | 9b6dfac | 2019-01-07 15:04:45 +0000 | [diff] [blame] | 7098 | return CXXNewExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7099 | Importer.getToContext(), E->isGlobalNew(), ToOperatorNew, | 
|  | 7100 | ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(), | 
|  | 7101 | ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(), | 
|  | 7102 | ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange, | 
|  | 7103 | ToDirectInitRange); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7104 | } | 
|  | 7105 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7106 | ExpectedStmt ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { | 
|  | 7107 | auto Imp = importSeq( | 
|  | 7108 | E->getType(), E->getOperatorDelete(), E->getArgument(), E->getBeginLoc()); | 
|  | 7109 | if (!Imp) | 
|  | 7110 | return Imp.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7111 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7112 | QualType ToType; | 
|  | 7113 | FunctionDecl *ToOperatorDelete; | 
|  | 7114 | Expr *ToArgument; | 
|  | 7115 | SourceLocation ToBeginLoc; | 
|  | 7116 | std::tie(ToType, ToOperatorDelete, ToArgument, ToBeginLoc) = *Imp; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7117 |  | 
|  | 7118 | return new (Importer.getToContext()) CXXDeleteExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7119 | ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(), | 
|  | 7120 | E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument, | 
|  | 7121 | ToBeginLoc); | 
| Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 7122 | } | 
|  | 7123 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7124 | ExpectedStmt ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { | 
|  | 7125 | auto Imp = importSeq( | 
|  | 7126 | E->getType(), E->getLocation(), E->getConstructor(), | 
|  | 7127 | E->getParenOrBraceRange()); | 
|  | 7128 | if (!Imp) | 
|  | 7129 | return Imp.takeError(); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7130 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7131 | QualType ToType; | 
|  | 7132 | SourceLocation ToLocation; | 
|  | 7133 | CXXConstructorDecl *ToConstructor; | 
|  | 7134 | SourceRange ToParenOrBraceRange; | 
|  | 7135 | std::tie(ToType, ToLocation, ToConstructor, ToParenOrBraceRange) = *Imp; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7136 |  | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7137 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7138 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | 
|  | 7139 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7140 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7141 | return CXXConstructExpr::Create( | 
|  | 7142 | Importer.getToContext(), ToType, ToLocation, ToConstructor, | 
|  | 7143 | E->isElidable(), ToArgs, E->hadMultipleCandidates(), | 
|  | 7144 | E->isListInitialization(), E->isStdInitListInitialization(), | 
|  | 7145 | E->requiresZeroInitialization(), E->getConstructionKind(), | 
|  | 7146 | ToParenOrBraceRange); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7147 | } | 
|  | 7148 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7149 | ExpectedStmt ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *E) { | 
|  | 7150 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | 
|  | 7151 | if (!ToSubExprOrErr) | 
|  | 7152 | return ToSubExprOrErr.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7153 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7154 | SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects()); | 
|  | 7155 | if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects)) | 
|  | 7156 | return std::move(Err); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7157 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7158 | return ExprWithCleanups::Create( | 
|  | 7159 | Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(), | 
|  | 7160 | ToObjects); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7161 | } | 
|  | 7162 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7163 | ExpectedStmt ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { | 
|  | 7164 | auto Imp = importSeq( | 
|  | 7165 | E->getCallee(), E->getType(), E->getRParenLoc()); | 
|  | 7166 | if (!Imp) | 
|  | 7167 | return Imp.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7168 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7169 | Expr *ToCallee; | 
|  | 7170 | QualType ToType; | 
|  | 7171 | SourceLocation ToRParenLoc; | 
|  | 7172 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7173 |  | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7174 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7175 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | 
|  | 7176 | return std::move(Err); | 
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7177 |  | 
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7178 | return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, | 
|  | 7179 | ToType, E->getValueKind(), ToRParenLoc); | 
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7180 | } | 
|  | 7181 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7182 | ExpectedStmt ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { | 
|  | 7183 | ExpectedType ToTypeOrErr = import(E->getType()); | 
|  | 7184 | if (!ToTypeOrErr) | 
|  | 7185 | return ToTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7186 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7187 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | 
|  | 7188 | if (!ToLocationOrErr) | 
|  | 7189 | return ToLocationOrErr.takeError(); | 
|  | 7190 |  | 
|  | 7191 | return new (Importer.getToContext()) CXXThisExpr( | 
|  | 7192 | *ToLocationOrErr, *ToTypeOrErr, E->isImplicit()); | 
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7193 | } | 
|  | 7194 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7195 | ExpectedStmt ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { | 
|  | 7196 | ExpectedType ToTypeOrErr = import(E->getType()); | 
|  | 7197 | if (!ToTypeOrErr) | 
|  | 7198 | return ToTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7199 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7200 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | 
|  | 7201 | if (!ToLocationOrErr) | 
|  | 7202 | return ToLocationOrErr.takeError(); | 
|  | 7203 |  | 
|  | 7204 | return new (Importer.getToContext()) CXXBoolLiteralExpr( | 
|  | 7205 | E->getValue(), *ToTypeOrErr, *ToLocationOrErr); | 
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7206 | } | 
|  | 7207 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7208 | ExpectedStmt ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { | 
|  | 7209 | auto Imp1 = importSeq( | 
|  | 7210 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), | 
|  | 7211 | E->getTemplateKeywordLoc(), E->getMemberDecl(), E->getType()); | 
|  | 7212 | if (!Imp1) | 
|  | 7213 | return Imp1.takeError(); | 
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7214 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7215 | Expr *ToBase; | 
|  | 7216 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; | 
|  | 7217 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 7218 | ValueDecl *ToMemberDecl; | 
|  | 7219 | QualType ToType; | 
|  | 7220 | std::tie( | 
|  | 7221 | ToBase, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, | 
|  | 7222 | ToType) = *Imp1; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7223 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7224 | auto Imp2 = importSeq( | 
|  | 7225 | E->getFoundDecl().getDecl(), E->getMemberNameInfo().getName(), | 
|  | 7226 | E->getMemberNameInfo().getLoc(), E->getLAngleLoc(), E->getRAngleLoc()); | 
|  | 7227 | if (!Imp2) | 
|  | 7228 | return Imp2.takeError(); | 
|  | 7229 | NamedDecl *ToDecl; | 
|  | 7230 | DeclarationName ToName; | 
|  | 7231 | SourceLocation ToLoc, ToLAngleLoc, ToRAngleLoc; | 
|  | 7232 | std::tie(ToDecl, ToName, ToLoc, ToLAngleLoc, ToRAngleLoc) = *Imp2; | 
| Peter Szecsi | ef97252 | 2018-05-02 11:52:54 +0000 | [diff] [blame] | 7233 |  | 
|  | 7234 | DeclAccessPair ToFoundDecl = | 
|  | 7235 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7236 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7237 | DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7238 |  | 
| Gabor Marton | 5caba30 | 2019-03-07 13:38:20 +0000 | [diff] [blame] | 7239 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7240 | if (E->hasExplicitTemplateArgs()) { | 
| Gabor Marton | 5caba30 | 2019-03-07 13:38:20 +0000 | [diff] [blame] | 7241 | if (Error Err = | 
|  | 7242 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), | 
|  | 7243 | E->template_arguments(), ToTAInfo)) | 
|  | 7244 | return std::move(Err); | 
|  | 7245 | ResInfo = &ToTAInfo; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7246 | } | 
|  | 7247 |  | 
| Richard Smith | 1bbad59 | 2019-06-11 17:50:36 +0000 | [diff] [blame] | 7248 | return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(), | 
|  | 7249 | ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, | 
|  | 7250 | ToMemberDecl, ToFoundDecl, ToMemberNameInfo, | 
|  | 7251 | ResInfo, ToType, E->getValueKind(), | 
|  | 7252 | E->getObjectKind(), E->isNonOdrUse()); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7253 | } | 
|  | 7254 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7255 | ExpectedStmt | 
|  | 7256 | ASTNodeImporter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { | 
|  | 7257 | auto Imp = importSeq( | 
|  | 7258 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), | 
|  | 7259 | E->getScopeTypeInfo(), E->getColonColonLoc(), E->getTildeLoc()); | 
|  | 7260 | if (!Imp) | 
|  | 7261 | return Imp.takeError(); | 
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7262 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7263 | Expr *ToBase; | 
|  | 7264 | SourceLocation ToOperatorLoc, ToColonColonLoc, ToTildeLoc; | 
|  | 7265 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 7266 | TypeSourceInfo *ToScopeTypeInfo; | 
|  | 7267 | std::tie( | 
|  | 7268 | ToBase, ToOperatorLoc, ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, | 
|  | 7269 | ToTildeLoc) = *Imp; | 
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7270 |  | 
|  | 7271 | PseudoDestructorTypeStorage Storage; | 
|  | 7272 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { | 
|  | 7273 | IdentifierInfo *ToII = Importer.Import(FromII); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7274 | ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc()); | 
|  | 7275 | if (!ToDestroyedTypeLocOrErr) | 
|  | 7276 | return ToDestroyedTypeLocOrErr.takeError(); | 
|  | 7277 | Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr); | 
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7278 | } else { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7279 | if (auto ToTIOrErr = import(E->getDestroyedTypeInfo())) | 
|  | 7280 | Storage = PseudoDestructorTypeStorage(*ToTIOrErr); | 
|  | 7281 | else | 
|  | 7282 | return ToTIOrErr.takeError(); | 
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7283 | } | 
|  | 7284 |  | 
|  | 7285 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7286 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, | 
|  | 7287 | ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage); | 
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7288 | } | 
|  | 7289 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7290 | ExpectedStmt ASTNodeImporter::VisitCXXDependentScopeMemberExpr( | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7291 | CXXDependentScopeMemberExpr *E) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7292 | auto Imp = importSeq( | 
|  | 7293 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), | 
|  | 7294 | E->getTemplateKeywordLoc(), E->getFirstQualifierFoundInScope()); | 
|  | 7295 | if (!Imp) | 
|  | 7296 | return Imp.takeError(); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7297 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7298 | QualType ToType; | 
|  | 7299 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; | 
|  | 7300 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 7301 | NamedDecl *ToFirstQualifierFoundInScope; | 
|  | 7302 | std::tie( | 
|  | 7303 | ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, | 
|  | 7304 | ToFirstQualifierFoundInScope) = *Imp; | 
|  | 7305 |  | 
|  | 7306 | Expr *ToBase = nullptr; | 
|  | 7307 | if (!E->isImplicitAccess()) { | 
|  | 7308 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) | 
|  | 7309 | ToBase = *ToBaseOrErr; | 
|  | 7310 | else | 
|  | 7311 | return ToBaseOrErr.takeError(); | 
|  | 7312 | } | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7313 |  | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7314 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7315 | if (E->hasExplicitTemplateArgs()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7316 | if (Error Err = ImportTemplateArgumentListInfo( | 
|  | 7317 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), | 
|  | 7318 | ToTAInfo)) | 
|  | 7319 | return std::move(Err); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7320 | ResInfo = &ToTAInfo; | 
|  | 7321 | } | 
|  | 7322 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7323 | auto ToMemberNameInfoOrErr = importSeq(E->getMember(), E->getMemberLoc()); | 
|  | 7324 | if (!ToMemberNameInfoOrErr) | 
|  | 7325 | return ToMemberNameInfoOrErr.takeError(); | 
|  | 7326 | DeclarationNameInfo ToMemberNameInfo( | 
|  | 7327 | std::get<0>(*ToMemberNameInfoOrErr), std::get<1>(*ToMemberNameInfoOrErr)); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7328 | // Import additional name location/type info. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7329 | if (Error Err = ImportDeclarationNameLoc( | 
|  | 7330 | E->getMemberNameInfo(), ToMemberNameInfo)) | 
|  | 7331 | return std::move(Err); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7332 |  | 
|  | 7333 | return CXXDependentScopeMemberExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7334 | Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc, | 
|  | 7335 | ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope, | 
|  | 7336 | ToMemberNameInfo, ResInfo); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7337 | } | 
|  | 7338 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7339 | ExpectedStmt | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7340 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7341 | auto Imp = importSeq( | 
|  | 7342 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDeclName(), | 
|  | 7343 | E->getExprLoc(), E->getLAngleLoc(), E->getRAngleLoc()); | 
|  | 7344 | if (!Imp) | 
|  | 7345 | return Imp.takeError(); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7346 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7347 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 7348 | SourceLocation ToTemplateKeywordLoc, ToExprLoc, ToLAngleLoc, ToRAngleLoc; | 
|  | 7349 | DeclarationName ToDeclName; | 
|  | 7350 | std::tie( | 
|  | 7351 | ToQualifierLoc, ToTemplateKeywordLoc, ToDeclName, ToExprLoc, | 
|  | 7352 | ToLAngleLoc, ToRAngleLoc) = *Imp; | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7353 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7354 | DeclarationNameInfo ToNameInfo(ToDeclName, ToExprLoc); | 
|  | 7355 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) | 
|  | 7356 | return std::move(Err); | 
|  | 7357 |  | 
|  | 7358 | TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7359 | TemplateArgumentListInfo *ResInfo = nullptr; | 
|  | 7360 | if (E->hasExplicitTemplateArgs()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7361 | if (Error Err = | 
|  | 7362 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) | 
|  | 7363 | return std::move(Err); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7364 | ResInfo = &ToTAInfo; | 
|  | 7365 | } | 
|  | 7366 |  | 
|  | 7367 | return DependentScopeDeclRefExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7368 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, | 
|  | 7369 | ToNameInfo, ResInfo); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7370 | } | 
|  | 7371 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7372 | ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr( | 
|  | 7373 | CXXUnresolvedConstructExpr *E) { | 
|  | 7374 | auto Imp = importSeq( | 
|  | 7375 | E->getLParenLoc(), E->getRParenLoc(), E->getTypeSourceInfo()); | 
|  | 7376 | if (!Imp) | 
|  | 7377 | return Imp.takeError(); | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7378 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7379 | SourceLocation ToLParenLoc, ToRParenLoc; | 
|  | 7380 | TypeSourceInfo *ToTypeSourceInfo; | 
|  | 7381 | std::tie(ToLParenLoc, ToRParenLoc, ToTypeSourceInfo) = *Imp; | 
|  | 7382 |  | 
|  | 7383 | SmallVector<Expr *, 8> ToArgs(E->arg_size()); | 
|  | 7384 | if (Error Err = | 
|  | 7385 | ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin())) | 
|  | 7386 | return std::move(Err); | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7387 |  | 
|  | 7388 | return CXXUnresolvedConstructExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7389 | Importer.getToContext(), ToTypeSourceInfo, ToLParenLoc, | 
|  | 7390 | llvm::makeArrayRef(ToArgs), ToRParenLoc); | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7391 | } | 
|  | 7392 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7393 | ExpectedStmt | 
|  | 7394 | ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { | 
|  | 7395 | Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass()); | 
|  | 7396 | if (!ToNamingClassOrErr) | 
|  | 7397 | return ToNamingClassOrErr.takeError(); | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7398 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7399 | auto ToQualifierLocOrErr = import(E->getQualifierLoc()); | 
|  | 7400 | if (!ToQualifierLocOrErr) | 
|  | 7401 | return ToQualifierLocOrErr.takeError(); | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7402 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7403 | auto ToNameInfoOrErr = importSeq(E->getName(), E->getNameLoc()); | 
|  | 7404 | if (!ToNameInfoOrErr) | 
|  | 7405 | return ToNameInfoOrErr.takeError(); | 
|  | 7406 | DeclarationNameInfo ToNameInfo( | 
|  | 7407 | std::get<0>(*ToNameInfoOrErr), std::get<1>(*ToNameInfoOrErr)); | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7408 | // Import additional name location/type info. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7409 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) | 
|  | 7410 | return std::move(Err); | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7411 |  | 
|  | 7412 | UnresolvedSet<8> ToDecls; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7413 | for (auto *D : E->decls()) | 
|  | 7414 | if (auto ToDOrErr = import(D)) | 
|  | 7415 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7416 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7417 | return ToDOrErr.takeError(); | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7418 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7419 | if (E->hasExplicitTemplateArgs() && E->getTemplateKeywordLoc().isValid()) { | 
|  | 7420 | TemplateArgumentListInfo ToTAInfo; | 
|  | 7421 | if (Error Err = ImportTemplateArgumentListInfo( | 
|  | 7422 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), | 
|  | 7423 | ToTAInfo)) | 
|  | 7424 | return std::move(Err); | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7425 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7426 | ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc()); | 
|  | 7427 | if (!ToTemplateKeywordLocOrErr) | 
|  | 7428 | return ToTemplateKeywordLocOrErr.takeError(); | 
|  | 7429 |  | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7430 | return UnresolvedLookupExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7431 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, | 
|  | 7432 | *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo, | 
|  | 7433 | ToDecls.begin(), ToDecls.end()); | 
|  | 7434 | } | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7435 |  | 
|  | 7436 | return UnresolvedLookupExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7437 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, | 
|  | 7438 | ToNameInfo, E->requiresADL(), E->isOverloaded(), ToDecls.begin(), | 
|  | 7439 | ToDecls.end()); | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7440 | } | 
|  | 7441 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7442 | ExpectedStmt | 
|  | 7443 | ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { | 
|  | 7444 | auto Imp1 = importSeq( | 
|  | 7445 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), | 
|  | 7446 | E->getTemplateKeywordLoc()); | 
|  | 7447 | if (!Imp1) | 
|  | 7448 | return Imp1.takeError(); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7449 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7450 | QualType ToType; | 
|  | 7451 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; | 
|  | 7452 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 7453 | std::tie(ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc) = *Imp1; | 
|  | 7454 |  | 
|  | 7455 | auto Imp2 = importSeq(E->getName(), E->getNameLoc()); | 
|  | 7456 | if (!Imp2) | 
|  | 7457 | return Imp2.takeError(); | 
|  | 7458 | DeclarationNameInfo ToNameInfo(std::get<0>(*Imp2), std::get<1>(*Imp2)); | 
|  | 7459 | // Import additional name location/type info. | 
|  | 7460 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) | 
|  | 7461 | return std::move(Err); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7462 |  | 
|  | 7463 | UnresolvedSet<8> ToDecls; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7464 | for (Decl *D : E->decls()) | 
|  | 7465 | if (auto ToDOrErr = import(D)) | 
|  | 7466 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7467 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7468 | return ToDOrErr.takeError(); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7469 |  | 
|  | 7470 | TemplateArgumentListInfo ToTAInfo; | 
|  | 7471 | TemplateArgumentListInfo *ResInfo = nullptr; | 
|  | 7472 | if (E->hasExplicitTemplateArgs()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7473 | if (Error Err = | 
|  | 7474 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) | 
|  | 7475 | return std::move(Err); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7476 | ResInfo = &ToTAInfo; | 
|  | 7477 | } | 
|  | 7478 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7479 | Expr *ToBase = nullptr; | 
|  | 7480 | if (!E->isImplicitAccess()) { | 
|  | 7481 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) | 
|  | 7482 | ToBase = *ToBaseOrErr; | 
|  | 7483 | else | 
|  | 7484 | return ToBaseOrErr.takeError(); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7485 | } | 
|  | 7486 |  | 
|  | 7487 | return UnresolvedMemberExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7488 | Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType, | 
|  | 7489 | E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, | 
|  | 7490 | ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end()); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7491 | } | 
|  | 7492 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7493 | ExpectedStmt ASTNodeImporter::VisitCallExpr(CallExpr *E) { | 
|  | 7494 | auto Imp = importSeq(E->getCallee(), E->getType(), E->getRParenLoc()); | 
|  | 7495 | if (!Imp) | 
|  | 7496 | return Imp.takeError(); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7497 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7498 | Expr *ToCallee; | 
|  | 7499 | QualType ToType; | 
|  | 7500 | SourceLocation ToRParenLoc; | 
|  | 7501 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7502 |  | 
|  | 7503 | unsigned NumArgs = E->getNumArgs(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7504 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); | 
|  | 7505 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | 
|  | 7506 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7507 |  | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7508 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { | 
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7509 | return CXXOperatorCallExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7510 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType, | 
| Eric Fiselier | 5cdc2cd | 2018-12-12 21:50:55 +0000 | [diff] [blame] | 7511 | OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(), | 
|  | 7512 | OCE->getADLCallKind()); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7513 | } | 
|  | 7514 |  | 
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7515 | return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType, | 
|  | 7516 | E->getValueKind(), ToRParenLoc, /*MinNumArgs=*/0, | 
|  | 7517 | E->getADLCallKind()); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7518 | } | 
|  | 7519 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7520 | ExpectedStmt ASTNodeImporter::VisitLambdaExpr(LambdaExpr *E) { | 
|  | 7521 | CXXRecordDecl *FromClass = E->getLambdaClass(); | 
|  | 7522 | auto ToClassOrErr = import(FromClass); | 
|  | 7523 | if (!ToClassOrErr) | 
|  | 7524 | return ToClassOrErr.takeError(); | 
|  | 7525 | CXXRecordDecl *ToClass = *ToClassOrErr; | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7526 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7527 | auto ToCallOpOrErr = import(E->getCallOperator()); | 
|  | 7528 | if (!ToCallOpOrErr) | 
|  | 7529 | return ToCallOpOrErr.takeError(); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7530 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7531 | SmallVector<LambdaCapture, 8> ToCaptures; | 
|  | 7532 | ToCaptures.reserve(E->capture_size()); | 
|  | 7533 | for (const auto &FromCapture : E->captures()) { | 
|  | 7534 | if (auto ToCaptureOrErr = import(FromCapture)) | 
|  | 7535 | ToCaptures.push_back(*ToCaptureOrErr); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7536 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7537 | return ToCaptureOrErr.takeError(); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7538 | } | 
|  | 7539 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7540 | SmallVector<Expr *, 8> ToCaptureInits(E->capture_size()); | 
|  | 7541 | if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits)) | 
|  | 7542 | return std::move(Err); | 
|  | 7543 |  | 
|  | 7544 | auto Imp = importSeq( | 
|  | 7545 | E->getIntroducerRange(), E->getCaptureDefaultLoc(), E->getEndLoc()); | 
|  | 7546 | if (!Imp) | 
|  | 7547 | return Imp.takeError(); | 
|  | 7548 |  | 
|  | 7549 | SourceRange ToIntroducerRange; | 
|  | 7550 | SourceLocation ToCaptureDefaultLoc, ToEndLoc; | 
|  | 7551 | std::tie(ToIntroducerRange, ToCaptureDefaultLoc, ToEndLoc) = *Imp; | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7552 |  | 
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 7553 | return LambdaExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7554 | Importer.getToContext(), ToClass, ToIntroducerRange, | 
|  | 7555 | E->getCaptureDefault(), ToCaptureDefaultLoc, ToCaptures, | 
|  | 7556 | E->hasExplicitParameters(), E->hasExplicitResultType(), ToCaptureInits, | 
|  | 7557 | ToEndLoc, E->containsUnexpandedParameterPack()); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7558 | } | 
|  | 7559 |  | 
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7560 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7561 | ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) { | 
|  | 7562 | auto Imp = importSeq(E->getLBraceLoc(), E->getRBraceLoc(), E->getType()); | 
|  | 7563 | if (!Imp) | 
|  | 7564 | return Imp.takeError(); | 
|  | 7565 |  | 
|  | 7566 | SourceLocation ToLBraceLoc, ToRBraceLoc; | 
|  | 7567 | QualType ToType; | 
|  | 7568 | std::tie(ToLBraceLoc, ToRBraceLoc, ToType) = *Imp; | 
|  | 7569 |  | 
|  | 7570 | SmallVector<Expr *, 4> ToExprs(E->getNumInits()); | 
|  | 7571 | if (Error Err = ImportContainerChecked(E->inits(), ToExprs)) | 
|  | 7572 | return std::move(Err); | 
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7573 |  | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7574 | ASTContext &ToCtx = Importer.getToContext(); | 
|  | 7575 | InitListExpr *To = new (ToCtx) InitListExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7576 | ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc); | 
|  | 7577 | To->setType(ToType); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7578 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7579 | if (E->hasArrayFiller()) { | 
|  | 7580 | if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller())) | 
|  | 7581 | To->setArrayFiller(*ToFillerOrErr); | 
|  | 7582 | else | 
|  | 7583 | return ToFillerOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7584 | } | 
|  | 7585 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7586 | if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) { | 
|  | 7587 | if (auto ToFDOrErr = import(FromFD)) | 
|  | 7588 | To->setInitializedFieldInUnion(*ToFDOrErr); | 
|  | 7589 | else | 
|  | 7590 | return ToFDOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7591 | } | 
|  | 7592 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7593 | if (InitListExpr *SyntForm = E->getSyntacticForm()) { | 
|  | 7594 | if (auto ToSyntFormOrErr = import(SyntForm)) | 
|  | 7595 | To->setSyntacticForm(*ToSyntFormOrErr); | 
|  | 7596 | else | 
|  | 7597 | return ToSyntFormOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7598 | } | 
|  | 7599 |  | 
| Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7600 | // Copy InitListExprBitfields, which are not handled in the ctor of | 
|  | 7601 | // InitListExpr. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7602 | To->sawArrayRangeDesignator(E->hadArrayRangeDesignator()); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7603 |  | 
|  | 7604 | return To; | 
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7605 | } | 
|  | 7606 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7607 | ExpectedStmt ASTNodeImporter::VisitCXXStdInitializerListExpr( | 
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7608 | CXXStdInitializerListExpr *E) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7609 | ExpectedType ToTypeOrErr = import(E->getType()); | 
|  | 7610 | if (!ToTypeOrErr) | 
|  | 7611 | return ToTypeOrErr.takeError(); | 
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7612 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7613 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | 
|  | 7614 | if (!ToSubExprOrErr) | 
|  | 7615 | return ToSubExprOrErr.takeError(); | 
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7616 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7617 | return new (Importer.getToContext()) CXXStdInitializerListExpr( | 
|  | 7618 | *ToTypeOrErr, *ToSubExprOrErr); | 
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7619 | } | 
|  | 7620 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7621 | ExpectedStmt ASTNodeImporter::VisitCXXInheritedCtorInitExpr( | 
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7622 | CXXInheritedCtorInitExpr *E) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7623 | auto Imp = importSeq(E->getLocation(), E->getType(), E->getConstructor()); | 
|  | 7624 | if (!Imp) | 
|  | 7625 | return Imp.takeError(); | 
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7626 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7627 | SourceLocation ToLocation; | 
|  | 7628 | QualType ToType; | 
|  | 7629 | CXXConstructorDecl *ToConstructor; | 
|  | 7630 | std::tie(ToLocation, ToType, ToConstructor) = *Imp; | 
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7631 |  | 
|  | 7632 | return new (Importer.getToContext()) CXXInheritedCtorInitExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7633 | ToLocation, ToType, ToConstructor, E->constructsVBase(), | 
|  | 7634 | E->inheritedFromVBase()); | 
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7635 | } | 
|  | 7636 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7637 | ExpectedStmt ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { | 
|  | 7638 | auto Imp = importSeq(E->getType(), E->getCommonExpr(), E->getSubExpr()); | 
|  | 7639 | if (!Imp) | 
|  | 7640 | return Imp.takeError(); | 
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7641 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7642 | QualType ToType; | 
|  | 7643 | Expr *ToCommonExpr, *ToSubExpr; | 
|  | 7644 | std::tie(ToType, ToCommonExpr, ToSubExpr) = *Imp; | 
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7645 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7646 | return new (Importer.getToContext()) ArrayInitLoopExpr( | 
|  | 7647 | ToType, ToCommonExpr, ToSubExpr); | 
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7648 | } | 
|  | 7649 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7650 | ExpectedStmt ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { | 
|  | 7651 | ExpectedType ToTypeOrErr = import(E->getType()); | 
|  | 7652 | if (!ToTypeOrErr) | 
|  | 7653 | return ToTypeOrErr.takeError(); | 
|  | 7654 | return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr); | 
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7655 | } | 
|  | 7656 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7657 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { | 
|  | 7658 | ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc()); | 
|  | 7659 | if (!ToBeginLocOrErr) | 
|  | 7660 | return ToBeginLocOrErr.takeError(); | 
|  | 7661 |  | 
|  | 7662 | auto ToFieldOrErr = import(E->getField()); | 
|  | 7663 | if (!ToFieldOrErr) | 
|  | 7664 | return ToFieldOrErr.takeError(); | 
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7665 |  | 
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 7666 | auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext()); | 
|  | 7667 | if (!UsedContextOrErr) | 
|  | 7668 | return UsedContextOrErr.takeError(); | 
|  | 7669 |  | 
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7670 | return CXXDefaultInitExpr::Create( | 
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 7671 | Importer.getToContext(), *ToBeginLocOrErr, *ToFieldOrErr, *UsedContextOrErr); | 
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7672 | } | 
|  | 7673 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7674 | ExpectedStmt ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { | 
|  | 7675 | auto Imp = importSeq( | 
|  | 7676 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten(), | 
|  | 7677 | E->getOperatorLoc(), E->getRParenLoc(), E->getAngleBrackets()); | 
|  | 7678 | if (!Imp) | 
|  | 7679 | return Imp.takeError(); | 
|  | 7680 |  | 
|  | 7681 | QualType ToType; | 
|  | 7682 | Expr *ToSubExpr; | 
|  | 7683 | TypeSourceInfo *ToTypeInfoAsWritten; | 
|  | 7684 | SourceLocation ToOperatorLoc, ToRParenLoc; | 
|  | 7685 | SourceRange ToAngleBrackets; | 
|  | 7686 | std::tie( | 
|  | 7687 | ToType, ToSubExpr, ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, | 
|  | 7688 | ToAngleBrackets) = *Imp; | 
|  | 7689 |  | 
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7690 | ExprValueKind VK = E->getValueKind(); | 
|  | 7691 | CastKind CK = E->getCastKind(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7692 | auto ToBasePathOrErr = ImportCastPath(E); | 
|  | 7693 | if (!ToBasePathOrErr) | 
|  | 7694 | return ToBasePathOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7695 |  | 
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7696 | if (isa<CXXStaticCastExpr>(E)) { | 
|  | 7697 | return CXXStaticCastExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7698 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), | 
|  | 7699 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); | 
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7700 | } else if (isa<CXXDynamicCastExpr>(E)) { | 
|  | 7701 | return CXXDynamicCastExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7702 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), | 
|  | 7703 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); | 
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7704 | } else if (isa<CXXReinterpretCastExpr>(E)) { | 
|  | 7705 | return CXXReinterpretCastExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7706 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), | 
|  | 7707 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); | 
| Raphael Isemann | c705bb8 | 2018-08-20 16:20:01 +0000 | [diff] [blame] | 7708 | } else if (isa<CXXConstCastExpr>(E)) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7709 | return CXXConstCastExpr::Create( | 
|  | 7710 | Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten, | 
|  | 7711 | ToOperatorLoc, ToRParenLoc, ToAngleBrackets); | 
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7712 | } else { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7713 | llvm_unreachable("Unknown cast type"); | 
|  | 7714 | return make_error<ImportError>(); | 
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7715 | } | 
|  | 7716 | } | 
|  | 7717 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7718 | ExpectedStmt ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7719 | SubstNonTypeTemplateParmExpr *E) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7720 | auto Imp = importSeq( | 
|  | 7721 | E->getType(), E->getExprLoc(), E->getParameter(), E->getReplacement()); | 
|  | 7722 | if (!Imp) | 
|  | 7723 | return Imp.takeError(); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7724 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7725 | QualType ToType; | 
|  | 7726 | SourceLocation ToExprLoc; | 
|  | 7727 | NonTypeTemplateParmDecl *ToParameter; | 
|  | 7728 | Expr *ToReplacement; | 
|  | 7729 | std::tie(ToType, ToExprLoc, ToParameter, ToReplacement) = *Imp; | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7730 |  | 
|  | 7731 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7732 | ToType, E->getValueKind(), ToExprLoc, ToParameter, ToReplacement); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7733 | } | 
|  | 7734 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7735 | ExpectedStmt ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { | 
|  | 7736 | auto Imp = importSeq( | 
|  | 7737 | E->getType(), E->getBeginLoc(), E->getEndLoc()); | 
|  | 7738 | if (!Imp) | 
|  | 7739 | return Imp.takeError(); | 
|  | 7740 |  | 
|  | 7741 | QualType ToType; | 
|  | 7742 | SourceLocation ToBeginLoc, ToEndLoc; | 
|  | 7743 | std::tie(ToType, ToBeginLoc, ToEndLoc) = *Imp; | 
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7744 |  | 
|  | 7745 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7746 | if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs)) | 
|  | 7747 | return std::move(Err); | 
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7748 |  | 
|  | 7749 | // According to Sema::BuildTypeTrait(), if E is value-dependent, | 
|  | 7750 | // Value is always false. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7751 | bool ToValue = (E->isValueDependent() ? false : E->getValue()); | 
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7752 |  | 
|  | 7753 | return TypeTraitExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7754 | Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs, | 
|  | 7755 | ToEndLoc, ToValue); | 
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7756 | } | 
|  | 7757 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7758 | ExpectedStmt ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { | 
|  | 7759 | ExpectedType ToTypeOrErr = import(E->getType()); | 
|  | 7760 | if (!ToTypeOrErr) | 
|  | 7761 | return ToTypeOrErr.takeError(); | 
|  | 7762 |  | 
|  | 7763 | auto ToSourceRangeOrErr = import(E->getSourceRange()); | 
|  | 7764 | if (!ToSourceRangeOrErr) | 
|  | 7765 | return ToSourceRangeOrErr.takeError(); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7766 |  | 
|  | 7767 | if (E->isTypeOperand()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7768 | if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo())) | 
|  | 7769 | return new (Importer.getToContext()) CXXTypeidExpr( | 
|  | 7770 | *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr); | 
|  | 7771 | else | 
|  | 7772 | return ToTSIOrErr.takeError(); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7773 | } | 
|  | 7774 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7775 | ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand()); | 
|  | 7776 | if (!ToExprOperandOrErr) | 
|  | 7777 | return ToExprOperandOrErr.takeError(); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7778 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7779 | return new (Importer.getToContext()) CXXTypeidExpr( | 
|  | 7780 | *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7781 | } | 
|  | 7782 |  | 
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 7783 | Error ASTNodeImporter::ImportOverriddenMethods(CXXMethodDecl *ToMethod, | 
|  | 7784 | CXXMethodDecl *FromMethod) { | 
|  | 7785 | Error ImportErrors = Error::success(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7786 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) { | 
|  | 7787 | if (auto ImportedOrErr = import(FromOverriddenMethod)) | 
|  | 7788 | ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>( | 
|  | 7789 | (*ImportedOrErr)->getCanonicalDecl())); | 
|  | 7790 | else | 
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 7791 | ImportErrors = | 
|  | 7792 | joinErrors(std::move(ImportErrors), ImportedOrErr.takeError()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7793 | } | 
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 7794 | return ImportErrors; | 
| Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7795 | } | 
|  | 7796 |  | 
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7797 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, | 
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7798 | ASTContext &FromContext, FileManager &FromFileManager, | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7799 | bool MinimalImport, | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7800 | std::shared_ptr<ASTImporterSharedState> SharedState) | 
|  | 7801 | : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext), | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7802 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), | 
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 7803 | Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) { | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7804 |  | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7805 | // Create a default state without the lookup table: LLDB case. | 
|  | 7806 | if (!SharedState) { | 
|  | 7807 | this->SharedState = std::make_shared<ASTImporterSharedState>(); | 
|  | 7808 | } | 
|  | 7809 |  | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7810 | ImportedDecls[FromContext.getTranslationUnitDecl()] = | 
|  | 7811 | ToContext.getTranslationUnitDecl(); | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7812 | } | 
|  | 7813 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7814 | ASTImporter::~ASTImporter() = default; | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7815 |  | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7816 | Optional<unsigned> ASTImporter::getFieldIndex(Decl *F) { | 
|  | 7817 | assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) && | 
|  | 7818 | "Try to get field index for non-field."); | 
|  | 7819 |  | 
|  | 7820 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); | 
|  | 7821 | if (!Owner) | 
|  | 7822 | return None; | 
|  | 7823 |  | 
|  | 7824 | unsigned Index = 0; | 
|  | 7825 | for (const auto *D : Owner->decls()) { | 
|  | 7826 | if (D == F) | 
|  | 7827 | return Index; | 
|  | 7828 |  | 
|  | 7829 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) | 
|  | 7830 | ++Index; | 
|  | 7831 | } | 
|  | 7832 |  | 
|  | 7833 | llvm_unreachable("Field was not found in its parent context."); | 
|  | 7834 |  | 
|  | 7835 | return None; | 
|  | 7836 | } | 
|  | 7837 |  | 
|  | 7838 | ASTImporter::FoundDeclsTy | 
|  | 7839 | ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) { | 
|  | 7840 | // We search in the redecl context because of transparent contexts. | 
|  | 7841 | // E.g. a simple C language enum is a transparent context: | 
|  | 7842 | //   enum E { A, B }; | 
|  | 7843 | // Now if we had a global variable in the TU | 
|  | 7844 | //   int A; | 
|  | 7845 | // then the enum constant 'A' and the variable 'A' violates ODR. | 
|  | 7846 | // We can diagnose this only if we search in the redecl context. | 
|  | 7847 | DeclContext *ReDC = DC->getRedeclContext(); | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7848 | if (SharedState->getLookupTable()) { | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7849 | ASTImporterLookupTable::LookupResult LookupResult = | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7850 | SharedState->getLookupTable()->lookup(ReDC, Name); | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7851 | return FoundDeclsTy(LookupResult.begin(), LookupResult.end()); | 
|  | 7852 | } else { | 
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 7853 | DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name); | 
|  | 7854 | FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end()); | 
|  | 7855 | // We must search by the slow case of localUncachedLookup because that is | 
|  | 7856 | // working even if there is no LookupPtr for the DC. We could use | 
|  | 7857 | // DC::buildLookup() to create the LookupPtr, but that would load external | 
|  | 7858 | // decls again, we must avoid that case. | 
|  | 7859 | // Also, even if we had the LookupPtr, we must find Decls which are not | 
|  | 7860 | // in the LookupPtr, so we need the slow case. | 
|  | 7861 | // These cases are handled in ASTImporterLookupTable, but we cannot use | 
|  | 7862 | // that with LLDB since that traverses through the AST which initiates the | 
|  | 7863 | // load of external decls again via DC::decls().  And again, we must avoid | 
|  | 7864 | // loading external decls during the import. | 
|  | 7865 | if (Result.empty()) | 
|  | 7866 | ReDC->localUncachedLookup(Name, Result); | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7867 | return Result; | 
|  | 7868 | } | 
|  | 7869 | } | 
|  | 7870 |  | 
|  | 7871 | void ASTImporter::AddToLookupTable(Decl *ToD) { | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7872 | SharedState->addDeclToLookup(ToD); | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7873 | } | 
|  | 7874 |  | 
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 7875 | Expected<Decl *> ASTImporter::ImportImpl(Decl *FromD) { | 
|  | 7876 | // Import the decl using ASTNodeImporter. | 
|  | 7877 | ASTNodeImporter Importer(*this); | 
|  | 7878 | return Importer.Visit(FromD); | 
|  | 7879 | } | 
|  | 7880 |  | 
|  | 7881 | void ASTImporter::RegisterImportedDecl(Decl *FromD, Decl *ToD) { | 
|  | 7882 | MapImported(FromD, ToD); | 
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 7883 | } | 
|  | 7884 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7885 | Expected<QualType> ASTImporter::Import(QualType FromT) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7886 | if (FromT.isNull()) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7887 | return QualType{}; | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7888 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7889 | const Type *FromTy = FromT.getTypePtr(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7890 |  | 
|  | 7891 | // Check whether we've already imported this type. | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7892 | llvm::DenseMap<const Type *, const Type *>::iterator Pos | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7893 | = ImportedTypes.find(FromTy); | 
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7894 | if (Pos != ImportedTypes.end()) | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7895 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7896 |  | 
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7897 | // Import the type | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7898 | ASTNodeImporter Importer(*this); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7899 | ExpectedType ToTOrErr = Importer.Visit(FromTy); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7900 | if (!ToTOrErr) | 
|  | 7901 | return ToTOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7902 |  | 
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7903 | // Record the imported type. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7904 | ImportedTypes[FromTy] = (*ToTOrErr).getTypePtr(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7905 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7906 | return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7907 | } | 
|  | 7908 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7909 | Expected<TypeSourceInfo *> ASTImporter::Import(TypeSourceInfo *FromTSI) { | 
| Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7910 | if (!FromTSI) | 
|  | 7911 | return FromTSI; | 
|  | 7912 |  | 
|  | 7913 | // FIXME: For now we just create a "trivial" type source info based | 
| Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 7914 | // on the type and a single location. Implement a real version of this. | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7915 | ExpectedType TOrErr = Import(FromTSI->getType()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7916 | if (!TOrErr) | 
|  | 7917 | return TOrErr.takeError(); | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7918 | ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7919 | if (!BeginLocOrErr) | 
|  | 7920 | return BeginLocOrErr.takeError(); | 
| Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7921 |  | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7922 | return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr); | 
|  | 7923 | } | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7924 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7925 | Expected<Attr *> ASTImporter::Import(const Attr *FromAttr) { | 
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7926 | Attr *ToAttr = FromAttr->clone(ToContext); | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7927 | if (auto ToRangeOrErr = Import(FromAttr->getRange())) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7928 | ToAttr->setRange(*ToRangeOrErr); | 
|  | 7929 | else | 
|  | 7930 | return ToRangeOrErr.takeError(); | 
|  | 7931 |  | 
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7932 | return ToAttr; | 
| Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 7933 | } | 
| Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 7934 |  | 
| Gabor Marton | be77a98 | 2018-12-12 11:22:55 +0000 | [diff] [blame] | 7935 | Decl *ASTImporter::GetAlreadyImportedOrNull(const Decl *FromD) const { | 
|  | 7936 | auto Pos = ImportedDecls.find(FromD); | 
|  | 7937 | if (Pos != ImportedDecls.end()) | 
|  | 7938 | return Pos->second; | 
|  | 7939 | else | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7940 | return nullptr; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7941 | } | 
|  | 7942 |  | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 7943 | TranslationUnitDecl *ASTImporter::GetFromTU(Decl *ToD) { | 
|  | 7944 | auto FromDPos = ImportedFromDecls.find(ToD); | 
|  | 7945 | if (FromDPos == ImportedFromDecls.end()) | 
|  | 7946 | return nullptr; | 
|  | 7947 | return FromDPos->second->getTranslationUnitDecl(); | 
|  | 7948 | } | 
|  | 7949 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7950 | Expected<Decl *> ASTImporter::Import(Decl *FromD) { | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7951 | if (!FromD) | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7952 | return nullptr; | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7953 |  | 
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 7954 | // Push FromD to the stack, and remove that when we return. | 
|  | 7955 | ImportPath.push(FromD); | 
|  | 7956 | auto ImportPathBuilder = | 
|  | 7957 | llvm::make_scope_exit([this]() { ImportPath.pop(); }); | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7958 |  | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 7959 | // Check whether there was a previous failed import. | 
|  | 7960 | // If yes return the existing error. | 
|  | 7961 | if (auto Error = getImportDeclErrorIfAny(FromD)) | 
|  | 7962 | return make_error<ImportError>(*Error); | 
|  | 7963 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7964 | // Check whether we've already imported this declaration. | 
|  | 7965 | Decl *ToD = GetAlreadyImportedOrNull(FromD); | 
|  | 7966 | if (ToD) { | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7967 | // Already imported (possibly from another TU) and with an error. | 
|  | 7968 | if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) { | 
|  | 7969 | setImportDeclError(FromD, *Error); | 
|  | 7970 | return make_error<ImportError>(*Error); | 
|  | 7971 | } | 
|  | 7972 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7973 | // If FromD has some updated flags after last import, apply it | 
|  | 7974 | updateFlags(FromD, ToD); | 
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 7975 | // If we encounter a cycle during an import then we save the relevant part | 
|  | 7976 | // of the import path associated to the Decl. | 
|  | 7977 | if (ImportPath.hasCycleAtBack()) | 
|  | 7978 | SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack()); | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7979 | return ToD; | 
|  | 7980 | } | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7981 |  | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7982 | // Import the declaration. | 
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 7983 | ExpectedDecl ToDOrErr = ImportImpl(FromD); | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 7984 | if (!ToDOrErr) { | 
|  | 7985 | // Failed to import. | 
|  | 7986 |  | 
|  | 7987 | auto Pos = ImportedDecls.find(FromD); | 
|  | 7988 | if (Pos != ImportedDecls.end()) { | 
|  | 7989 | // Import failed after the object was created. | 
|  | 7990 | // Remove all references to it. | 
|  | 7991 | auto *ToD = Pos->second; | 
|  | 7992 | ImportedDecls.erase(Pos); | 
|  | 7993 |  | 
|  | 7994 | // ImportedDecls and ImportedFromDecls are not symmetric.  It may happen | 
|  | 7995 | // (e.g. with namespaces) that several decls from the 'from' context are | 
|  | 7996 | // mapped to the same decl in the 'to' context.  If we removed entries | 
|  | 7997 | // from the LookupTable here then we may end up removing them multiple | 
|  | 7998 | // times. | 
|  | 7999 |  | 
|  | 8000 | // The Lookuptable contains decls only which are in the 'to' context. | 
|  | 8001 | // Remove from the Lookuptable only if it is *imported* into the 'to' | 
|  | 8002 | // context (and do not remove it if it was added during the initial | 
|  | 8003 | // traverse of the 'to' context). | 
|  | 8004 | auto PosF = ImportedFromDecls.find(ToD); | 
|  | 8005 | if (PosF != ImportedFromDecls.end()) { | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8006 | SharedState->removeDeclFromLookup(ToD); | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8007 | ImportedFromDecls.erase(PosF); | 
|  | 8008 | } | 
|  | 8009 |  | 
|  | 8010 | // FIXME: AST may contain remaining references to the failed object. | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8011 | // However, the ImportDeclErrors in the shared state contains all the | 
|  | 8012 | // failed objects together with their error. | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8013 | } | 
|  | 8014 |  | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8015 | // Error encountered for the first time. | 
|  | 8016 | // After takeError the error is not usable any more in ToDOrErr. | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8017 | // Get a copy of the error object (any more simple solution for this?). | 
|  | 8018 | ImportError ErrOut; | 
|  | 8019 | handleAllErrors(ToDOrErr.takeError(), | 
|  | 8020 | [&ErrOut](const ImportError &E) { ErrOut = E; }); | 
|  | 8021 | setImportDeclError(FromD, ErrOut); | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8022 | // Set the error for the mapped to Decl, which is in the "to" context. | 
|  | 8023 | if (Pos != ImportedDecls.end()) | 
|  | 8024 | SharedState->setImportDeclError(Pos->second, ErrOut); | 
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8025 |  | 
|  | 8026 | // Set the error for all nodes which have been created before we | 
|  | 8027 | // recognized the error. | 
|  | 8028 | for (const auto &Path : SavedImportPaths[FromD]) | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8029 | for (Decl *FromDi : Path) { | 
|  | 8030 | setImportDeclError(FromDi, ErrOut); | 
|  | 8031 | //FIXME Should we remove these Decls from ImportedDecls? | 
|  | 8032 | // Set the error for the mapped to Decl, which is in the "to" context. | 
|  | 8033 | auto Ii = ImportedDecls.find(FromDi); | 
|  | 8034 | if (Ii != ImportedDecls.end()) | 
|  | 8035 | SharedState->setImportDeclError(Ii->second, ErrOut); | 
|  | 8036 | // FIXME Should we remove these Decls from the LookupTable, | 
|  | 8037 | // and from ImportedFromDecls? | 
|  | 8038 | } | 
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8039 | SavedImportPaths[FromD].clear(); | 
|  | 8040 |  | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8041 | // Do not return ToDOrErr, error was taken out of it. | 
|  | 8042 | return make_error<ImportError>(ErrOut); | 
|  | 8043 | } | 
|  | 8044 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8045 | ToD = *ToDOrErr; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8046 |  | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8047 | // FIXME: Handle the "already imported with error" case. We can get here | 
|  | 8048 | // nullptr only if GetImportedOrCreateDecl returned nullptr (after a | 
|  | 8049 | // previously failed create was requested). | 
|  | 8050 | // Later GetImportedOrCreateDecl can be updated to return the error. | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 8051 | if (!ToD) { | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8052 | auto Err = getImportDeclErrorIfAny(FromD); | 
|  | 8053 | assert(Err); | 
|  | 8054 | return make_error<ImportError>(*Err); | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 8055 | } | 
|  | 8056 |  | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8057 | // We could import from the current TU without error.  But previously we | 
|  | 8058 | // already had imported a Decl as `ToD` from another TU (with another | 
|  | 8059 | // ASTImporter object) and with an error. | 
|  | 8060 | if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) { | 
|  | 8061 | setImportDeclError(FromD, *Error); | 
|  | 8062 | return make_error<ImportError>(*Error); | 
|  | 8063 | } | 
|  | 8064 |  | 
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 8065 | // Make sure that ImportImpl registered the imported decl. | 
|  | 8066 | assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?"); | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8067 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8068 | // Notify subclasses. | 
|  | 8069 | Imported(FromD, ToD); | 
|  | 8070 |  | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 8071 | updateFlags(FromD, ToD); | 
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8072 | SavedImportPaths[FromD].clear(); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8073 | return ToDOrErr; | 
|  | 8074 | } | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8075 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8076 | Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) { | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8077 | if (!FromDC) | 
|  | 8078 | return FromDC; | 
|  | 8079 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8080 | ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC)); | 
| Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 8081 | if (!ToDCOrErr) | 
|  | 8082 | return ToDCOrErr.takeError(); | 
|  | 8083 | auto *ToDC = cast<DeclContext>(*ToDCOrErr); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8084 |  | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8085 | // When we're using a record/enum/Objective-C class/protocol as a context, we | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8086 | // need it to have a definition. | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8087 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { | 
|  | 8088 | auto *FromRecord = cast<RecordDecl>(FromDC); | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8089 | if (ToRecord->isCompleteDefinition()) { | 
|  | 8090 | // Do nothing. | 
|  | 8091 | } else if (FromRecord->isCompleteDefinition()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8092 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | 
|  | 8093 | FromRecord, ToRecord, ASTNodeImporter::IDK_Basic)) | 
|  | 8094 | return std::move(Err); | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8095 | } else { | 
|  | 8096 | CompleteDecl(ToRecord); | 
|  | 8097 | } | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8098 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { | 
|  | 8099 | auto *FromEnum = cast<EnumDecl>(FromDC); | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8100 | if (ToEnum->isCompleteDefinition()) { | 
|  | 8101 | // Do nothing. | 
|  | 8102 | } else if (FromEnum->isCompleteDefinition()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8103 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | 
|  | 8104 | FromEnum, ToEnum, ASTNodeImporter::IDK_Basic)) | 
|  | 8105 | return std::move(Err); | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8106 | } else { | 
|  | 8107 | CompleteDecl(ToEnum); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8108 | } | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8109 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { | 
|  | 8110 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8111 | if (ToClass->getDefinition()) { | 
|  | 8112 | // Do nothing. | 
|  | 8113 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8114 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | 
|  | 8115 | FromDef, ToClass, ASTNodeImporter::IDK_Basic)) | 
|  | 8116 | return std::move(Err); | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8117 | } else { | 
|  | 8118 | CompleteDecl(ToClass); | 
|  | 8119 | } | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8120 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { | 
|  | 8121 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8122 | if (ToProto->getDefinition()) { | 
|  | 8123 | // Do nothing. | 
|  | 8124 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8125 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | 
|  | 8126 | FromDef, ToProto, ASTNodeImporter::IDK_Basic)) | 
|  | 8127 | return std::move(Err); | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8128 | } else { | 
|  | 8129 | CompleteDecl(ToProto); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8130 | } | 
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 8131 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8132 |  | 
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 8133 | return ToDC; | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8134 | } | 
|  | 8135 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8136 | Expected<Expr *> ASTImporter::Import(Expr *FromE) { | 
|  | 8137 | if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE))) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8138 | return cast_or_null<Expr>(*ToSOrErr); | 
|  | 8139 | else | 
|  | 8140 | return ToSOrErr.takeError(); | 
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8141 | } | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8142 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8143 | Expected<Stmt *> ASTImporter::Import(Stmt *FromS) { | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8144 | if (!FromS) | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8145 | return nullptr; | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8146 |  | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8147 | // Check whether we've already imported this statement. | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 8148 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); | 
|  | 8149 | if (Pos != ImportedStmts.end()) | 
|  | 8150 | return Pos->second; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8151 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8152 | // Import the statement. | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 8153 | ASTNodeImporter Importer(*this); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8154 | ExpectedStmt ToSOrErr = Importer.Visit(FromS); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8155 | if (!ToSOrErr) | 
|  | 8156 | return ToSOrErr; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8157 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8158 | if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) { | 
| Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 8159 | auto *FromE = cast<Expr>(FromS); | 
|  | 8160 | // Copy ExprBitfields, which may not be handled in Expr subclasses | 
|  | 8161 | // constructors. | 
|  | 8162 | ToE->setValueKind(FromE->getValueKind()); | 
|  | 8163 | ToE->setObjectKind(FromE->getObjectKind()); | 
|  | 8164 | ToE->setTypeDependent(FromE->isTypeDependent()); | 
|  | 8165 | ToE->setValueDependent(FromE->isValueDependent()); | 
|  | 8166 | ToE->setInstantiationDependent(FromE->isInstantiationDependent()); | 
|  | 8167 | ToE->setContainsUnexpandedParameterPack( | 
|  | 8168 | FromE->containsUnexpandedParameterPack()); | 
|  | 8169 | } | 
|  | 8170 |  | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8171 | // Record the imported statement object. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8172 | ImportedStmts[FromS] = *ToSOrErr; | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8173 | return ToSOrErr; | 
|  | 8174 | } | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8175 |  | 
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8176 | Expected<NestedNameSpecifier *> | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8177 | ASTImporter::Import(NestedNameSpecifier *FromNNS) { | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8178 | if (!FromNNS) | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8179 | return nullptr; | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8180 |  | 
| Simon Pilgrim | 130df2c | 2019-07-15 13:00:43 +0000 | [diff] [blame] | 8181 | NestedNameSpecifier *Prefix = nullptr; | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8182 | if (Error Err = importInto(Prefix, FromNNS->getPrefix())) | 
|  | 8183 | return std::move(Err); | 
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8184 |  | 
|  | 8185 | switch (FromNNS->getKind()) { | 
|  | 8186 | case NestedNameSpecifier::Identifier: | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8187 | assert(FromNNS->getAsIdentifier() && "NNS should contain identifier."); | 
|  | 8188 | return NestedNameSpecifier::Create(ToContext, Prefix, | 
|  | 8189 | Import(FromNNS->getAsIdentifier())); | 
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8190 |  | 
|  | 8191 | case NestedNameSpecifier::Namespace: | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8192 | if (ExpectedDecl NSOrErr = Import(FromNNS->getAsNamespace())) { | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8193 | return NestedNameSpecifier::Create(ToContext, Prefix, | 
|  | 8194 | cast<NamespaceDecl>(*NSOrErr)); | 
|  | 8195 | } else | 
|  | 8196 | return NSOrErr.takeError(); | 
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8197 |  | 
|  | 8198 | case NestedNameSpecifier::NamespaceAlias: | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8199 | if (ExpectedDecl NSADOrErr = Import(FromNNS->getAsNamespaceAlias())) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8200 | return NestedNameSpecifier::Create(ToContext, Prefix, | 
|  | 8201 | cast<NamespaceAliasDecl>(*NSADOrErr)); | 
|  | 8202 | else | 
|  | 8203 | return NSADOrErr.takeError(); | 
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8204 |  | 
|  | 8205 | case NestedNameSpecifier::Global: | 
|  | 8206 | return NestedNameSpecifier::GlobalSpecifier(ToContext); | 
|  | 8207 |  | 
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8208 | case NestedNameSpecifier::Super: | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8209 | if (ExpectedDecl RDOrErr = Import(FromNNS->getAsRecordDecl())) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8210 | return NestedNameSpecifier::SuperSpecifier(ToContext, | 
|  | 8211 | cast<CXXRecordDecl>(*RDOrErr)); | 
|  | 8212 | else | 
|  | 8213 | return RDOrErr.takeError(); | 
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8214 |  | 
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8215 | case NestedNameSpecifier::TypeSpec: | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8216 | case NestedNameSpecifier::TypeSpecWithTemplate: | 
|  | 8217 | if (Expected<QualType> TyOrErr = | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8218 | Import(QualType(FromNNS->getAsType(), 0u))) { | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8219 | bool TSTemplate = | 
|  | 8220 | FromNNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate; | 
|  | 8221 | return NestedNameSpecifier::Create(ToContext, Prefix, TSTemplate, | 
|  | 8222 | TyOrErr->getTypePtr()); | 
|  | 8223 | } else { | 
|  | 8224 | return TyOrErr.takeError(); | 
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8225 | } | 
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8226 | } | 
|  | 8227 |  | 
|  | 8228 | llvm_unreachable("Invalid nested name specifier kind"); | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8229 | } | 
|  | 8230 |  | 
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8231 | Expected<NestedNameSpecifierLoc> | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8232 | ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8233 | // Copied from NestedNameSpecifier mostly. | 
|  | 8234 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; | 
|  | 8235 | NestedNameSpecifierLoc NNS = FromNNS; | 
|  | 8236 |  | 
|  | 8237 | // Push each of the nested-name-specifiers's onto a stack for | 
|  | 8238 | // serialization in reverse order. | 
|  | 8239 | while (NNS) { | 
|  | 8240 | NestedNames.push_back(NNS); | 
|  | 8241 | NNS = NNS.getPrefix(); | 
|  | 8242 | } | 
|  | 8243 |  | 
|  | 8244 | NestedNameSpecifierLocBuilder Builder; | 
|  | 8245 |  | 
|  | 8246 | while (!NestedNames.empty()) { | 
|  | 8247 | NNS = NestedNames.pop_back_val(); | 
| Simon Pilgrim | 4c146ab | 2019-05-18 11:33:27 +0000 | [diff] [blame] | 8248 | NestedNameSpecifier *Spec = nullptr; | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8249 | if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier())) | 
|  | 8250 | return std::move(Err); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8251 |  | 
|  | 8252 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8253 |  | 
|  | 8254 | SourceLocation ToLocalBeginLoc, ToLocalEndLoc; | 
|  | 8255 | if (Kind != NestedNameSpecifier::Super) { | 
|  | 8256 | if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc())) | 
|  | 8257 | return std::move(Err); | 
|  | 8258 |  | 
|  | 8259 | if (Kind != NestedNameSpecifier::Global) | 
|  | 8260 | if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc())) | 
|  | 8261 | return std::move(Err); | 
|  | 8262 | } | 
|  | 8263 |  | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8264 | switch (Kind) { | 
|  | 8265 | case NestedNameSpecifier::Identifier: | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8266 | Builder.Extend(getToContext(), Spec->getAsIdentifier(), ToLocalBeginLoc, | 
|  | 8267 | ToLocalEndLoc); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8268 | break; | 
|  | 8269 |  | 
|  | 8270 | case NestedNameSpecifier::Namespace: | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8271 | Builder.Extend(getToContext(), Spec->getAsNamespace(), ToLocalBeginLoc, | 
|  | 8272 | ToLocalEndLoc); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8273 | break; | 
|  | 8274 |  | 
|  | 8275 | case NestedNameSpecifier::NamespaceAlias: | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8276 | Builder.Extend(getToContext(), Spec->getAsNamespaceAlias(), | 
|  | 8277 | ToLocalBeginLoc, ToLocalEndLoc); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8278 | break; | 
|  | 8279 |  | 
|  | 8280 | case NestedNameSpecifier::TypeSpec: | 
|  | 8281 | case NestedNameSpecifier::TypeSpecWithTemplate: { | 
| Balazs Keri | 5f4fd8b | 2019-03-14 14:20:23 +0000 | [diff] [blame] | 8282 | SourceLocation ToTLoc; | 
|  | 8283 | if (Error Err = importInto(ToTLoc, NNS.getTypeLoc().getBeginLoc())) | 
|  | 8284 | return std::move(Err); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8285 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( | 
| Balazs Keri | 5f4fd8b | 2019-03-14 14:20:23 +0000 | [diff] [blame] | 8286 | QualType(Spec->getAsType(), 0), ToTLoc); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8287 | Builder.Extend(getToContext(), ToLocalBeginLoc, TSI->getTypeLoc(), | 
|  | 8288 | ToLocalEndLoc); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8289 | break; | 
|  | 8290 | } | 
|  | 8291 |  | 
|  | 8292 | case NestedNameSpecifier::Global: | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8293 | Builder.MakeGlobal(getToContext(), ToLocalBeginLoc); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8294 | break; | 
|  | 8295 |  | 
|  | 8296 | case NestedNameSpecifier::Super: { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8297 | auto ToSourceRangeOrErr = Import(NNS.getSourceRange()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8298 | if (!ToSourceRangeOrErr) | 
|  | 8299 | return ToSourceRangeOrErr.takeError(); | 
|  | 8300 |  | 
|  | 8301 | Builder.MakeSuper(getToContext(), Spec->getAsRecordDecl(), | 
|  | 8302 | ToSourceRangeOrErr->getBegin(), | 
|  | 8303 | ToSourceRangeOrErr->getEnd()); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8304 | } | 
|  | 8305 | } | 
|  | 8306 | } | 
|  | 8307 |  | 
|  | 8308 | return Builder.getWithLocInContext(getToContext()); | 
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 8309 | } | 
|  | 8310 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8311 | Expected<TemplateName> ASTImporter::Import(TemplateName From) { | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8312 | switch (From.getKind()) { | 
|  | 8313 | case TemplateName::Template: | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8314 | if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl())) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8315 | return TemplateName(cast<TemplateDecl>(*ToTemplateOrErr)); | 
|  | 8316 | else | 
|  | 8317 | return ToTemplateOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8318 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8319 | case TemplateName::OverloadedTemplate: { | 
|  | 8320 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); | 
|  | 8321 | UnresolvedSet<2> ToTemplates; | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8322 | for (auto *I : *FromStorage) { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8323 | if (auto ToOrErr = Import(I)) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8324 | ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr)); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8325 | else | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8326 | return ToOrErr.takeError(); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8327 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8328 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8329 | ToTemplates.end()); | 
|  | 8330 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8331 |  | 
| Richard Smith | b23c5e8 | 2019-05-09 03:31:27 +0000 | [diff] [blame] | 8332 | case TemplateName::AssumedTemplate: { | 
|  | 8333 | AssumedTemplateStorage *FromStorage = From.getAsAssumedTemplateName(); | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8334 | auto DeclNameOrErr = Import(FromStorage->getDeclName()); | 
| Richard Smith | b23c5e8 | 2019-05-09 03:31:27 +0000 | [diff] [blame] | 8335 | if (!DeclNameOrErr) | 
|  | 8336 | return DeclNameOrErr.takeError(); | 
|  | 8337 | return ToContext.getAssumedTemplateName(*DeclNameOrErr); | 
|  | 8338 | } | 
|  | 8339 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8340 | case TemplateName::QualifiedTemplate: { | 
|  | 8341 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8342 | auto QualifierOrErr = Import(QTN->getQualifier()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8343 | if (!QualifierOrErr) | 
|  | 8344 | return QualifierOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8345 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8346 | if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl())) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8347 | return ToContext.getQualifiedTemplateName( | 
|  | 8348 | *QualifierOrErr, QTN->hasTemplateKeyword(), | 
|  | 8349 | cast<TemplateDecl>(*ToTemplateOrErr)); | 
|  | 8350 | else | 
|  | 8351 | return ToTemplateOrErr.takeError(); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8352 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8353 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8354 | case TemplateName::DependentTemplate: { | 
|  | 8355 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8356 | auto QualifierOrErr = Import(DTN->getQualifier()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8357 | if (!QualifierOrErr) | 
|  | 8358 | return QualifierOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8359 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8360 | if (DTN->isIdentifier()) { | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8361 | return ToContext.getDependentTemplateName(*QualifierOrErr, | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8362 | Import(DTN->getIdentifier())); | 
|  | 8363 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8364 |  | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8365 | return ToContext.getDependentTemplateName(*QualifierOrErr, | 
|  | 8366 | DTN->getOperator()); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8367 | } | 
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8368 |  | 
|  | 8369 | case TemplateName::SubstTemplateTemplateParm: { | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8370 | SubstTemplateTemplateParmStorage *Subst = | 
|  | 8371 | From.getAsSubstTemplateTemplateParm(); | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8372 | ExpectedDecl ParamOrErr = Import(Subst->getParameter()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8373 | if (!ParamOrErr) | 
|  | 8374 | return ParamOrErr.takeError(); | 
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8375 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8376 | auto ReplacementOrErr = Import(Subst->getReplacement()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8377 | if (!ReplacementOrErr) | 
|  | 8378 | return ReplacementOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8379 |  | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8380 | return ToContext.getSubstTemplateTemplateParm( | 
|  | 8381 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ReplacementOrErr); | 
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8382 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8383 |  | 
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8384 | case TemplateName::SubstTemplateTemplateParmPack: { | 
|  | 8385 | SubstTemplateTemplateParmPackStorage *SubstPack | 
|  | 8386 | = From.getAsSubstTemplateTemplateParmPack(); | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8387 | ExpectedDecl ParamOrErr = Import(SubstPack->getParameterPack()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8388 | if (!ParamOrErr) | 
|  | 8389 | return ParamOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8390 |  | 
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8391 | ASTNodeImporter Importer(*this); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8392 | auto ArgPackOrErr = | 
|  | 8393 | Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); | 
|  | 8394 | if (!ArgPackOrErr) | 
|  | 8395 | return ArgPackOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8396 |  | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8397 | return ToContext.getSubstTemplateTemplateParmPack( | 
|  | 8398 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ArgPackOrErr); | 
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8399 | } | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8400 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8401 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8402 | llvm_unreachable("Invalid template name kind"); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8403 | } | 
|  | 8404 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8405 | Expected<SourceLocation> ASTImporter::Import(SourceLocation FromLoc) { | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8406 | if (FromLoc.isInvalid()) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8407 | return SourceLocation{}; | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8408 |  | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8409 | SourceManager &FromSM = FromContext.getSourceManager(); | 
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8410 | bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc); | 
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8411 |  | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8412 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8413 | Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8414 | if (!ToFileIDOrErr) | 
|  | 8415 | return ToFileIDOrErr.takeError(); | 
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8416 | SourceManager &ToSM = ToContext.getSourceManager(); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8417 | return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second); | 
|  | 8418 | } | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8419 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8420 | Expected<SourceRange> ASTImporter::Import(SourceRange FromRange) { | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8421 | SourceLocation ToBegin, ToEnd; | 
|  | 8422 | if (Error Err = importInto(ToBegin, FromRange.getBegin())) | 
|  | 8423 | return std::move(Err); | 
|  | 8424 | if (Error Err = importInto(ToEnd, FromRange.getEnd())) | 
|  | 8425 | return std::move(Err); | 
|  | 8426 |  | 
|  | 8427 | return SourceRange(ToBegin, ToEnd); | 
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8428 | } | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8429 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8430 | Expected<FileID> ASTImporter::Import(FileID FromID, bool IsBuiltin) { | 
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8431 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8432 | if (Pos != ImportedFileIDs.end()) | 
|  | 8433 | return Pos->second; | 
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8434 |  | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8435 | SourceManager &FromSM = FromContext.getSourceManager(); | 
|  | 8436 | SourceManager &ToSM = ToContext.getSourceManager(); | 
|  | 8437 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); | 
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8438 |  | 
|  | 8439 | // Map the FromID to the "to" source manager. | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8440 | FileID ToID; | 
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8441 | if (FromSLoc.isExpansion()) { | 
|  | 8442 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8443 | ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8444 | if (!ToSpLoc) | 
|  | 8445 | return ToSpLoc.takeError(); | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8446 | ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8447 | if (!ToExLocS) | 
|  | 8448 | return ToExLocS.takeError(); | 
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8449 | unsigned TokenLen = FromSM.getFileIDSize(FromID); | 
|  | 8450 | SourceLocation MLoc; | 
|  | 8451 | if (FromEx.isMacroArgExpansion()) { | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8452 | MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, TokenLen); | 
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8453 | } else { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8454 | if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd())) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8455 | MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, TokenLen, | 
|  | 8456 | FromEx.isExpansionTokenRange()); | 
|  | 8457 | else | 
|  | 8458 | return ToExLocE.takeError(); | 
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8459 | } | 
|  | 8460 | ToID = ToSM.getFileID(MLoc); | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8461 | } else { | 
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8462 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); | 
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8463 |  | 
|  | 8464 | if (!IsBuiltin) { | 
|  | 8465 | // Include location of this file. | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8466 | ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8467 | if (!ToIncludeLoc) | 
|  | 8468 | return ToIncludeLoc.takeError(); | 
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8469 |  | 
|  | 8470 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { | 
|  | 8471 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the | 
|  | 8472 | // disk again | 
|  | 8473 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather | 
|  | 8474 | // than mmap the files several times. | 
| Harlan Haskins | 8d323d1 | 2019-08-01 21:31:56 +0000 | [diff] [blame] | 8475 | auto Entry = | 
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8476 | ToFileManager.getFile(Cache->OrigEntry->getName()); | 
|  | 8477 | // FIXME: The filename may be a virtual name that does probably not | 
|  | 8478 | // point to a valid file and we get no Entry here. In this case try with | 
|  | 8479 | // the memory buffer below. | 
|  | 8480 | if (Entry) | 
| Harlan Haskins | 8d323d1 | 2019-08-01 21:31:56 +0000 | [diff] [blame] | 8481 | ToID = ToSM.createFileID(*Entry, *ToIncludeLoc, | 
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8482 | FromSLoc.getFile().getFileCharacteristic()); | 
|  | 8483 | } | 
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8484 | } | 
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8485 |  | 
|  | 8486 | if (ToID.isInvalid() || IsBuiltin) { | 
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8487 | // FIXME: We want to re-use the existing MemoryBuffer! | 
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8488 | bool Invalid = true; | 
| Duncan P. N. Exon Smith | f584819 | 2019-08-26 20:32:05 +0000 | [diff] [blame] | 8489 | const llvm::MemoryBuffer *FromBuf = | 
|  | 8490 | Cache->getBuffer(FromContext.getDiagnostics(), | 
|  | 8491 | FromSM.getFileManager(), SourceLocation{}, &Invalid); | 
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8492 | if (!FromBuf || Invalid) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8493 | // FIXME: Use a new error kind? | 
|  | 8494 | return llvm::make_error<ImportError>(ImportError::Unknown); | 
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8495 |  | 
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8496 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = | 
|  | 8497 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), | 
|  | 8498 | FromBuf->getBufferIdentifier()); | 
|  | 8499 | ToID = ToSM.createFileID(std::move(ToBuf), | 
|  | 8500 | FromSLoc.getFile().getFileCharacteristic()); | 
|  | 8501 | } | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8502 | } | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8503 |  | 
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8504 | assert(ToID.isValid() && "Unexpected invalid fileID was created."); | 
|  | 8505 |  | 
| Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 8506 | ImportedFileIDs[FromID] = ToID; | 
| Balazs Keri | d22f877 | 2019-07-24 10:16:37 +0000 | [diff] [blame] | 8507 |  | 
|  | 8508 | if (FileIDImportHandler) | 
|  | 8509 | FileIDImportHandler(ToID, FromID); | 
|  | 8510 |  | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8511 | return ToID; | 
|  | 8512 | } | 
|  | 8513 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8514 | Expected<CXXCtorInitializer *> ASTImporter::Import(CXXCtorInitializer *From) { | 
|  | 8515 | ExpectedExpr ToExprOrErr = Import(From->getInit()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8516 | if (!ToExprOrErr) | 
|  | 8517 | return ToExprOrErr.takeError(); | 
|  | 8518 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8519 | auto LParenLocOrErr = Import(From->getLParenLoc()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8520 | if (!LParenLocOrErr) | 
|  | 8521 | return LParenLocOrErr.takeError(); | 
|  | 8522 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8523 | auto RParenLocOrErr = Import(From->getRParenLoc()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8524 | if (!RParenLocOrErr) | 
|  | 8525 | return RParenLocOrErr.takeError(); | 
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8526 |  | 
|  | 8527 | if (From->isBaseInitializer()) { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8528 | auto ToTInfoOrErr = Import(From->getTypeSourceInfo()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8529 | if (!ToTInfoOrErr) | 
|  | 8530 | return ToTInfoOrErr.takeError(); | 
|  | 8531 |  | 
|  | 8532 | SourceLocation EllipsisLoc; | 
|  | 8533 | if (From->isPackExpansion()) | 
|  | 8534 | if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc())) | 
|  | 8535 | return std::move(Err); | 
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8536 |  | 
|  | 8537 | return new (ToContext) CXXCtorInitializer( | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8538 | ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr, | 
|  | 8539 | *ToExprOrErr, *RParenLocOrErr, EllipsisLoc); | 
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8540 | } else if (From->isMemberInitializer()) { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8541 | ExpectedDecl ToFieldOrErr = Import(From->getMember()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8542 | if (!ToFieldOrErr) | 
|  | 8543 | return ToFieldOrErr.takeError(); | 
|  | 8544 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8545 | auto MemberLocOrErr = Import(From->getMemberLocation()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8546 | if (!MemberLocOrErr) | 
|  | 8547 | return MemberLocOrErr.takeError(); | 
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8548 |  | 
|  | 8549 | return new (ToContext) CXXCtorInitializer( | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8550 | ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr, | 
|  | 8551 | *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); | 
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8552 | } else if (From->isIndirectMemberInitializer()) { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8553 | ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8554 | if (!ToIFieldOrErr) | 
|  | 8555 | return ToIFieldOrErr.takeError(); | 
|  | 8556 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8557 | auto MemberLocOrErr = Import(From->getMemberLocation()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8558 | if (!MemberLocOrErr) | 
|  | 8559 | return MemberLocOrErr.takeError(); | 
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8560 |  | 
|  | 8561 | return new (ToContext) CXXCtorInitializer( | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8562 | ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr), | 
|  | 8563 | *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); | 
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8564 | } else if (From->isDelegatingInitializer()) { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8565 | auto ToTInfoOrErr = Import(From->getTypeSourceInfo()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8566 | if (!ToTInfoOrErr) | 
|  | 8567 | return ToTInfoOrErr.takeError(); | 
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8568 |  | 
|  | 8569 | return new (ToContext) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8570 | CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr, | 
|  | 8571 | *ToExprOrErr, *RParenLocOrErr); | 
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8572 | } else { | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8573 | // FIXME: assert? | 
|  | 8574 | return make_error<ImportError>(); | 
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8575 | } | 
| Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 8576 | } | 
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8577 |  | 
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8578 | Expected<CXXBaseSpecifier *> | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8579 | ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8580 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); | 
|  | 8581 | if (Pos != ImportedCXXBaseSpecifiers.end()) | 
|  | 8582 | return Pos->second; | 
|  | 8583 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8584 | Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8585 | if (!ToSourceRange) | 
|  | 8586 | return ToSourceRange.takeError(); | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8587 | Expected<TypeSourceInfo *> ToTSI = Import(BaseSpec->getTypeSourceInfo()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8588 | if (!ToTSI) | 
|  | 8589 | return ToTSI.takeError(); | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8590 | ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8591 | if (!ToEllipsisLoc) | 
|  | 8592 | return ToEllipsisLoc.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8593 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8594 | *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), | 
|  | 8595 | BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8596 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; | 
|  | 8597 | return Imported; | 
|  | 8598 | } | 
|  | 8599 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8600 | Error ASTImporter::ImportDefinition(Decl *From) { | 
|  | 8601 | ExpectedDecl ToOrErr = Import(From); | 
|  | 8602 | if (!ToOrErr) | 
|  | 8603 | return ToOrErr.takeError(); | 
|  | 8604 | Decl *To = *ToOrErr; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8605 |  | 
| Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8606 | auto *FromDC = cast<DeclContext>(From); | 
|  | 8607 | ASTNodeImporter Importer(*this); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8608 |  | 
| Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8609 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { | 
|  | 8610 | if (!ToRecord->getDefinition()) { | 
|  | 8611 | return Importer.ImportDefinition( | 
|  | 8612 | cast<RecordDecl>(FromDC), ToRecord, | 
|  | 8613 | ASTNodeImporter::IDK_Everything); | 
| Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 8614 | } | 
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8615 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8616 |  | 
| Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8617 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { | 
|  | 8618 | if (!ToEnum->getDefinition()) { | 
|  | 8619 | return Importer.ImportDefinition( | 
|  | 8620 | cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything); | 
|  | 8621 | } | 
|  | 8622 | } | 
|  | 8623 |  | 
|  | 8624 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { | 
|  | 8625 | if (!ToIFace->getDefinition()) { | 
|  | 8626 | return Importer.ImportDefinition( | 
|  | 8627 | cast<ObjCInterfaceDecl>(FromDC), ToIFace, | 
|  | 8628 | ASTNodeImporter::IDK_Everything); | 
|  | 8629 | } | 
|  | 8630 | } | 
|  | 8631 |  | 
|  | 8632 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { | 
|  | 8633 | if (!ToProto->getDefinition()) { | 
|  | 8634 | return Importer.ImportDefinition( | 
|  | 8635 | cast<ObjCProtocolDecl>(FromDC), ToProto, | 
|  | 8636 | ASTNodeImporter::IDK_Everything); | 
|  | 8637 | } | 
|  | 8638 | } | 
|  | 8639 |  | 
|  | 8640 | return Importer.ImportDeclContext(FromDC, true); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8641 | } | 
|  | 8642 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8643 | Expected<DeclarationName> ASTImporter::Import(DeclarationName FromName) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8644 | if (!FromName) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8645 | return DeclarationName{}; | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8646 |  | 
|  | 8647 | switch (FromName.getNameKind()) { | 
|  | 8648 | case DeclarationName::Identifier: | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8649 | return DeclarationName(Import(FromName.getAsIdentifierInfo())); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8650 |  | 
|  | 8651 | case DeclarationName::ObjCZeroArgSelector: | 
|  | 8652 | case DeclarationName::ObjCOneArgSelector: | 
|  | 8653 | case DeclarationName::ObjCMultiArgSelector: | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8654 | if (auto ToSelOrErr = Import(FromName.getObjCSelector())) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8655 | return DeclarationName(*ToSelOrErr); | 
|  | 8656 | else | 
|  | 8657 | return ToSelOrErr.takeError(); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8658 |  | 
|  | 8659 | case DeclarationName::CXXConstructorName: { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8660 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8661 | return ToContext.DeclarationNames.getCXXConstructorName( | 
|  | 8662 | ToContext.getCanonicalType(*ToTyOrErr)); | 
|  | 8663 | else | 
|  | 8664 | return ToTyOrErr.takeError(); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8665 | } | 
|  | 8666 |  | 
|  | 8667 | case DeclarationName::CXXDestructorName: { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8668 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8669 | return ToContext.DeclarationNames.getCXXDestructorName( | 
|  | 8670 | ToContext.getCanonicalType(*ToTyOrErr)); | 
|  | 8671 | else | 
|  | 8672 | return ToTyOrErr.takeError(); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8673 | } | 
|  | 8674 |  | 
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8675 | case DeclarationName::CXXDeductionGuideName: { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8676 | if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate())) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8677 | return ToContext.DeclarationNames.getCXXDeductionGuideName( | 
|  | 8678 | cast<TemplateDecl>(*ToTemplateOrErr)); | 
|  | 8679 | else | 
|  | 8680 | return ToTemplateOrErr.takeError(); | 
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8681 | } | 
|  | 8682 |  | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8683 | case DeclarationName::CXXConversionFunctionName: { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8684 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8685 | return ToContext.DeclarationNames.getCXXConversionFunctionName( | 
|  | 8686 | ToContext.getCanonicalType(*ToTyOrErr)); | 
|  | 8687 | else | 
|  | 8688 | return ToTyOrErr.takeError(); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8689 | } | 
|  | 8690 |  | 
|  | 8691 | case DeclarationName::CXXOperatorName: | 
|  | 8692 | return ToContext.DeclarationNames.getCXXOperatorName( | 
|  | 8693 | FromName.getCXXOverloadedOperator()); | 
|  | 8694 |  | 
|  | 8695 | case DeclarationName::CXXLiteralOperatorName: | 
|  | 8696 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8697 | Import(FromName.getCXXLiteralIdentifier())); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8698 |  | 
|  | 8699 | case DeclarationName::CXXUsingDirective: | 
|  | 8700 | // FIXME: STATICS! | 
|  | 8701 | return DeclarationName::getUsingDirectiveName(); | 
|  | 8702 | } | 
|  | 8703 |  | 
| David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 8704 | llvm_unreachable("Invalid DeclarationName Kind!"); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8705 | } | 
|  | 8706 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8707 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8708 | if (!FromId) | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8709 | return nullptr; | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8710 |  | 
| Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 8711 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); | 
|  | 8712 |  | 
|  | 8713 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) | 
|  | 8714 | ToId->setBuiltinID(FromId->getBuiltinID()); | 
|  | 8715 |  | 
|  | 8716 | return ToId; | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8717 | } | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8718 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8719 | Expected<Selector> ASTImporter::Import(Selector FromSel) { | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8720 | if (FromSel.isNull()) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8721 | return Selector{}; | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8722 |  | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 8723 | SmallVector<IdentifierInfo *, 4> Idents; | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8724 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); | 
|  | 8725 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) | 
|  | 8726 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); | 
|  | 8727 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); | 
|  | 8728 | } | 
|  | 8729 |  | 
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 8730 | Expected<DeclarationName> ASTImporter::HandleNameConflict(DeclarationName Name, | 
|  | 8731 | DeclContext *DC, | 
|  | 8732 | unsigned IDNS, | 
|  | 8733 | NamedDecl **Decls, | 
|  | 8734 | unsigned NumDecls) { | 
|  | 8735 | if (ODRHandling == ODRHandlingType::Conservative) | 
|  | 8736 | // Report error at any name conflict. | 
|  | 8737 | return make_error<ImportError>(ImportError::NameConflict); | 
|  | 8738 | else | 
|  | 8739 | // Allow to create the new Decl with the same name. | 
|  | 8740 | return Name; | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8741 | } | 
|  | 8742 |  | 
|  | 8743 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { | 
| Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8744 | if (LastDiagFromFrom) | 
|  | 8745 | ToContext.getDiagnostics().notePriorDiagnosticFrom( | 
|  | 8746 | FromContext.getDiagnostics()); | 
|  | 8747 | LastDiagFromFrom = false; | 
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8748 | return ToContext.getDiagnostics().Report(Loc, DiagID); | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8749 | } | 
|  | 8750 |  | 
|  | 8751 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { | 
| Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8752 | if (!LastDiagFromFrom) | 
|  | 8753 | FromContext.getDiagnostics().notePriorDiagnosticFrom( | 
|  | 8754 | ToContext.getDiagnostics()); | 
|  | 8755 | LastDiagFromFrom = true; | 
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8756 | return FromContext.getDiagnostics().Report(Loc, DiagID); | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8757 | } | 
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8758 |  | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8759 | void ASTImporter::CompleteDecl (Decl *D) { | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8760 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8761 | if (!ID->getDefinition()) | 
|  | 8762 | ID->startDefinition(); | 
|  | 8763 | } | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8764 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8765 | if (!PD->getDefinition()) | 
|  | 8766 | PD->startDefinition(); | 
|  | 8767 | } | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8768 | else if (auto *TD = dyn_cast<TagDecl>(D)) { | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8769 | if (!TD->getDefinition() && !TD->isBeingDefined()) { | 
|  | 8770 | TD->startDefinition(); | 
|  | 8771 | TD->setCompleteDefinition(true); | 
|  | 8772 | } | 
|  | 8773 | } | 
|  | 8774 | else { | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8775 | assert(0 && "CompleteDecl called on a Decl that can't be completed"); | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8776 | } | 
|  | 8777 | } | 
|  | 8778 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8779 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { | 
|  | 8780 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); | 
|  | 8781 | assert((Pos == ImportedDecls.end() || Pos->second == To) && | 
|  | 8782 | "Try to import an already imported Decl"); | 
|  | 8783 | if (Pos != ImportedDecls.end()) | 
|  | 8784 | return Pos->second; | 
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8785 | ImportedDecls[From] = To; | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 8786 | // This mapping should be maintained only in this function. Therefore do not | 
|  | 8787 | // check for additional consistency. | 
|  | 8788 | ImportedFromDecls[To] = From; | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8789 | AddToLookupTable(To); | 
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8790 | return To; | 
| Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 8791 | } | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8792 |  | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8793 | llvm::Optional<ImportError> | 
|  | 8794 | ASTImporter::getImportDeclErrorIfAny(Decl *FromD) const { | 
|  | 8795 | auto Pos = ImportDeclErrors.find(FromD); | 
|  | 8796 | if (Pos != ImportDeclErrors.end()) | 
|  | 8797 | return Pos->second; | 
|  | 8798 | else | 
|  | 8799 | return Optional<ImportError>(); | 
|  | 8800 | } | 
|  | 8801 |  | 
|  | 8802 | void ASTImporter::setImportDeclError(Decl *From, ImportError Error) { | 
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8803 | auto InsertRes = ImportDeclErrors.insert({From, Error}); | 
| Benjamin Kramer | 4f76936 | 2019-07-01 14:33:26 +0000 | [diff] [blame] | 8804 | (void)InsertRes; | 
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8805 | // Either we set the error for the first time, or we already had set one and | 
|  | 8806 | // now we want to set the same error. | 
|  | 8807 | assert(InsertRes.second || InsertRes.first->second.Error == Error.Error); | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8808 | } | 
|  | 8809 |  | 
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8810 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, | 
|  | 8811 | bool Complain) { | 
| Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 8812 | llvm::DenseMap<const Type *, const Type *>::iterator Pos = | 
|  | 8813 | ImportedTypes.find(From.getTypePtr()); | 
|  | 8814 | if (Pos != ImportedTypes.end()) { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8815 | if (ExpectedType ToFromOrErr = Import(From)) { | 
| Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 8816 | if (ToContext.hasSameType(*ToFromOrErr, To)) | 
|  | 8817 | return true; | 
|  | 8818 | } else { | 
|  | 8819 | llvm::consumeError(ToFromOrErr.takeError()); | 
|  | 8820 | } | 
|  | 8821 | } | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 8822 |  | 
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8823 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8824 | getStructuralEquivalenceKind(*this), false, | 
|  | 8825 | Complain); | 
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 8826 | return Ctx.IsEquivalent(From, To); | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8827 | } |