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 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the ASTImporter class which imports AST nodes from one |
| 11 | // context into another context. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 14 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTImporter.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" |
| 47 | #include "clang/Basic/ExceptionSpecificationType.h" |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 48 | #include "clang/Basic/FileManager.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 49 | #include "clang/Basic/IdentifierTable.h" |
| 50 | #include "clang/Basic/LLVM.h" |
| 51 | #include "clang/Basic/LangOptions.h" |
| 52 | #include "clang/Basic/SourceLocation.h" |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 53 | #include "clang/Basic/SourceManager.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 54 | #include "clang/Basic/Specifiers.h" |
| 55 | #include "llvm/ADT/APSInt.h" |
| 56 | #include "llvm/ADT/ArrayRef.h" |
| 57 | #include "llvm/ADT/DenseMap.h" |
| 58 | #include "llvm/ADT/None.h" |
| 59 | #include "llvm/ADT/Optional.h" |
| 60 | #include "llvm/ADT/STLExtras.h" |
| 61 | #include "llvm/ADT/SmallVector.h" |
| 62 | #include "llvm/Support/Casting.h" |
| 63 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 64 | #include "llvm/Support/MemoryBuffer.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 65 | #include <algorithm> |
| 66 | #include <cassert> |
| 67 | #include <cstddef> |
| 68 | #include <memory> |
| 69 | #include <type_traits> |
| 70 | #include <utility> |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 71 | |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 72 | namespace clang { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 73 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 74 | using llvm::make_error; |
| 75 | using llvm::Error; |
| 76 | using llvm::Expected; |
| 77 | using ExpectedType = llvm::Expected<QualType>; |
| 78 | using ExpectedStmt = llvm::Expected<Stmt *>; |
| 79 | using ExpectedExpr = llvm::Expected<Expr *>; |
| 80 | using ExpectedDecl = llvm::Expected<Decl *>; |
| 81 | using ExpectedSLoc = llvm::Expected<SourceLocation>; |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 82 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 83 | std::string ImportError::toString() const { |
| 84 | // FIXME: Improve error texts. |
| 85 | switch (Error) { |
| 86 | case NameConflict: |
| 87 | return "NameConflict"; |
| 88 | case UnsupportedConstruct: |
| 89 | return "UnsupportedConstruct"; |
| 90 | case Unknown: |
| 91 | return "Unknown error"; |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 92 | } |
Balazs Keri | 2a13d66 | 2018-10-19 15:16:51 +0000 | [diff] [blame] | 93 | llvm_unreachable("Invalid error code."); |
| 94 | return "Invalid error code."; |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 97 | void ImportError::log(raw_ostream &OS) const { |
| 98 | OS << toString(); |
| 99 | } |
| 100 | |
| 101 | std::error_code ImportError::convertToErrorCode() const { |
| 102 | llvm_unreachable("Function not implemented."); |
| 103 | } |
| 104 | |
| 105 | char ImportError::ID; |
| 106 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 107 | template <class T> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 108 | SmallVector<Decl *, 2> |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 109 | getCanonicalForwardRedeclChain(Redeclarable<T>* D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 110 | SmallVector<Decl *, 2> Redecls; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 111 | for (auto *R : D->getFirstDecl()->redecls()) { |
| 112 | if (R != D->getFirstDecl()) |
| 113 | Redecls.push_back(R); |
| 114 | } |
| 115 | Redecls.push_back(D->getFirstDecl()); |
| 116 | std::reverse(Redecls.begin(), Redecls.end()); |
| 117 | return Redecls; |
| 118 | } |
| 119 | |
| 120 | SmallVector<Decl*, 2> getCanonicalForwardRedeclChain(Decl* D) { |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 121 | if (auto *FD = dyn_cast<FunctionDecl>(D)) |
| 122 | return getCanonicalForwardRedeclChain<FunctionDecl>(FD); |
| 123 | if (auto *VD = dyn_cast<VarDecl>(D)) |
| 124 | return getCanonicalForwardRedeclChain<VarDecl>(VD); |
| 125 | llvm_unreachable("Bad declaration kind"); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 126 | } |
| 127 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 128 | void updateFlags(const Decl *From, Decl *To) { |
| 129 | // Check if some flags or attrs are new in 'From' and copy into 'To'. |
| 130 | // FIXME: Other flags or attrs? |
| 131 | if (From->isUsed(false) && !To->isUsed(false)) |
| 132 | To->setIsUsed(); |
| 133 | } |
| 134 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 135 | Optional<unsigned> ASTImporter::getFieldIndex(Decl *F) { |
| 136 | assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) && |
| 137 | "Try to get field index for non-field."); |
| 138 | |
| 139 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); |
| 140 | if (!Owner) |
| 141 | return None; |
| 142 | |
| 143 | unsigned Index = 0; |
| 144 | for (const auto *D : Owner->decls()) { |
| 145 | if (D == F) |
| 146 | return Index; |
| 147 | |
| 148 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) |
| 149 | ++Index; |
| 150 | } |
| 151 | |
| 152 | llvm_unreachable("Field was not found in its parent context."); |
| 153 | |
| 154 | return None; |
| 155 | } |
| 156 | |
| 157 | // FIXME: Temporary until every import returns Expected. |
| 158 | template <> |
| 159 | LLVM_NODISCARD Error |
| 160 | ASTImporter::importInto(SourceLocation &To, const SourceLocation &From) { |
| 161 | To = Import(From); |
| 162 | if (From.isValid() && To.isInvalid()) |
| 163 | return llvm::make_error<ImportError>(); |
| 164 | return Error::success(); |
| 165 | } |
| 166 | // FIXME: Temporary until every import returns Expected. |
| 167 | template <> |
| 168 | LLVM_NODISCARD Error |
| 169 | ASTImporter::importInto(QualType &To, const QualType &From) { |
| 170 | To = Import(From); |
| 171 | if (!From.isNull() && To.isNull()) |
| 172 | return llvm::make_error<ImportError>(); |
| 173 | return Error::success(); |
| 174 | } |
| 175 | |
| 176 | class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>, |
| 177 | public DeclVisitor<ASTNodeImporter, ExpectedDecl>, |
| 178 | public StmtVisitor<ASTNodeImporter, ExpectedStmt> { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 179 | ASTImporter &Importer; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 180 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 181 | // Use this instead of Importer.importInto . |
| 182 | template <typename ImportT> |
| 183 | LLVM_NODISCARD Error importInto(ImportT &To, const ImportT &From) { |
| 184 | return Importer.importInto(To, From); |
| 185 | } |
| 186 | |
| 187 | // Use this to import pointers of specific type. |
| 188 | template <typename ImportT> |
| 189 | LLVM_NODISCARD Error importInto(ImportT *&To, ImportT *From) { |
| 190 | auto ToI = Importer.Import(From); |
| 191 | if (!ToI && From) |
| 192 | return make_error<ImportError>(); |
| 193 | To = cast_or_null<ImportT>(ToI); |
| 194 | return Error::success(); |
| 195 | // FIXME: This should be the final code. |
| 196 | //auto ToOrErr = Importer.Import(From); |
| 197 | //if (ToOrErr) { |
| 198 | // To = cast_or_null<ImportT>(*ToOrErr); |
| 199 | //} |
| 200 | //return ToOrErr.takeError(); |
| 201 | } |
| 202 | |
| 203 | // Call the import function of ASTImporter for a baseclass of type `T` and |
| 204 | // cast the return value to `T`. |
| 205 | template <typename T> |
| 206 | Expected<T *> import(T *From) { |
| 207 | auto *To = Importer.Import(From); |
| 208 | if (!To && From) |
| 209 | return make_error<ImportError>(); |
| 210 | return cast_or_null<T>(To); |
| 211 | // FIXME: This should be the final code. |
| 212 | //auto ToOrErr = Importer.Import(From); |
| 213 | //if (!ToOrErr) |
| 214 | // return ToOrErr.takeError(); |
| 215 | //return cast_or_null<T>(*ToOrErr); |
| 216 | } |
| 217 | |
| 218 | template <typename T> |
| 219 | Expected<T *> import(const T *From) { |
| 220 | return import(const_cast<T *>(From)); |
| 221 | } |
| 222 | |
| 223 | // Call the import function of ASTImporter for type `T`. |
| 224 | template <typename T> |
| 225 | Expected<T> import(const T &From) { |
| 226 | T To = Importer.Import(From); |
| 227 | T DefaultT; |
| 228 | if (To == DefaultT && !(From == DefaultT)) |
| 229 | return make_error<ImportError>(); |
| 230 | return To; |
| 231 | // FIXME: This should be the final code. |
| 232 | //return Importer.Import(From); |
| 233 | } |
| 234 | |
| 235 | template <class T> |
| 236 | Expected<std::tuple<T>> |
| 237 | importSeq(const T &From) { |
| 238 | Expected<T> ToOrErr = import(From); |
| 239 | if (!ToOrErr) |
| 240 | return ToOrErr.takeError(); |
| 241 | return std::make_tuple<T>(std::move(*ToOrErr)); |
| 242 | } |
| 243 | |
| 244 | // Import multiple objects with a single function call. |
| 245 | // This should work for every type for which a variant of `import` exists. |
| 246 | // The arguments are processed from left to right and import is stopped on |
| 247 | // first error. |
| 248 | template <class THead, class... TTail> |
| 249 | Expected<std::tuple<THead, TTail...>> |
| 250 | importSeq(const THead &FromHead, const TTail &...FromTail) { |
| 251 | Expected<std::tuple<THead>> ToHeadOrErr = importSeq(FromHead); |
| 252 | if (!ToHeadOrErr) |
| 253 | return ToHeadOrErr.takeError(); |
| 254 | Expected<std::tuple<TTail...>> ToTailOrErr = importSeq(FromTail...); |
| 255 | if (!ToTailOrErr) |
| 256 | return ToTailOrErr.takeError(); |
| 257 | return std::tuple_cat(*ToHeadOrErr, *ToTailOrErr); |
| 258 | } |
| 259 | |
| 260 | // Wrapper for an overload set. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 261 | template <typename ToDeclT> struct CallOverloadedCreateFun { |
| 262 | template <typename... Args> |
| 263 | auto operator()(Args &&... args) |
| 264 | -> decltype(ToDeclT::Create(std::forward<Args>(args)...)) { |
| 265 | return ToDeclT::Create(std::forward<Args>(args)...); |
| 266 | } |
| 267 | }; |
| 268 | |
| 269 | // Always use these functions to create a Decl during import. There are |
| 270 | // certain tasks which must be done after the Decl was created, e.g. we |
| 271 | // must immediately register that as an imported Decl. The parameter `ToD` |
| 272 | // will be set to the newly created Decl or if had been imported before |
| 273 | // then to the already imported Decl. Returns a bool value set to true if |
| 274 | // the `FromD` had been imported before. |
| 275 | template <typename ToDeclT, typename FromDeclT, typename... Args> |
| 276 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, |
| 277 | Args &&... args) { |
| 278 | // There may be several overloads of ToDeclT::Create. We must make sure |
| 279 | // to call the one which would be chosen by the arguments, thus we use a |
| 280 | // wrapper for the overload set. |
| 281 | CallOverloadedCreateFun<ToDeclT> OC; |
| 282 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, |
| 283 | std::forward<Args>(args)...); |
| 284 | } |
| 285 | // Use this overload if a special Type is needed to be created. E.g if we |
| 286 | // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl` |
| 287 | // then: |
| 288 | // TypedefNameDecl *ToTypedef; |
| 289 | // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...); |
| 290 | template <typename NewDeclT, typename ToDeclT, typename FromDeclT, |
| 291 | typename... Args> |
| 292 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, |
| 293 | Args &&... args) { |
| 294 | CallOverloadedCreateFun<NewDeclT> OC; |
| 295 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, |
| 296 | std::forward<Args>(args)...); |
| 297 | } |
| 298 | // Use this version if a special create function must be |
| 299 | // used, e.g. CXXRecordDecl::CreateLambda . |
| 300 | template <typename ToDeclT, typename CreateFunT, typename FromDeclT, |
| 301 | typename... Args> |
| 302 | LLVM_NODISCARD bool |
| 303 | GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun, |
| 304 | FromDeclT *FromD, Args &&... args) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 305 | // FIXME: This code is needed later. |
| 306 | //if (Importer.getImportDeclErrorIfAny(FromD)) { |
| 307 | // ToD = nullptr; |
| 308 | // return true; // Already imported but with error. |
| 309 | //} |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 310 | ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD)); |
| 311 | if (ToD) |
| 312 | return true; // Already imported. |
| 313 | ToD = CreateFun(std::forward<Args>(args)...); |
| 314 | InitializeImportedDecl(FromD, ToD); |
| 315 | return false; // A new Decl is created. |
| 316 | } |
| 317 | |
| 318 | void InitializeImportedDecl(Decl *FromD, Decl *ToD) { |
| 319 | Importer.MapImported(FromD, ToD); |
| 320 | ToD->IdentifierNamespace = FromD->IdentifierNamespace; |
| 321 | if (FromD->hasAttrs()) |
| 322 | for (const Attr *FromAttr : FromD->getAttrs()) |
| 323 | ToD->addAttr(Importer.Import(FromAttr)); |
| 324 | if (FromD->isUsed()) |
| 325 | ToD->setIsUsed(); |
| 326 | if (FromD->isImplicit()) |
| 327 | ToD->setImplicit(); |
| 328 | } |
| 329 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 330 | public: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 331 | explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {} |
Gabor Marton | 344b099 | 2018-05-16 11:48:11 +0000 | [diff] [blame] | 332 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 333 | using TypeVisitor<ASTNodeImporter, ExpectedType>::Visit; |
| 334 | using DeclVisitor<ASTNodeImporter, ExpectedDecl>::Visit; |
| 335 | using StmtVisitor<ASTNodeImporter, ExpectedStmt>::Visit; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 336 | |
| 337 | // Importing types |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 338 | ExpectedType VisitType(const Type *T); |
| 339 | ExpectedType VisitAtomicType(const AtomicType *T); |
| 340 | ExpectedType VisitBuiltinType(const BuiltinType *T); |
| 341 | ExpectedType VisitDecayedType(const DecayedType *T); |
| 342 | ExpectedType VisitComplexType(const ComplexType *T); |
| 343 | ExpectedType VisitPointerType(const PointerType *T); |
| 344 | ExpectedType VisitBlockPointerType(const BlockPointerType *T); |
| 345 | ExpectedType VisitLValueReferenceType(const LValueReferenceType *T); |
| 346 | ExpectedType VisitRValueReferenceType(const RValueReferenceType *T); |
| 347 | ExpectedType VisitMemberPointerType(const MemberPointerType *T); |
| 348 | ExpectedType VisitConstantArrayType(const ConstantArrayType *T); |
| 349 | ExpectedType VisitIncompleteArrayType(const IncompleteArrayType *T); |
| 350 | ExpectedType VisitVariableArrayType(const VariableArrayType *T); |
| 351 | ExpectedType VisitDependentSizedArrayType(const DependentSizedArrayType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 352 | // FIXME: DependentSizedExtVectorType |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 353 | ExpectedType VisitVectorType(const VectorType *T); |
| 354 | ExpectedType VisitExtVectorType(const ExtVectorType *T); |
| 355 | ExpectedType VisitFunctionNoProtoType(const FunctionNoProtoType *T); |
| 356 | ExpectedType VisitFunctionProtoType(const FunctionProtoType *T); |
| 357 | ExpectedType VisitUnresolvedUsingType(const UnresolvedUsingType *T); |
| 358 | ExpectedType VisitParenType(const ParenType *T); |
| 359 | ExpectedType VisitTypedefType(const TypedefType *T); |
| 360 | ExpectedType VisitTypeOfExprType(const TypeOfExprType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 361 | // FIXME: DependentTypeOfExprType |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 362 | ExpectedType VisitTypeOfType(const TypeOfType *T); |
| 363 | ExpectedType VisitDecltypeType(const DecltypeType *T); |
| 364 | ExpectedType VisitUnaryTransformType(const UnaryTransformType *T); |
| 365 | ExpectedType VisitAutoType(const AutoType *T); |
| 366 | ExpectedType VisitInjectedClassNameType(const InjectedClassNameType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 367 | // FIXME: DependentDecltypeType |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 368 | ExpectedType VisitRecordType(const RecordType *T); |
| 369 | ExpectedType VisitEnumType(const EnumType *T); |
| 370 | ExpectedType VisitAttributedType(const AttributedType *T); |
| 371 | ExpectedType VisitTemplateTypeParmType(const TemplateTypeParmType *T); |
| 372 | ExpectedType VisitSubstTemplateTypeParmType( |
| 373 | const SubstTemplateTypeParmType *T); |
| 374 | ExpectedType VisitTemplateSpecializationType( |
| 375 | const TemplateSpecializationType *T); |
| 376 | ExpectedType VisitElaboratedType(const ElaboratedType *T); |
| 377 | ExpectedType VisitDependentNameType(const DependentNameType *T); |
| 378 | ExpectedType VisitPackExpansionType(const PackExpansionType *T); |
| 379 | ExpectedType VisitDependentTemplateSpecializationType( |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 380 | const DependentTemplateSpecializationType *T); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 381 | ExpectedType VisitObjCInterfaceType(const ObjCInterfaceType *T); |
| 382 | ExpectedType VisitObjCObjectType(const ObjCObjectType *T); |
| 383 | ExpectedType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); |
Rafael Stahl | df55620 | 2018-05-29 08:12:15 +0000 | [diff] [blame] | 384 | |
| 385 | // Importing declarations |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 386 | Error ImportDeclParts( |
| 387 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, |
| 388 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc); |
| 389 | Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr); |
| 390 | Error ImportDeclarationNameLoc( |
| 391 | const DeclarationNameInfo &From, DeclarationNameInfo &To); |
| 392 | Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); |
| 393 | Error ImportDeclContext( |
| 394 | Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC); |
| 395 | Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 396 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 397 | Expected<CXXCastPath> ImportCastPath(CastExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 398 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 399 | using Designator = DesignatedInitExpr::Designator; |
| 400 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 401 | /// What we should import from the definition. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 402 | enum ImportDefinitionKind { |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 403 | /// Import the default subset of the definition, which might be |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 404 | /// nothing (if minimal import is set) or might be everything (if minimal |
| 405 | /// import is not set). |
| 406 | IDK_Default, |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 407 | /// Import everything. |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 408 | IDK_Everything, |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 409 | /// Import only the bare bones needed to establish a valid |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 410 | /// DeclContext. |
| 411 | IDK_Basic |
| 412 | }; |
| 413 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 414 | bool shouldForceImportDeclContext(ImportDefinitionKind IDK) { |
| 415 | return IDK == IDK_Everything || |
| 416 | (IDK == IDK_Default && !Importer.isMinimalImport()); |
| 417 | } |
| 418 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 419 | Error ImportInitializer(VarDecl *From, VarDecl *To); |
| 420 | Error ImportDefinition( |
| 421 | RecordDecl *From, RecordDecl *To, |
| 422 | ImportDefinitionKind Kind = IDK_Default); |
| 423 | Error ImportDefinition( |
| 424 | EnumDecl *From, EnumDecl *To, |
| 425 | ImportDefinitionKind Kind = IDK_Default); |
| 426 | Error ImportDefinition( |
| 427 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, |
| 428 | ImportDefinitionKind Kind = IDK_Default); |
| 429 | Error ImportDefinition( |
| 430 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, |
| 431 | ImportDefinitionKind Kind = IDK_Default); |
| 432 | Expected<TemplateParameterList *> ImportTemplateParameterList( |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 433 | TemplateParameterList *Params); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 434 | Error ImportTemplateArguments( |
| 435 | const TemplateArgument *FromArgs, unsigned NumFromArgs, |
| 436 | SmallVectorImpl<TemplateArgument> &ToArgs); |
| 437 | Expected<TemplateArgument> |
| 438 | ImportTemplateArgument(const TemplateArgument &From); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 439 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 440 | template <typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 441 | Error ImportTemplateArgumentListInfo( |
| 442 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 443 | |
| 444 | template<typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 445 | Error ImportTemplateArgumentListInfo( |
| 446 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 447 | const InContainerTy &Container, TemplateArgumentListInfo &Result); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 448 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 449 | using TemplateArgsTy = SmallVector<TemplateArgument, 8>; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 450 | using FunctionTemplateAndArgsTy = |
| 451 | std::tuple<FunctionTemplateDecl *, TemplateArgsTy>; |
| 452 | Expected<FunctionTemplateAndArgsTy> |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 453 | ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 454 | FunctionDecl *FromFD); |
| 455 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 456 | Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 457 | |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 458 | bool IsStructuralMatch(Decl *From, Decl *To, bool Complain); |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 459 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, |
| 460 | bool Complain = true); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 461 | bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 462 | bool Complain = true); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 463 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 464 | bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 465 | bool IsStructuralMatch(FunctionTemplateDecl *From, |
| 466 | FunctionTemplateDecl *To); |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 467 | bool IsStructuralMatch(FunctionDecl *From, FunctionDecl *To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 468 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 469 | bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 470 | ExpectedDecl VisitDecl(Decl *D); |
| 471 | ExpectedDecl VisitImportDecl(ImportDecl *D); |
| 472 | ExpectedDecl VisitEmptyDecl(EmptyDecl *D); |
| 473 | ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D); |
| 474 | ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D); |
| 475 | ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D); |
| 476 | ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D); |
| 477 | ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
| 478 | ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); |
| 479 | ExpectedDecl VisitTypedefDecl(TypedefDecl *D); |
| 480 | ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D); |
| 481 | ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); |
| 482 | ExpectedDecl VisitLabelDecl(LabelDecl *D); |
| 483 | ExpectedDecl VisitEnumDecl(EnumDecl *D); |
| 484 | ExpectedDecl VisitRecordDecl(RecordDecl *D); |
| 485 | ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D); |
| 486 | ExpectedDecl VisitFunctionDecl(FunctionDecl *D); |
| 487 | ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D); |
| 488 | ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 489 | ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 490 | ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D); |
| 491 | ExpectedDecl VisitFieldDecl(FieldDecl *D); |
| 492 | ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D); |
| 493 | ExpectedDecl VisitFriendDecl(FriendDecl *D); |
| 494 | ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D); |
| 495 | ExpectedDecl VisitVarDecl(VarDecl *D); |
| 496 | ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D); |
| 497 | ExpectedDecl VisitParmVarDecl(ParmVarDecl *D); |
| 498 | ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D); |
| 499 | ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
| 500 | ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| 501 | ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| 502 | ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D); |
| 503 | ExpectedDecl VisitUsingDecl(UsingDecl *D); |
| 504 | ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D); |
| 505 | ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 506 | ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
| 507 | ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 508 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 509 | Expected<ObjCTypeParamList *> |
| 510 | ImportObjCTypeParamList(ObjCTypeParamList *list); |
| 511 | |
| 512 | ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
| 513 | ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| 514 | ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| 515 | ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| 516 | ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
| 517 | ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
| 518 | ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 519 | ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
| 520 | ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D); |
| 521 | ExpectedDecl VisitClassTemplateSpecializationDecl( |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 522 | ClassTemplateSpecializationDecl *D); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 523 | ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D); |
| 524 | ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); |
| 525 | ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 526 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 527 | // Importing statements |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 528 | ExpectedStmt VisitStmt(Stmt *S); |
| 529 | ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S); |
| 530 | ExpectedStmt VisitDeclStmt(DeclStmt *S); |
| 531 | ExpectedStmt VisitNullStmt(NullStmt *S); |
| 532 | ExpectedStmt VisitCompoundStmt(CompoundStmt *S); |
| 533 | ExpectedStmt VisitCaseStmt(CaseStmt *S); |
| 534 | ExpectedStmt VisitDefaultStmt(DefaultStmt *S); |
| 535 | ExpectedStmt VisitLabelStmt(LabelStmt *S); |
| 536 | ExpectedStmt VisitAttributedStmt(AttributedStmt *S); |
| 537 | ExpectedStmt VisitIfStmt(IfStmt *S); |
| 538 | ExpectedStmt VisitSwitchStmt(SwitchStmt *S); |
| 539 | ExpectedStmt VisitWhileStmt(WhileStmt *S); |
| 540 | ExpectedStmt VisitDoStmt(DoStmt *S); |
| 541 | ExpectedStmt VisitForStmt(ForStmt *S); |
| 542 | ExpectedStmt VisitGotoStmt(GotoStmt *S); |
| 543 | ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S); |
| 544 | ExpectedStmt VisitContinueStmt(ContinueStmt *S); |
| 545 | ExpectedStmt VisitBreakStmt(BreakStmt *S); |
| 546 | ExpectedStmt VisitReturnStmt(ReturnStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 547 | // FIXME: MSAsmStmt |
| 548 | // FIXME: SEHExceptStmt |
| 549 | // FIXME: SEHFinallyStmt |
| 550 | // FIXME: SEHTryStmt |
| 551 | // FIXME: SEHLeaveStmt |
| 552 | // FIXME: CapturedStmt |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 553 | ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S); |
| 554 | ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S); |
| 555 | ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 556 | // FIXME: MSDependentExistsStmt |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 557 | ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); |
| 558 | ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); |
| 559 | ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); |
| 560 | ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S); |
| 561 | ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); |
| 562 | ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); |
| 563 | ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 564 | |
| 565 | // Importing expressions |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 566 | ExpectedStmt VisitExpr(Expr *E); |
| 567 | ExpectedStmt VisitVAArgExpr(VAArgExpr *E); |
| 568 | ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E); |
| 569 | ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E); |
| 570 | ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E); |
| 571 | ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E); |
| 572 | ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E); |
| 573 | ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); |
| 574 | ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E); |
| 575 | ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E); |
| 576 | ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E); |
| 577 | ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E); |
| 578 | ExpectedStmt VisitStringLiteral(StringLiteral *E); |
| 579 | ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
| 580 | ExpectedStmt VisitAtomicExpr(AtomicExpr *E); |
| 581 | ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E); |
| 582 | ExpectedStmt VisitParenExpr(ParenExpr *E); |
| 583 | ExpectedStmt VisitParenListExpr(ParenListExpr *E); |
| 584 | ExpectedStmt VisitStmtExpr(StmtExpr *E); |
| 585 | ExpectedStmt VisitUnaryOperator(UnaryOperator *E); |
| 586 | ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); |
| 587 | ExpectedStmt VisitBinaryOperator(BinaryOperator *E); |
| 588 | ExpectedStmt VisitConditionalOperator(ConditionalOperator *E); |
| 589 | ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E); |
| 590 | ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E); |
| 591 | ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); |
| 592 | ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E); |
| 593 | ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
| 594 | ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E); |
| 595 | ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E); |
| 596 | ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 597 | ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE); |
| 598 | ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E); |
| 599 | ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E); |
| 600 | ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); |
| 601 | ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); |
| 602 | ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); |
| 603 | ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E); |
| 604 | ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); |
| 605 | ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E); |
| 606 | ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E); |
| 607 | ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E); |
| 608 | ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E); |
| 609 | ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E); |
| 610 | ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E); |
| 611 | ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); |
| 612 | ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E); |
| 613 | ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E); |
| 614 | ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); |
| 615 | ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E); |
| 616 | ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E); |
| 617 | ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E); |
| 618 | ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); |
| 619 | ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); |
| 620 | ExpectedStmt VisitMemberExpr(MemberExpr *E); |
| 621 | ExpectedStmt VisitCallExpr(CallExpr *E); |
| 622 | ExpectedStmt VisitLambdaExpr(LambdaExpr *LE); |
| 623 | ExpectedStmt VisitInitListExpr(InitListExpr *E); |
| 624 | ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E); |
| 625 | ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E); |
| 626 | ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); |
| 627 | ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); |
| 628 | ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); |
| 629 | ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E); |
| 630 | ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); |
| 631 | ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E); |
| 632 | ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 633 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 634 | template<typename IIter, typename OIter> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 635 | Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 636 | using ItemT = typename std::remove_reference<decltype(*Obegin)>::type; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 637 | for (; Ibegin != Iend; ++Ibegin, ++Obegin) { |
| 638 | Expected<ItemT> ToOrErr = import(*Ibegin); |
| 639 | if (!ToOrErr) |
| 640 | return ToOrErr.takeError(); |
| 641 | *Obegin = *ToOrErr; |
| 642 | } |
| 643 | return Error::success(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 644 | } |
| 645 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 646 | // Import every item from a container structure into an output container. |
| 647 | // If error occurs, stops at first error and returns the error. |
| 648 | // The output container should have space for all needed elements (it is not |
| 649 | // expanded, new items are put into from the beginning). |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 650 | template<typename InContainerTy, typename OutContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 651 | Error ImportContainerChecked( |
| 652 | const InContainerTy &InContainer, OutContainerTy &OutContainer) { |
| 653 | return ImportArrayChecked( |
| 654 | InContainer.begin(), InContainer.end(), OutContainer.begin()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | template<typename InContainerTy, typename OIter> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 658 | Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 659 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); |
| 660 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 661 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 662 | void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 663 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 664 | Expected<FunctionDecl *> FindFunctionTemplateSpecialization( |
| 665 | FunctionDecl *FromFD); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 666 | }; |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 667 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 668 | // FIXME: Temporary until every import returns Expected. |
| 669 | template <> |
| 670 | Expected<TemplateName> ASTNodeImporter::import(const TemplateName &From) { |
| 671 | TemplateName To = Importer.Import(From); |
| 672 | if (To.isNull() && !From.isNull()) |
| 673 | return make_error<ImportError>(); |
| 674 | return To; |
| 675 | } |
| 676 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 677 | template <typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 678 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 679 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 680 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 681 | auto ToLAngleLocOrErr = import(FromLAngleLoc); |
| 682 | if (!ToLAngleLocOrErr) |
| 683 | return ToLAngleLocOrErr.takeError(); |
| 684 | auto ToRAngleLocOrErr = import(FromRAngleLoc); |
| 685 | if (!ToRAngleLocOrErr) |
| 686 | return ToRAngleLocOrErr.takeError(); |
| 687 | |
| 688 | TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr); |
| 689 | if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo)) |
| 690 | return Err; |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 691 | Result = ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 692 | return Error::success(); |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 693 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 694 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 695 | template <> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 696 | Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 697 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { |
| 698 | return ImportTemplateArgumentListInfo( |
| 699 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); |
| 700 | } |
| 701 | |
| 702 | template <> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 703 | Error ASTNodeImporter::ImportTemplateArgumentListInfo< |
| 704 | ASTTemplateArgumentListInfo>( |
| 705 | const ASTTemplateArgumentListInfo &From, |
| 706 | TemplateArgumentListInfo &Result) { |
| 707 | return ImportTemplateArgumentListInfo( |
| 708 | From.LAngleLoc, From.RAngleLoc, From.arguments(), Result); |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 709 | } |
| 710 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 711 | Expected<ASTNodeImporter::FunctionTemplateAndArgsTy> |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 712 | ASTNodeImporter::ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 713 | FunctionDecl *FromFD) { |
| 714 | assert(FromFD->getTemplatedKind() == |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 715 | FunctionDecl::TK_FunctionTemplateSpecialization); |
| 716 | |
| 717 | FunctionTemplateAndArgsTy Result; |
| 718 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 719 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 720 | if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate())) |
| 721 | return std::move(Err); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 722 | |
| 723 | // Import template arguments. |
| 724 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 725 | if (Error Err = ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), |
| 726 | std::get<1>(Result))) |
| 727 | return std::move(Err); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 728 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 729 | return Result; |
| 730 | } |
| 731 | |
| 732 | template <> |
| 733 | Expected<TemplateParameterList *> |
| 734 | ASTNodeImporter::import(TemplateParameterList *From) { |
| 735 | SmallVector<NamedDecl *, 4> To(From->size()); |
| 736 | if (Error Err = ImportContainerChecked(*From, To)) |
| 737 | return std::move(Err); |
| 738 | |
| 739 | ExpectedExpr ToRequiresClause = import(From->getRequiresClause()); |
| 740 | if (!ToRequiresClause) |
| 741 | return ToRequiresClause.takeError(); |
| 742 | |
| 743 | auto ToTemplateLocOrErr = import(From->getTemplateLoc()); |
| 744 | if (!ToTemplateLocOrErr) |
| 745 | return ToTemplateLocOrErr.takeError(); |
| 746 | auto ToLAngleLocOrErr = import(From->getLAngleLoc()); |
| 747 | if (!ToLAngleLocOrErr) |
| 748 | return ToLAngleLocOrErr.takeError(); |
| 749 | auto ToRAngleLocOrErr = import(From->getRAngleLoc()); |
| 750 | if (!ToRAngleLocOrErr) |
| 751 | return ToRAngleLocOrErr.takeError(); |
| 752 | |
| 753 | return TemplateParameterList::Create( |
| 754 | Importer.getToContext(), |
| 755 | *ToTemplateLocOrErr, |
| 756 | *ToLAngleLocOrErr, |
| 757 | To, |
| 758 | *ToRAngleLocOrErr, |
| 759 | *ToRequiresClause); |
| 760 | } |
| 761 | |
| 762 | template <> |
| 763 | Expected<TemplateArgument> |
| 764 | ASTNodeImporter::import(const TemplateArgument &From) { |
| 765 | switch (From.getKind()) { |
| 766 | case TemplateArgument::Null: |
| 767 | return TemplateArgument(); |
| 768 | |
| 769 | case TemplateArgument::Type: { |
| 770 | ExpectedType ToTypeOrErr = import(From.getAsType()); |
| 771 | if (!ToTypeOrErr) |
| 772 | return ToTypeOrErr.takeError(); |
| 773 | return TemplateArgument(*ToTypeOrErr); |
| 774 | } |
| 775 | |
| 776 | case TemplateArgument::Integral: { |
| 777 | ExpectedType ToTypeOrErr = import(From.getIntegralType()); |
| 778 | if (!ToTypeOrErr) |
| 779 | return ToTypeOrErr.takeError(); |
| 780 | return TemplateArgument(From, *ToTypeOrErr); |
| 781 | } |
| 782 | |
| 783 | case TemplateArgument::Declaration: { |
| 784 | Expected<ValueDecl *> ToOrErr = import(From.getAsDecl()); |
| 785 | if (!ToOrErr) |
| 786 | return ToOrErr.takeError(); |
| 787 | ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl()); |
| 788 | if (!ToTypeOrErr) |
| 789 | return ToTypeOrErr.takeError(); |
| 790 | return TemplateArgument(*ToOrErr, *ToTypeOrErr); |
| 791 | } |
| 792 | |
| 793 | case TemplateArgument::NullPtr: { |
| 794 | ExpectedType ToTypeOrErr = import(From.getNullPtrType()); |
| 795 | if (!ToTypeOrErr) |
| 796 | return ToTypeOrErr.takeError(); |
| 797 | return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true); |
| 798 | } |
| 799 | |
| 800 | case TemplateArgument::Template: { |
| 801 | Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate()); |
| 802 | if (!ToTemplateOrErr) |
| 803 | return ToTemplateOrErr.takeError(); |
| 804 | |
| 805 | return TemplateArgument(*ToTemplateOrErr); |
| 806 | } |
| 807 | |
| 808 | case TemplateArgument::TemplateExpansion: { |
| 809 | Expected<TemplateName> ToTemplateOrErr = |
| 810 | import(From.getAsTemplateOrTemplatePattern()); |
| 811 | if (!ToTemplateOrErr) |
| 812 | return ToTemplateOrErr.takeError(); |
| 813 | |
| 814 | return TemplateArgument( |
| 815 | *ToTemplateOrErr, From.getNumTemplateExpansions()); |
| 816 | } |
| 817 | |
| 818 | case TemplateArgument::Expression: |
| 819 | if (ExpectedExpr ToExpr = import(From.getAsExpr())) |
| 820 | return TemplateArgument(*ToExpr); |
| 821 | else |
| 822 | return ToExpr.takeError(); |
| 823 | |
| 824 | case TemplateArgument::Pack: { |
| 825 | SmallVector<TemplateArgument, 2> ToPack; |
| 826 | ToPack.reserve(From.pack_size()); |
| 827 | if (Error Err = ImportTemplateArguments( |
| 828 | From.pack_begin(), From.pack_size(), ToPack)) |
| 829 | return std::move(Err); |
| 830 | |
| 831 | return TemplateArgument( |
| 832 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | llvm_unreachable("Invalid template argument kind"); |
| 837 | } |
| 838 | |
| 839 | template <> |
| 840 | Expected<TemplateArgumentLoc> |
| 841 | ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) { |
| 842 | Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument()); |
| 843 | if (!ArgOrErr) |
| 844 | return ArgOrErr.takeError(); |
| 845 | TemplateArgument Arg = *ArgOrErr; |
| 846 | |
| 847 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); |
| 848 | |
| 849 | TemplateArgumentLocInfo ToInfo; |
| 850 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 851 | ExpectedExpr E = import(FromInfo.getAsExpr()); |
| 852 | if (!E) |
| 853 | return E.takeError(); |
| 854 | ToInfo = TemplateArgumentLocInfo(*E); |
| 855 | } else if (Arg.getKind() == TemplateArgument::Type) { |
| 856 | if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo())) |
| 857 | ToInfo = TemplateArgumentLocInfo(*TSIOrErr); |
| 858 | else |
| 859 | return TSIOrErr.takeError(); |
| 860 | } else { |
| 861 | auto ToTemplateQualifierLocOrErr = |
| 862 | import(FromInfo.getTemplateQualifierLoc()); |
| 863 | if (!ToTemplateQualifierLocOrErr) |
| 864 | return ToTemplateQualifierLocOrErr.takeError(); |
| 865 | auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc()); |
| 866 | if (!ToTemplateNameLocOrErr) |
| 867 | return ToTemplateNameLocOrErr.takeError(); |
| 868 | auto ToTemplateEllipsisLocOrErr = |
| 869 | import(FromInfo.getTemplateEllipsisLoc()); |
| 870 | if (!ToTemplateEllipsisLocOrErr) |
| 871 | return ToTemplateEllipsisLocOrErr.takeError(); |
| 872 | |
| 873 | ToInfo = TemplateArgumentLocInfo( |
| 874 | *ToTemplateQualifierLocOrErr, |
| 875 | *ToTemplateNameLocOrErr, |
| 876 | *ToTemplateEllipsisLocOrErr); |
| 877 | } |
| 878 | |
| 879 | return TemplateArgumentLoc(Arg, ToInfo); |
| 880 | } |
| 881 | |
| 882 | template <> |
| 883 | Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) { |
| 884 | if (DG.isNull()) |
| 885 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); |
| 886 | size_t NumDecls = DG.end() - DG.begin(); |
| 887 | SmallVector<Decl *, 1> ToDecls; |
| 888 | ToDecls.reserve(NumDecls); |
| 889 | for (Decl *FromD : DG) { |
| 890 | if (auto ToDOrErr = import(FromD)) |
| 891 | ToDecls.push_back(*ToDOrErr); |
| 892 | else |
| 893 | return ToDOrErr.takeError(); |
| 894 | } |
| 895 | return DeclGroupRef::Create(Importer.getToContext(), |
| 896 | ToDecls.begin(), |
| 897 | NumDecls); |
| 898 | } |
| 899 | |
| 900 | template <> |
| 901 | Expected<ASTNodeImporter::Designator> |
| 902 | ASTNodeImporter::import(const Designator &D) { |
| 903 | if (D.isFieldDesignator()) { |
| 904 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); |
| 905 | |
| 906 | ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc()); |
| 907 | if (!ToDotLocOrErr) |
| 908 | return ToDotLocOrErr.takeError(); |
| 909 | |
| 910 | ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc()); |
| 911 | if (!ToFieldLocOrErr) |
| 912 | return ToFieldLocOrErr.takeError(); |
| 913 | |
| 914 | return Designator(ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr); |
| 915 | } |
| 916 | |
| 917 | ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc()); |
| 918 | if (!ToLBracketLocOrErr) |
| 919 | return ToLBracketLocOrErr.takeError(); |
| 920 | |
| 921 | ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc()); |
| 922 | if (!ToRBracketLocOrErr) |
| 923 | return ToRBracketLocOrErr.takeError(); |
| 924 | |
| 925 | if (D.isArrayDesignator()) |
| 926 | return Designator(D.getFirstExprIndex(), |
| 927 | *ToLBracketLocOrErr, *ToRBracketLocOrErr); |
| 928 | |
| 929 | ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc()); |
| 930 | if (!ToEllipsisLocOrErr) |
| 931 | return ToEllipsisLocOrErr.takeError(); |
| 932 | |
| 933 | assert(D.isArrayRangeDesignator()); |
| 934 | return Designator( |
| 935 | D.getFirstExprIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr, |
| 936 | *ToRBracketLocOrErr); |
| 937 | } |
| 938 | |
| 939 | template <> |
| 940 | Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) { |
| 941 | VarDecl *Var = nullptr; |
| 942 | if (From.capturesVariable()) { |
| 943 | if (auto VarOrErr = import(From.getCapturedVar())) |
| 944 | Var = *VarOrErr; |
| 945 | else |
| 946 | return VarOrErr.takeError(); |
| 947 | } |
| 948 | |
| 949 | auto LocationOrErr = import(From.getLocation()); |
| 950 | if (!LocationOrErr) |
| 951 | return LocationOrErr.takeError(); |
| 952 | |
| 953 | SourceLocation EllipsisLoc; |
| 954 | if (From.isPackExpansion()) |
| 955 | if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc())) |
| 956 | return std::move(Err); |
| 957 | |
| 958 | return LambdaCapture( |
| 959 | *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var, |
| 960 | EllipsisLoc); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 961 | } |
| 962 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 963 | } // namespace clang |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 964 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 965 | //---------------------------------------------------------------------------- |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 966 | // Import Types |
| 967 | //---------------------------------------------------------------------------- |
| 968 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 969 | using namespace clang; |
| 970 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 971 | ExpectedType ASTNodeImporter::VisitType(const Type *T) { |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 972 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) |
| 973 | << T->getTypeClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 974 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 975 | } |
| 976 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 977 | ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ |
| 978 | ExpectedType UnderlyingTypeOrErr = import(T->getValueType()); |
| 979 | if (!UnderlyingTypeOrErr) |
| 980 | return UnderlyingTypeOrErr.takeError(); |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 981 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 982 | return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr); |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 983 | } |
| 984 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 985 | ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 986 | switch (T->getKind()) { |
Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 987 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 988 | case BuiltinType::Id: \ |
| 989 | return Importer.getToContext().SingletonId; |
Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 990 | #include "clang/Basic/OpenCLImageTypes.def" |
Andrew Savonichev | 3fee351 | 2018-11-08 11:25:41 +0000 | [diff] [blame^] | 991 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ |
| 992 | case BuiltinType::Id: \ |
| 993 | return Importer.getToContext().Id##Ty; |
| 994 | #include "clang/Basic/OpenCLExtensionTypes.def" |
John McCall | e314e27 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 995 | #define SHARED_SINGLETON_TYPE(Expansion) |
| 996 | #define BUILTIN_TYPE(Id, SingletonId) \ |
| 997 | case BuiltinType::Id: return Importer.getToContext().SingletonId; |
| 998 | #include "clang/AST/BuiltinTypes.def" |
| 999 | |
| 1000 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" |
| 1001 | // context supports C++. |
| 1002 | |
| 1003 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" |
| 1004 | // context supports ObjC. |
| 1005 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1006 | case BuiltinType::Char_U: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1007 | // The context we're importing from has an unsigned 'char'. If we're |
| 1008 | // importing into a context with a signed 'char', translate to |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1009 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1010 | if (Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1011 | return Importer.getToContext().UnsignedCharTy; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1012 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1013 | return Importer.getToContext().CharTy; |
| 1014 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1015 | case BuiltinType::Char_S: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1016 | // The context we're importing from has an unsigned 'char'. If we're |
| 1017 | // importing into a context with a signed 'char', translate to |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1018 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1019 | if (!Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1020 | return Importer.getToContext().SignedCharTy; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1021 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1022 | return Importer.getToContext().CharTy; |
| 1023 | |
Chris Lattner | ad3467e | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 1024 | case BuiltinType::WChar_S: |
| 1025 | case BuiltinType::WChar_U: |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1026 | // FIXME: If not in C++, shall we translate to the C equivalent of |
| 1027 | // wchar_t? |
| 1028 | return Importer.getToContext().WCharTy; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1029 | } |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 1030 | |
| 1031 | llvm_unreachable("Invalid BuiltinType Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1034 | ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { |
| 1035 | ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType()); |
| 1036 | if (!ToOriginalTypeOrErr) |
| 1037 | return ToOriginalTypeOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1038 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1039 | return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1042 | ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) { |
| 1043 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1044 | if (!ToElementTypeOrErr) |
| 1045 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1046 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1047 | return Importer.getToContext().getComplexType(*ToElementTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1048 | } |
| 1049 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1050 | ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) { |
| 1051 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1052 | if (!ToPointeeTypeOrErr) |
| 1053 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1054 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1055 | return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1056 | } |
| 1057 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1058 | ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1059 | // FIXME: Check for blocks support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1060 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1061 | if (!ToPointeeTypeOrErr) |
| 1062 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1063 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1064 | return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1065 | } |
| 1066 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1067 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1068 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1069 | // FIXME: Check for C++ support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1070 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); |
| 1071 | if (!ToPointeeTypeOrErr) |
| 1072 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1073 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1074 | return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1077 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1078 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1079 | // FIXME: Check for C++0x support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1080 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); |
| 1081 | if (!ToPointeeTypeOrErr) |
| 1082 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1083 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1084 | return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1087 | ExpectedType |
| 1088 | ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1089 | // FIXME: Check for C++ support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1090 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1091 | if (!ToPointeeTypeOrErr) |
| 1092 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1093 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1094 | ExpectedType ClassTypeOrErr = import(QualType(T->getClass(), 0)); |
| 1095 | if (!ClassTypeOrErr) |
| 1096 | return ClassTypeOrErr.takeError(); |
| 1097 | |
| 1098 | return Importer.getToContext().getMemberPointerType( |
| 1099 | *ToPointeeTypeOrErr, (*ClassTypeOrErr).getTypePtr()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1100 | } |
| 1101 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1102 | ExpectedType |
| 1103 | ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { |
| 1104 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1105 | if (!ToElementTypeOrErr) |
| 1106 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1107 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1108 | return Importer.getToContext().getConstantArrayType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1109 | T->getSize(), |
| 1110 | T->getSizeModifier(), |
| 1111 | T->getIndexTypeCVRQualifiers()); |
| 1112 | } |
| 1113 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1114 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1115 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1116 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1117 | if (!ToElementTypeOrErr) |
| 1118 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1119 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1120 | return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1121 | T->getSizeModifier(), |
| 1122 | T->getIndexTypeCVRQualifiers()); |
| 1123 | } |
| 1124 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1125 | ExpectedType |
| 1126 | ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { |
| 1127 | QualType ToElementType; |
| 1128 | Expr *ToSizeExpr; |
| 1129 | SourceRange ToBracketsRange; |
| 1130 | if (auto Imp = importSeq( |
| 1131 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) |
| 1132 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; |
| 1133 | else |
| 1134 | return Imp.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1135 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1136 | return Importer.getToContext().getVariableArrayType( |
| 1137 | ToElementType, ToSizeExpr, T->getSizeModifier(), |
| 1138 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1141 | ExpectedType ASTNodeImporter::VisitDependentSizedArrayType( |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1142 | const DependentSizedArrayType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1143 | QualType ToElementType; |
| 1144 | Expr *ToSizeExpr; |
| 1145 | SourceRange ToBracketsRange; |
| 1146 | if (auto Imp = importSeq( |
| 1147 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) |
| 1148 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; |
| 1149 | else |
| 1150 | return Imp.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1151 | // SizeExpr may be null if size is not specified directly. |
| 1152 | // For example, 'int a[]'. |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1153 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1154 | return Importer.getToContext().getDependentSizedArrayType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1155 | ToElementType, ToSizeExpr, T->getSizeModifier(), |
| 1156 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1159 | ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) { |
| 1160 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1161 | if (!ToElementTypeOrErr) |
| 1162 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1163 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1164 | return Importer.getToContext().getVectorType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1165 | T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 1166 | T->getVectorKind()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1167 | } |
| 1168 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1169 | ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { |
| 1170 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1171 | if (!ToElementTypeOrErr) |
| 1172 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1173 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1174 | return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1175 | T->getNumElements()); |
| 1176 | } |
| 1177 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1178 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1179 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1180 | // FIXME: What happens if we're importing a function without a prototype |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1181 | // into C++? Should we make it variadic? |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1182 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); |
| 1183 | if (!ToReturnTypeOrErr) |
| 1184 | return ToReturnTypeOrErr.takeError(); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1185 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1186 | return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr, |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1187 | T->getExtInfo()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1188 | } |
| 1189 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1190 | ExpectedType |
| 1191 | ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { |
| 1192 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); |
| 1193 | if (!ToReturnTypeOrErr) |
| 1194 | return ToReturnTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1195 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1196 | // Import argument types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1197 | SmallVector<QualType, 4> ArgTypes; |
Aaron Ballman | 40bd0aa | 2014-03-17 15:23:01 +0000 | [diff] [blame] | 1198 | for (const auto &A : T->param_types()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1199 | ExpectedType TyOrErr = import(A); |
| 1200 | if (!TyOrErr) |
| 1201 | return TyOrErr.takeError(); |
| 1202 | ArgTypes.push_back(*TyOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1203 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1204 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1205 | // Import exception types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1206 | SmallVector<QualType, 4> ExceptionTypes; |
Aaron Ballman | b088fbe | 2014-03-17 15:38:09 +0000 | [diff] [blame] | 1207 | for (const auto &E : T->exceptions()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1208 | ExpectedType TyOrErr = import(E); |
| 1209 | if (!TyOrErr) |
| 1210 | return TyOrErr.takeError(); |
| 1211 | ExceptionTypes.push_back(*TyOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1212 | } |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 1213 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1214 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); |
| 1215 | FunctionProtoType::ExtProtoInfo ToEPI; |
| 1216 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1217 | auto Imp = importSeq( |
| 1218 | FromEPI.ExceptionSpec.NoexceptExpr, |
| 1219 | FromEPI.ExceptionSpec.SourceDecl, |
| 1220 | FromEPI.ExceptionSpec.SourceTemplate); |
| 1221 | if (!Imp) |
| 1222 | return Imp.takeError(); |
| 1223 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1224 | ToEPI.ExtInfo = FromEPI.ExtInfo; |
| 1225 | ToEPI.Variadic = FromEPI.Variadic; |
| 1226 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; |
| 1227 | ToEPI.TypeQuals = FromEPI.TypeQuals; |
| 1228 | ToEPI.RefQualifier = FromEPI.RefQualifier; |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 1229 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; |
| 1230 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1231 | std::tie( |
| 1232 | ToEPI.ExceptionSpec.NoexceptExpr, |
| 1233 | ToEPI.ExceptionSpec.SourceDecl, |
| 1234 | ToEPI.ExceptionSpec.SourceTemplate) = *Imp; |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1235 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1236 | return Importer.getToContext().getFunctionType( |
| 1237 | *ToReturnTypeOrErr, ArgTypes, ToEPI); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1238 | } |
| 1239 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1240 | ExpectedType ASTNodeImporter::VisitUnresolvedUsingType( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1241 | const UnresolvedUsingType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1242 | UnresolvedUsingTypenameDecl *ToD; |
| 1243 | Decl *ToPrevD; |
| 1244 | if (auto Imp = importSeq(T->getDecl(), T->getDecl()->getPreviousDecl())) |
| 1245 | std::tie(ToD, ToPrevD) = *Imp; |
| 1246 | else |
| 1247 | return Imp.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1248 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1249 | return Importer.getToContext().getTypeDeclType( |
| 1250 | ToD, cast_or_null<TypeDecl>(ToPrevD)); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1253 | ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) { |
| 1254 | ExpectedType ToInnerTypeOrErr = import(T->getInnerType()); |
| 1255 | if (!ToInnerTypeOrErr) |
| 1256 | return ToInnerTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1257 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1258 | return Importer.getToContext().getParenType(*ToInnerTypeOrErr); |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 1259 | } |
| 1260 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1261 | ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { |
| 1262 | Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1263 | if (!ToDeclOrErr) |
| 1264 | return ToDeclOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1265 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1266 | return Importer.getToContext().getTypeDeclType(*ToDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1267 | } |
| 1268 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1269 | ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { |
| 1270 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); |
| 1271 | if (!ToExprOrErr) |
| 1272 | return ToExprOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1273 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1274 | return Importer.getToContext().getTypeOfExprType(*ToExprOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1277 | ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { |
| 1278 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1279 | if (!ToUnderlyingTypeOrErr) |
| 1280 | return ToUnderlyingTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1281 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1282 | return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1285 | ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1286 | // FIXME: Make sure that the "to" context supports C++0x! |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1287 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); |
| 1288 | if (!ToExprOrErr) |
| 1289 | return ToExprOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1290 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1291 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1292 | if (!ToUnderlyingTypeOrErr) |
| 1293 | return ToUnderlyingTypeOrErr.takeError(); |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 1294 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1295 | return Importer.getToContext().getDecltypeType( |
| 1296 | *ToExprOrErr, *ToUnderlyingTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1297 | } |
| 1298 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1299 | ExpectedType |
| 1300 | ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 1301 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); |
| 1302 | if (!ToBaseTypeOrErr) |
| 1303 | return ToBaseTypeOrErr.takeError(); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1304 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1305 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1306 | if (!ToUnderlyingTypeOrErr) |
| 1307 | return ToUnderlyingTypeOrErr.takeError(); |
| 1308 | |
| 1309 | return Importer.getToContext().getUnaryTransformType( |
| 1310 | *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind()); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1311 | } |
| 1312 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1313 | ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 1314 | // FIXME: Make sure that the "to" context supports C++11! |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1315 | ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType()); |
| 1316 | if (!ToDeducedTypeOrErr) |
| 1317 | return ToDeducedTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1318 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1319 | return Importer.getToContext().getAutoType(*ToDeducedTypeOrErr, |
| 1320 | T->getKeyword(), |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 1321 | /*IsDependent*/false); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1322 | } |
| 1323 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1324 | ExpectedType ASTNodeImporter::VisitInjectedClassNameType( |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1325 | const InjectedClassNameType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1326 | Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1327 | if (!ToDeclOrErr) |
| 1328 | return ToDeclOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1329 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1330 | ExpectedType ToInjTypeOrErr = import(T->getInjectedSpecializationType()); |
| 1331 | if (!ToInjTypeOrErr) |
| 1332 | return ToInjTypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1333 | |
| 1334 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading |
| 1335 | // See comments in InjectedClassNameType definition for details |
| 1336 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); |
| 1337 | enum { |
| 1338 | TypeAlignmentInBits = 4, |
| 1339 | TypeAlignment = 1 << TypeAlignmentInBits |
| 1340 | }; |
| 1341 | |
| 1342 | return QualType(new (Importer.getToContext(), TypeAlignment) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1343 | InjectedClassNameType(*ToDeclOrErr, *ToInjTypeOrErr), 0); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1344 | } |
| 1345 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1346 | ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) { |
| 1347 | Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1348 | if (!ToDeclOrErr) |
| 1349 | return ToDeclOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1350 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1351 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1352 | } |
| 1353 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1354 | ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) { |
| 1355 | Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1356 | if (!ToDeclOrErr) |
| 1357 | return ToDeclOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1358 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1359 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1360 | } |
| 1361 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1362 | ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { |
| 1363 | ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType()); |
| 1364 | if (!ToModifiedTypeOrErr) |
| 1365 | return ToModifiedTypeOrErr.takeError(); |
| 1366 | ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType()); |
| 1367 | if (!ToEquivalentTypeOrErr) |
| 1368 | return ToEquivalentTypeOrErr.takeError(); |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1369 | |
| 1370 | return Importer.getToContext().getAttributedType(T->getAttrKind(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1371 | *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr); |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1374 | ExpectedType ASTNodeImporter::VisitTemplateTypeParmType( |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1375 | const TemplateTypeParmType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1376 | Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1377 | if (!ToDeclOrErr) |
| 1378 | return ToDeclOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1379 | |
| 1380 | return Importer.getToContext().getTemplateTypeParmType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1381 | T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1382 | } |
| 1383 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1384 | ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType( |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1385 | const SubstTemplateTypeParmType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1386 | ExpectedType ReplacedOrErr = import(QualType(T->getReplacedParameter(), 0)); |
| 1387 | if (!ReplacedOrErr) |
| 1388 | return ReplacedOrErr.takeError(); |
| 1389 | const TemplateTypeParmType *Replaced = |
| 1390 | cast<TemplateTypeParmType>((*ReplacedOrErr).getTypePtr()); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1391 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1392 | ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType()); |
| 1393 | if (!ToReplacementTypeOrErr) |
| 1394 | return ToReplacementTypeOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1395 | |
| 1396 | return Importer.getToContext().getSubstTemplateTypeParmType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1397 | Replaced, (*ToReplacementTypeOrErr).getCanonicalType()); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1400 | ExpectedType ASTNodeImporter::VisitTemplateSpecializationType( |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1401 | const TemplateSpecializationType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1402 | auto ToTemplateOrErr = import(T->getTemplateName()); |
| 1403 | if (!ToTemplateOrErr) |
| 1404 | return ToTemplateOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1405 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1406 | SmallVector<TemplateArgument, 2> ToTemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1407 | if (Error Err = ImportTemplateArguments( |
| 1408 | T->getArgs(), T->getNumArgs(), ToTemplateArgs)) |
| 1409 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1410 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1411 | QualType ToCanonType; |
| 1412 | if (!QualType(T, 0).isCanonical()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1413 | QualType FromCanonType |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1414 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1415 | if (ExpectedType TyOrErr = import(FromCanonType)) |
| 1416 | ToCanonType = *TyOrErr; |
| 1417 | else |
| 1418 | return TyOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1419 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1420 | return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr, |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 1421 | ToTemplateArgs, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1422 | ToCanonType); |
| 1423 | } |
| 1424 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1425 | ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1426 | // Note: the qualifier in an ElaboratedType is optional. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1427 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1428 | if (!ToQualifierOrErr) |
| 1429 | return ToQualifierOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1430 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1431 | ExpectedType ToNamedTypeOrErr = import(T->getNamedType()); |
| 1432 | if (!ToNamedTypeOrErr) |
| 1433 | return ToNamedTypeOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1434 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1435 | Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl()); |
| 1436 | if (!ToOwnedTagDeclOrErr) |
| 1437 | return ToOwnedTagDeclOrErr.takeError(); |
Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 1438 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1439 | return Importer.getToContext().getElaboratedType(T->getKeyword(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1440 | *ToQualifierOrErr, |
| 1441 | *ToNamedTypeOrErr, |
| 1442 | *ToOwnedTagDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1443 | } |
| 1444 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1445 | ExpectedType |
| 1446 | ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { |
| 1447 | ExpectedType ToPatternOrErr = import(T->getPattern()); |
| 1448 | if (!ToPatternOrErr) |
| 1449 | return ToPatternOrErr.takeError(); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1450 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1451 | return Importer.getToContext().getPackExpansionType(*ToPatternOrErr, |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1452 | T->getNumExpansions()); |
| 1453 | } |
| 1454 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1455 | ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType( |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1456 | const DependentTemplateSpecializationType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1457 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1458 | if (!ToQualifierOrErr) |
| 1459 | return ToQualifierOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1460 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1461 | IdentifierInfo *ToName = Importer.Import(T->getIdentifier()); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1462 | |
| 1463 | SmallVector<TemplateArgument, 2> ToPack; |
| 1464 | ToPack.reserve(T->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1465 | if (Error Err = ImportTemplateArguments( |
| 1466 | T->getArgs(), T->getNumArgs(), ToPack)) |
| 1467 | return std::move(Err); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1468 | |
| 1469 | return Importer.getToContext().getDependentTemplateSpecializationType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1470 | T->getKeyword(), *ToQualifierOrErr, ToName, ToPack); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1471 | } |
| 1472 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1473 | ExpectedType |
| 1474 | ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) { |
| 1475 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1476 | if (!ToQualifierOrErr) |
| 1477 | return ToQualifierOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1478 | |
| 1479 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1480 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1481 | QualType Canon; |
| 1482 | if (T != T->getCanonicalTypeInternal().getTypePtr()) { |
| 1483 | if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal())) |
| 1484 | Canon = (*TyOrErr).getCanonicalType(); |
| 1485 | else |
| 1486 | return TyOrErr.takeError(); |
| 1487 | } |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1488 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1489 | return Importer.getToContext().getDependentNameType(T->getKeyword(), |
| 1490 | *ToQualifierOrErr, |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1491 | Name, Canon); |
| 1492 | } |
| 1493 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1494 | ExpectedType |
| 1495 | ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
| 1496 | Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1497 | if (!ToDeclOrErr) |
| 1498 | return ToDeclOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1499 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1500 | return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1501 | } |
| 1502 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1503 | ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { |
| 1504 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); |
| 1505 | if (!ToBaseTypeOrErr) |
| 1506 | return ToBaseTypeOrErr.takeError(); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1507 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1508 | SmallVector<QualType, 4> TypeArgs; |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 1509 | for (auto TypeArg : T->getTypeArgsAsWritten()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1510 | if (ExpectedType TyOrErr = import(TypeArg)) |
| 1511 | TypeArgs.push_back(*TyOrErr); |
| 1512 | else |
| 1513 | return TyOrErr.takeError(); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1514 | } |
| 1515 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1516 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 1517 | for (auto *P : T->quals()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1518 | if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P)) |
| 1519 | Protocols.push_back(*ProtocolOrErr); |
| 1520 | else |
| 1521 | return ProtocolOrErr.takeError(); |
| 1522 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1523 | } |
| 1524 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1525 | return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs, |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 1526 | Protocols, |
| 1527 | T->isKindOfTypeAsWritten()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1528 | } |
| 1529 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1530 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1531 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1532 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1533 | if (!ToPointeeTypeOrErr) |
| 1534 | return ToPointeeTypeOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1535 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1536 | return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1537 | } |
| 1538 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 1539 | //---------------------------------------------------------------------------- |
| 1540 | // Import Declarations |
| 1541 | //---------------------------------------------------------------------------- |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1542 | Error ASTNodeImporter::ImportDeclParts( |
| 1543 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, |
| 1544 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) { |
Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1545 | // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop. |
| 1546 | // example: int struct_in_proto(struct data_t{int a;int b;} *d); |
| 1547 | DeclContext *OrigDC = D->getDeclContext(); |
| 1548 | FunctionDecl *FunDecl; |
| 1549 | if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) && |
| 1550 | FunDecl->hasBody()) { |
Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1551 | auto getLeafPointeeType = [](const Type *T) { |
| 1552 | while (T->isPointerType() || T->isArrayType()) { |
| 1553 | T = T->getPointeeOrArrayElementType(); |
| 1554 | } |
| 1555 | return T; |
| 1556 | }; |
| 1557 | for (const ParmVarDecl *P : FunDecl->parameters()) { |
| 1558 | const Type *LeafT = |
| 1559 | getLeafPointeeType(P->getType().getCanonicalType().getTypePtr()); |
| 1560 | auto *RT = dyn_cast<RecordType>(LeafT); |
| 1561 | if (RT && RT->getDecl() == D) { |
| 1562 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 1563 | << D->getDeclKindName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1564 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1565 | } |
Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1566 | } |
| 1567 | } |
| 1568 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1569 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1570 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 1571 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1572 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1573 | // Import the name of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1574 | if (Error Err = importInto(Name, D->getDeclName())) |
| 1575 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1576 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1577 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1578 | if (Error Err = importInto(Loc, D->getLocation())) |
| 1579 | return Err; |
| 1580 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1581 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1582 | |
| 1583 | return Error::success(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1584 | } |
| 1585 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1586 | Error ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1587 | if (!FromD) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1588 | return Error::success(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1589 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1590 | if (!ToD) |
| 1591 | if (Error Err = importInto(ToD, FromD)) |
| 1592 | return Err; |
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 (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) { |
| 1595 | if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) { |
| 1596 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && |
| 1597 | !ToRecord->getDefinition()) { |
| 1598 | if (Error Err = ImportDefinition(FromRecord, ToRecord)) |
| 1599 | return Err; |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1600 | } |
| 1601 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1602 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1603 | } |
| 1604 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1605 | if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) { |
| 1606 | if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1607 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1608 | if (Error Err = ImportDefinition(FromEnum, ToEnum)) |
| 1609 | return Err; |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1610 | } |
| 1611 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1612 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1613 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1614 | |
| 1615 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1616 | } |
| 1617 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1618 | Error |
| 1619 | ASTNodeImporter::ImportDeclarationNameLoc( |
| 1620 | const DeclarationNameInfo &From, DeclarationNameInfo& To) { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1621 | // NOTE: To.Name and To.Loc are already imported. |
| 1622 | // We only have to import To.LocInfo. |
| 1623 | switch (To.getName().getNameKind()) { |
| 1624 | case DeclarationName::Identifier: |
| 1625 | case DeclarationName::ObjCZeroArgSelector: |
| 1626 | case DeclarationName::ObjCOneArgSelector: |
| 1627 | case DeclarationName::ObjCMultiArgSelector: |
| 1628 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1629 | case DeclarationName::CXXDeductionGuideName: |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1630 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1631 | |
| 1632 | case DeclarationName::CXXOperatorName: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1633 | if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange())) |
| 1634 | To.setCXXOperatorNameRange(*ToRangeOrErr); |
| 1635 | else |
| 1636 | return ToRangeOrErr.takeError(); |
| 1637 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1638 | } |
| 1639 | case DeclarationName::CXXLiteralOperatorName: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1640 | if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc())) |
| 1641 | To.setCXXLiteralOperatorNameLoc(*LocOrErr); |
| 1642 | else |
| 1643 | return LocOrErr.takeError(); |
| 1644 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1645 | } |
| 1646 | case DeclarationName::CXXConstructorName: |
| 1647 | case DeclarationName::CXXDestructorName: |
| 1648 | case DeclarationName::CXXConversionFunctionName: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1649 | if (auto ToTInfoOrErr = import(From.getNamedTypeInfo())) |
| 1650 | To.setNamedTypeInfo(*ToTInfoOrErr); |
| 1651 | else |
| 1652 | return ToTInfoOrErr.takeError(); |
| 1653 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1654 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1655 | } |
Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 1656 | llvm_unreachable("Unknown name kind."); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1657 | } |
| 1658 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1659 | Error |
| 1660 | ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1661 | if (Importer.isMinimalImport() && !ForceImport) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1662 | auto ToDCOrErr = Importer.ImportContext(FromDC); |
| 1663 | return ToDCOrErr.takeError(); |
| 1664 | } |
Davide Italiano | 93a64ef | 2018-10-30 20:46:29 +0000 | [diff] [blame] | 1665 | llvm::SmallVector<Decl *, 8> ImportedDecls; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1666 | for (auto *From : FromDC->decls()) { |
| 1667 | ExpectedDecl ImportedOrErr = import(From); |
Davide Italiano | 93a64ef | 2018-10-30 20:46:29 +0000 | [diff] [blame] | 1668 | if (!ImportedOrErr) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1669 | // Ignore the error, continue with next Decl. |
| 1670 | // FIXME: Handle this case somehow better. |
Davide Italiano | 93a64ef | 2018-10-30 20:46:29 +0000 | [diff] [blame] | 1671 | consumeError(ImportedOrErr.takeError()); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1672 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1673 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1674 | return Error::success(); |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 1675 | } |
| 1676 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1677 | Error ASTNodeImporter::ImportDeclContext( |
| 1678 | Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) { |
| 1679 | auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext()); |
| 1680 | if (!ToDCOrErr) |
| 1681 | return ToDCOrErr.takeError(); |
| 1682 | ToDC = *ToDCOrErr; |
| 1683 | |
| 1684 | if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) { |
| 1685 | auto ToLexicalDCOrErr = Importer.ImportContext( |
| 1686 | FromD->getLexicalDeclContext()); |
| 1687 | if (!ToLexicalDCOrErr) |
| 1688 | return ToLexicalDCOrErr.takeError(); |
| 1689 | ToLexicalDC = *ToLexicalDCOrErr; |
| 1690 | } else |
| 1691 | ToLexicalDC = ToDC; |
| 1692 | |
| 1693 | return Error::success(); |
| 1694 | } |
| 1695 | |
| 1696 | Error ASTNodeImporter::ImportImplicitMethods( |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1697 | const CXXRecordDecl *From, CXXRecordDecl *To) { |
| 1698 | assert(From->isCompleteDefinition() && To->getDefinition() == To && |
| 1699 | "Import implicit methods to or from non-definition"); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1700 | |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1701 | for (CXXMethodDecl *FromM : From->methods()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1702 | if (FromM->isImplicit()) { |
| 1703 | Expected<CXXMethodDecl *> ToMOrErr = import(FromM); |
| 1704 | if (!ToMOrErr) |
| 1705 | return ToMOrErr.takeError(); |
| 1706 | } |
| 1707 | |
| 1708 | return Error::success(); |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1709 | } |
| 1710 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1711 | static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, |
| 1712 | ASTImporter &Importer) { |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1713 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1714 | Decl *ToTypedef = Importer.Import(FromTypedef); |
| 1715 | if (!ToTypedef) |
| 1716 | return make_error<ImportError>(); |
| 1717 | To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(ToTypedef)); |
| 1718 | // FIXME: This should be the final code. |
| 1719 | //if (Expected<Decl *> ToTypedefOrErr = Importer.Import(FromTypedef)) |
| 1720 | // To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr)); |
| 1721 | //else |
| 1722 | // return ToTypedefOrErr.takeError(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1723 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1724 | return Error::success(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1725 | } |
| 1726 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1727 | Error ASTNodeImporter::ImportDefinition( |
| 1728 | RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1729 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1730 | if (Kind == IDK_Everything) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1731 | return ImportDeclContext(From, /*ForceImport=*/true); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1732 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1733 | return Error::success(); |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1734 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1735 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1736 | To->startDefinition(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1737 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1738 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 1739 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1740 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1741 | // Add base classes. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1742 | if (auto *ToCXX = dyn_cast<CXXRecordDecl>(To)) { |
| 1743 | auto *FromCXX = cast<CXXRecordDecl>(From); |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1744 | |
| 1745 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); |
| 1746 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); |
| 1747 | ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1748 | ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1749 | ToData.Aggregate = FromData.Aggregate; |
| 1750 | ToData.PlainOldData = FromData.PlainOldData; |
| 1751 | ToData.Empty = FromData.Empty; |
| 1752 | ToData.Polymorphic = FromData.Polymorphic; |
| 1753 | ToData.Abstract = FromData.Abstract; |
| 1754 | ToData.IsStandardLayout = FromData.IsStandardLayout; |
Richard Smith | b6070db | 2018-04-05 18:55:37 +0000 | [diff] [blame] | 1755 | ToData.IsCXX11StandardLayout = FromData.IsCXX11StandardLayout; |
| 1756 | ToData.HasBasesWithFields = FromData.HasBasesWithFields; |
| 1757 | ToData.HasBasesWithNonStaticDataMembers = |
| 1758 | FromData.HasBasesWithNonStaticDataMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1759 | ToData.HasPrivateFields = FromData.HasPrivateFields; |
| 1760 | ToData.HasProtectedFields = FromData.HasProtectedFields; |
| 1761 | ToData.HasPublicFields = FromData.HasPublicFields; |
| 1762 | ToData.HasMutableFields = FromData.HasMutableFields; |
Richard Smith | ab44d5b | 2013-12-10 08:25:00 +0000 | [diff] [blame] | 1763 | ToData.HasVariantMembers = FromData.HasVariantMembers; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1764 | ToData.HasOnlyCMembers = FromData.HasOnlyCMembers; |
Richard Smith | e2648ba | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 1765 | ToData.HasInClassInitializer = FromData.HasInClassInitializer; |
Richard Smith | 593f993 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 1766 | ToData.HasUninitializedReferenceMember |
| 1767 | = FromData.HasUninitializedReferenceMember; |
Nico Weber | 6a6376b | 2016-02-19 01:52:46 +0000 | [diff] [blame] | 1768 | ToData.HasUninitializedFields = FromData.HasUninitializedFields; |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 1769 | ToData.HasInheritedConstructor = FromData.HasInheritedConstructor; |
| 1770 | ToData.HasInheritedAssignment = FromData.HasInheritedAssignment; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1771 | ToData.NeedOverloadResolutionForCopyConstructor |
| 1772 | = FromData.NeedOverloadResolutionForCopyConstructor; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1773 | ToData.NeedOverloadResolutionForMoveConstructor |
| 1774 | = FromData.NeedOverloadResolutionForMoveConstructor; |
| 1775 | ToData.NeedOverloadResolutionForMoveAssignment |
| 1776 | = FromData.NeedOverloadResolutionForMoveAssignment; |
| 1777 | ToData.NeedOverloadResolutionForDestructor |
| 1778 | = FromData.NeedOverloadResolutionForDestructor; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1779 | ToData.DefaultedCopyConstructorIsDeleted |
| 1780 | = FromData.DefaultedCopyConstructorIsDeleted; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1781 | ToData.DefaultedMoveConstructorIsDeleted |
| 1782 | = FromData.DefaultedMoveConstructorIsDeleted; |
| 1783 | ToData.DefaultedMoveAssignmentIsDeleted |
| 1784 | = FromData.DefaultedMoveAssignmentIsDeleted; |
| 1785 | ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1786 | ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers; |
| 1787 | ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1788 | ToData.HasConstexprNonCopyMoveConstructor |
| 1789 | = FromData.HasConstexprNonCopyMoveConstructor; |
Nico Weber | 72c57f4 | 2016-02-24 20:58:14 +0000 | [diff] [blame] | 1790 | ToData.HasDefaultedDefaultConstructor |
| 1791 | = FromData.HasDefaultedDefaultConstructor; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1792 | ToData.DefaultedDefaultConstructorIsConstexpr |
| 1793 | = FromData.DefaultedDefaultConstructorIsConstexpr; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1794 | ToData.HasConstexprDefaultConstructor |
| 1795 | = FromData.HasConstexprDefaultConstructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1796 | ToData.HasNonLiteralTypeFieldsOrBases |
| 1797 | = FromData.HasNonLiteralTypeFieldsOrBases; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1798 | // ComputedVisibleConversions not imported. |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1799 | ToData.UserProvidedDefaultConstructor |
| 1800 | = FromData.UserProvidedDefaultConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1801 | ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers; |
Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 1802 | ToData.ImplicitCopyConstructorCanHaveConstParamForVBase |
| 1803 | = FromData.ImplicitCopyConstructorCanHaveConstParamForVBase; |
| 1804 | ToData.ImplicitCopyConstructorCanHaveConstParamForNonVBase |
| 1805 | = FromData.ImplicitCopyConstructorCanHaveConstParamForNonVBase; |
Richard Smith | 1c33fe8 | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 1806 | ToData.ImplicitCopyAssignmentHasConstParam |
| 1807 | = FromData.ImplicitCopyAssignmentHasConstParam; |
| 1808 | ToData.HasDeclaredCopyConstructorWithConstParam |
| 1809 | = FromData.HasDeclaredCopyConstructorWithConstParam; |
| 1810 | ToData.HasDeclaredCopyAssignmentWithConstParam |
| 1811 | = FromData.HasDeclaredCopyAssignmentWithConstParam; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1812 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1813 | SmallVector<CXXBaseSpecifier *, 4> Bases; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1814 | for (const auto &Base1 : FromCXX->bases()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1815 | ExpectedType TyOrErr = import(Base1.getType()); |
| 1816 | if (!TyOrErr) |
| 1817 | return TyOrErr.takeError(); |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1818 | |
| 1819 | SourceLocation EllipsisLoc; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1820 | if (Base1.isPackExpansion()) { |
| 1821 | if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc())) |
| 1822 | EllipsisLoc = *LocOrErr; |
| 1823 | else |
| 1824 | return LocOrErr.takeError(); |
| 1825 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1826 | |
| 1827 | // Ensure that we have a definition for the base. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1828 | if (Error Err = |
| 1829 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl())) |
| 1830 | return Err; |
| 1831 | |
| 1832 | auto RangeOrErr = import(Base1.getSourceRange()); |
| 1833 | if (!RangeOrErr) |
| 1834 | return RangeOrErr.takeError(); |
| 1835 | |
| 1836 | auto TSIOrErr = import(Base1.getTypeSourceInfo()); |
| 1837 | if (!TSIOrErr) |
| 1838 | return TSIOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1839 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1840 | Bases.push_back( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1841 | new (Importer.getToContext()) CXXBaseSpecifier( |
| 1842 | *RangeOrErr, |
| 1843 | Base1.isVirtual(), |
| 1844 | Base1.isBaseOfClass(), |
| 1845 | Base1.getAccessSpecifierAsWritten(), |
| 1846 | *TSIOrErr, |
| 1847 | EllipsisLoc)); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1848 | } |
| 1849 | if (!Bases.empty()) |
Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1850 | ToCXX->setBases(Bases.data(), Bases.size()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1851 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1852 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1853 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1854 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 1855 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1856 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1857 | To->completeDefinition(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1858 | return Error::success(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1859 | } |
| 1860 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1861 | Error ASTNodeImporter::ImportInitializer(VarDecl *From, VarDecl *To) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1862 | if (To->getAnyInitializer()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1863 | return Error::success(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1864 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1865 | Expr *FromInit = From->getInit(); |
| 1866 | if (!FromInit) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1867 | return Error::success(); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1868 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1869 | ExpectedExpr ToInitOrErr = import(FromInit); |
| 1870 | if (!ToInitOrErr) |
| 1871 | return ToInitOrErr.takeError(); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1872 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1873 | To->setInit(*ToInitOrErr); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1874 | if (From->isInitKnownICE()) { |
| 1875 | EvaluatedStmt *Eval = To->ensureEvaluatedStmt(); |
| 1876 | Eval->CheckedICE = true; |
| 1877 | Eval->IsICE = From->isInitICE(); |
| 1878 | } |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1879 | |
| 1880 | // FIXME: Other bits to merge? |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1881 | return Error::success(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1882 | } |
| 1883 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1884 | Error ASTNodeImporter::ImportDefinition( |
| 1885 | EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1886 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1887 | if (Kind == IDK_Everything) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1888 | return ImportDeclContext(From, /*ForceImport=*/true); |
| 1889 | return Error::success(); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1890 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1891 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1892 | To->startDefinition(); |
| 1893 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1894 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 1895 | return Err; |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1896 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1897 | ExpectedType ToTypeOrErr = |
| 1898 | import(Importer.getFromContext().getTypeDeclType(From)); |
| 1899 | if (!ToTypeOrErr) |
| 1900 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1901 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1902 | ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType()); |
| 1903 | if (!ToPromotionTypeOrErr) |
| 1904 | return ToPromotionTypeOrErr.takeError(); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1905 | |
| 1906 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1907 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 1908 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1909 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1910 | // FIXME: we might need to merge the number of positive or negative bits |
| 1911 | // if the enumerator lists don't match. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1912 | To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr, |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1913 | From->getNumPositiveBits(), |
| 1914 | From->getNumNegativeBits()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1915 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1916 | } |
| 1917 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1918 | // FIXME: Remove this, use `import` instead. |
| 1919 | Expected<TemplateParameterList *> ASTNodeImporter::ImportTemplateParameterList( |
| 1920 | TemplateParameterList *Params) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1921 | SmallVector<NamedDecl *, 4> ToParams(Params->size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1922 | if (Error Err = ImportContainerChecked(*Params, ToParams)) |
| 1923 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1924 | |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1925 | Expr *ToRequiresClause; |
| 1926 | if (Expr *const R = Params->getRequiresClause()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1927 | if (Error Err = importInto(ToRequiresClause, R)) |
| 1928 | return std::move(Err); |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1929 | } else { |
| 1930 | ToRequiresClause = nullptr; |
| 1931 | } |
| 1932 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1933 | auto ToTemplateLocOrErr = import(Params->getTemplateLoc()); |
| 1934 | if (!ToTemplateLocOrErr) |
| 1935 | return ToTemplateLocOrErr.takeError(); |
| 1936 | auto ToLAngleLocOrErr = import(Params->getLAngleLoc()); |
| 1937 | if (!ToLAngleLocOrErr) |
| 1938 | return ToLAngleLocOrErr.takeError(); |
| 1939 | auto ToRAngleLocOrErr = import(Params->getRAngleLoc()); |
| 1940 | if (!ToRAngleLocOrErr) |
| 1941 | return ToRAngleLocOrErr.takeError(); |
| 1942 | |
| 1943 | return TemplateParameterList::Create( |
| 1944 | Importer.getToContext(), |
| 1945 | *ToTemplateLocOrErr, |
| 1946 | *ToLAngleLocOrErr, |
| 1947 | ToParams, |
| 1948 | *ToRAngleLocOrErr, |
| 1949 | ToRequiresClause); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1950 | } |
| 1951 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1952 | Error ASTNodeImporter::ImportTemplateArguments( |
| 1953 | const TemplateArgument *FromArgs, unsigned NumFromArgs, |
| 1954 | SmallVectorImpl<TemplateArgument> &ToArgs) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1955 | for (unsigned I = 0; I != NumFromArgs; ++I) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1956 | if (auto ToOrErr = import(FromArgs[I])) |
| 1957 | ToArgs.push_back(*ToOrErr); |
| 1958 | else |
| 1959 | return ToOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1960 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1961 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1962 | return Error::success(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1963 | } |
| 1964 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1965 | // FIXME: Do not forget to remove this and use only 'import'. |
| 1966 | Expected<TemplateArgument> |
| 1967 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { |
| 1968 | return import(From); |
| 1969 | } |
| 1970 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1971 | template <typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1972 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1973 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { |
| 1974 | for (const auto &FromLoc : Container) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1975 | if (auto ToLocOrErr = import(FromLoc)) |
| 1976 | ToTAInfo.addArgument(*ToLocOrErr); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1977 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1978 | return ToLocOrErr.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1979 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1980 | return Error::success(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1981 | } |
| 1982 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1983 | static StructuralEquivalenceKind |
| 1984 | getStructuralEquivalenceKind(const ASTImporter &Importer) { |
| 1985 | return Importer.isMinimalImport() ? StructuralEquivalenceKind::Minimal |
| 1986 | : StructuralEquivalenceKind::Default; |
| 1987 | } |
| 1988 | |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1989 | bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) { |
| 1990 | StructuralEquivalenceContext Ctx( |
| 1991 | Importer.getFromContext(), Importer.getToContext(), |
| 1992 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1993 | false, Complain); |
| 1994 | return Ctx.IsEquivalent(From, To); |
| 1995 | } |
| 1996 | |
| 1997 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1998 | RecordDecl *ToRecord, bool Complain) { |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1999 | // Eliminate a potential failure point where we attempt to re-import |
| 2000 | // something we're trying to import while completing ToRecord. |
| 2001 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); |
| 2002 | if (ToOrigin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2003 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2004 | if (ToOriginRecord) |
| 2005 | ToRecord = ToOriginRecord; |
| 2006 | } |
| 2007 | |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 2008 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2009 | ToRecord->getASTContext(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2010 | Importer.getNonEquivalentDecls(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2011 | getStructuralEquivalenceKind(Importer), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2012 | false, Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2013 | return Ctx.IsEquivalent(FromRecord, ToRecord); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2014 | } |
| 2015 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2016 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 2017 | bool Complain) { |
| 2018 | StructuralEquivalenceContext Ctx( |
| 2019 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2020 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2021 | false, Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2022 | return Ctx.IsEquivalent(FromVar, ToVar); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2023 | } |
| 2024 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2025 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2026 | StructuralEquivalenceContext Ctx( |
| 2027 | Importer.getFromContext(), Importer.getToContext(), |
| 2028 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2029 | return Ctx.IsEquivalent(FromEnum, ToEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2030 | } |
| 2031 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2032 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, |
| 2033 | FunctionTemplateDecl *To) { |
| 2034 | StructuralEquivalenceContext Ctx( |
| 2035 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2036 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2037 | false, false); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2038 | return Ctx.IsEquivalent(From, To); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2039 | } |
| 2040 | |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2041 | bool ASTNodeImporter::IsStructuralMatch(FunctionDecl *From, FunctionDecl *To) { |
| 2042 | StructuralEquivalenceContext Ctx( |
| 2043 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2044 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2045 | false, false); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2046 | return Ctx.IsEquivalent(From, To); |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2047 | } |
| 2048 | |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2049 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2050 | EnumConstantDecl *ToEC) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2051 | const llvm::APSInt &FromVal = FromEC->getInitVal(); |
| 2052 | const llvm::APSInt &ToVal = ToEC->getInitVal(); |
| 2053 | |
| 2054 | return FromVal.isSigned() == ToVal.isSigned() && |
| 2055 | FromVal.getBitWidth() == ToVal.getBitWidth() && |
| 2056 | FromVal == ToVal; |
| 2057 | } |
| 2058 | |
| 2059 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2060 | ClassTemplateDecl *To) { |
| 2061 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2062 | Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2063 | Importer.getNonEquivalentDecls(), |
| 2064 | getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2065 | return Ctx.IsEquivalent(From, To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2066 | } |
| 2067 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2068 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, |
| 2069 | VarTemplateDecl *To) { |
| 2070 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2071 | Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2072 | Importer.getNonEquivalentDecls(), |
| 2073 | getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2074 | return Ctx.IsEquivalent(From, To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2075 | } |
| 2076 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2077 | ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 2078 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2079 | << D->getDeclKindName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2080 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2081 | } |
| 2082 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2083 | ExpectedDecl ASTNodeImporter::VisitImportDecl(ImportDecl *D) { |
| 2084 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 2085 | << D->getDeclKindName(); |
| 2086 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| 2087 | } |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2088 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2089 | ExpectedDecl ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { |
| 2090 | // Import the context of this declaration. |
| 2091 | DeclContext *DC, *LexicalDC; |
| 2092 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 2093 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2094 | |
| 2095 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2096 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2097 | if (!LocOrErr) |
| 2098 | return LocOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2099 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2100 | EmptyDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2101 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2102 | return ToD; |
| 2103 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2104 | ToD->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2105 | LexicalDC->addDeclInternal(ToD); |
| 2106 | return ToD; |
| 2107 | } |
| 2108 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2109 | ExpectedDecl ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2110 | TranslationUnitDecl *ToD = |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2111 | Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2112 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2113 | Importer.MapImported(D, ToD); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2114 | |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2115 | return ToD; |
| 2116 | } |
| 2117 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2118 | ExpectedDecl ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
| 2119 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2120 | if (!LocOrErr) |
| 2121 | return LocOrErr.takeError(); |
| 2122 | auto ColonLocOrErr = import(D->getColonLoc()); |
| 2123 | if (!ColonLocOrErr) |
| 2124 | return ColonLocOrErr.takeError(); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2125 | |
| 2126 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2127 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2128 | if (!DCOrErr) |
| 2129 | return DCOrErr.takeError(); |
| 2130 | DeclContext *DC = *DCOrErr; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2131 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2132 | AccessSpecDecl *ToD; |
| 2133 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2134 | DC, *LocOrErr, *ColonLocOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2135 | return ToD; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2136 | |
| 2137 | // Lexical DeclContext and Semantic DeclContext |
| 2138 | // is always the same for the accessSpec. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2139 | ToD->setLexicalDeclContext(DC); |
| 2140 | DC->addDeclInternal(ToD); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2141 | |
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 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2145 | ExpectedDecl ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 2146 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2147 | if (!DCOrErr) |
| 2148 | return DCOrErr.takeError(); |
| 2149 | DeclContext *DC = *DCOrErr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2150 | DeclContext *LexicalDC = DC; |
| 2151 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2152 | SourceLocation ToLocation, ToRParenLoc; |
| 2153 | Expr *ToAssertExpr; |
| 2154 | StringLiteral *ToMessage; |
| 2155 | if (auto Imp = importSeq( |
| 2156 | D->getLocation(), D->getAssertExpr(), D->getMessage(), D->getRParenLoc())) |
| 2157 | std::tie(ToLocation, ToAssertExpr, ToMessage, ToRParenLoc) = *Imp; |
| 2158 | else |
| 2159 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2160 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2161 | StaticAssertDecl *ToD; |
| 2162 | if (GetImportedOrCreateDecl( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2163 | ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage, |
| 2164 | ToRParenLoc, D->isFailed())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2165 | return ToD; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2166 | |
| 2167 | ToD->setLexicalDeclContext(LexicalDC); |
| 2168 | LexicalDC->addDeclInternal(ToD); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2169 | return ToD; |
| 2170 | } |
| 2171 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2172 | ExpectedDecl ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2173 | // Import the major distinguishing characteristics of this namespace. |
| 2174 | DeclContext *DC, *LexicalDC; |
| 2175 | DeclarationName Name; |
| 2176 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2177 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2178 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2179 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2180 | if (ToD) |
| 2181 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2182 | |
| 2183 | NamespaceDecl *MergeWithNamespace = nullptr; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2184 | if (!Name) { |
| 2185 | // This is an anonymous namespace. Adopt an existing anonymous |
| 2186 | // namespace if we can. |
| 2187 | // FIXME: Not testable. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2188 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2189 | MergeWithNamespace = TU->getAnonymousNamespace(); |
| 2190 | else |
| 2191 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); |
| 2192 | } else { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2193 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2194 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2195 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2196 | for (auto *FoundDecl : FoundDecls) { |
| 2197 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2198 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2199 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2200 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2201 | MergeWithNamespace = FoundNS; |
| 2202 | ConflictingDecls.clear(); |
| 2203 | break; |
| 2204 | } |
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 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2207 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2208 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2209 | if (!ConflictingDecls.empty()) { |
John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 2210 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2211 | ConflictingDecls.data(), |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2212 | ConflictingDecls.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2213 | if (!Name) |
| 2214 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2215 | } |
| 2216 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2217 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2218 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2219 | if (!BeginLocOrErr) |
| 2220 | return BeginLocOrErr.takeError(); |
| 2221 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2222 | // Create the "to" namespace, if needed. |
| 2223 | NamespaceDecl *ToNamespace = MergeWithNamespace; |
| 2224 | if (!ToNamespace) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2225 | if (GetImportedOrCreateDecl( |
| 2226 | ToNamespace, D, Importer.getToContext(), DC, D->isInline(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2227 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2228 | /*PrevDecl=*/nullptr)) |
| 2229 | return ToNamespace; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2230 | ToNamespace->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2231 | LexicalDC->addDeclInternal(ToNamespace); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2232 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2233 | // If this is an anonymous namespace, register it as the anonymous |
| 2234 | // namespace within its context. |
| 2235 | if (!Name) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2236 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2237 | TU->setAnonymousNamespace(ToNamespace); |
| 2238 | else |
| 2239 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); |
| 2240 | } |
| 2241 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2242 | Importer.MapImported(D, ToNamespace); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2243 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2244 | if (Error Err = ImportDeclContext(D)) |
| 2245 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2246 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2247 | return ToNamespace; |
| 2248 | } |
| 2249 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2250 | ExpectedDecl ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2251 | // Import the major distinguishing characteristics of this namespace. |
| 2252 | DeclContext *DC, *LexicalDC; |
| 2253 | DeclarationName Name; |
| 2254 | SourceLocation Loc; |
| 2255 | NamedDecl *LookupD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2256 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) |
| 2257 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2258 | if (LookupD) |
| 2259 | return LookupD; |
| 2260 | |
| 2261 | // NOTE: No conflict resolution is done for namespace aliases now. |
| 2262 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2263 | SourceLocation ToNamespaceLoc, ToAliasLoc, ToTargetNameLoc; |
| 2264 | NestedNameSpecifierLoc ToQualifierLoc; |
| 2265 | NamespaceDecl *ToNamespace; |
| 2266 | if (auto Imp = importSeq( |
| 2267 | D->getNamespaceLoc(), D->getAliasLoc(), D->getQualifierLoc(), |
| 2268 | D->getTargetNameLoc(), D->getNamespace())) |
| 2269 | std::tie( |
| 2270 | ToNamespaceLoc, ToAliasLoc, ToQualifierLoc, ToTargetNameLoc, |
| 2271 | ToNamespace) = *Imp; |
| 2272 | else |
| 2273 | return Imp.takeError(); |
| 2274 | IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier()); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2275 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2276 | NamespaceAliasDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2277 | if (GetImportedOrCreateDecl( |
| 2278 | ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc, |
| 2279 | ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2280 | return ToD; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2281 | |
| 2282 | ToD->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2283 | LexicalDC->addDeclInternal(ToD); |
| 2284 | |
| 2285 | return ToD; |
| 2286 | } |
| 2287 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2288 | ExpectedDecl |
| 2289 | ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2290 | // Import the major distinguishing characteristics of this typedef. |
| 2291 | DeclContext *DC, *LexicalDC; |
| 2292 | DeclarationName Name; |
| 2293 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2294 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2295 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2296 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2297 | if (ToD) |
| 2298 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2299 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2300 | // If this typedef is not in block scope, determine whether we've |
| 2301 | // seen a typedef with the same name (that we can merge with) or any |
| 2302 | // other entity by that name (which name lookup could conflict with). |
| 2303 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2304 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2305 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2306 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2307 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2308 | for (auto *FoundDecl : FoundDecls) { |
| 2309 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2310 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2311 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2312 | if (Importer.IsStructurallyEquivalent( |
| 2313 | D->getUnderlyingType(), FoundTypedef->getUnderlyingType())) |
| 2314 | return Importer.MapImported(D, FoundTypedef); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2315 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2316 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2317 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2318 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2319 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2320 | if (!ConflictingDecls.empty()) { |
| 2321 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2322 | ConflictingDecls.data(), |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2323 | ConflictingDecls.size()); |
| 2324 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2325 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2326 | } |
| 2327 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2328 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2329 | QualType ToUnderlyingType; |
| 2330 | TypeSourceInfo *ToTypeSourceInfo; |
| 2331 | SourceLocation ToBeginLoc; |
| 2332 | if (auto Imp = importSeq( |
| 2333 | D->getUnderlyingType(), D->getTypeSourceInfo(), D->getBeginLoc())) |
| 2334 | std::tie(ToUnderlyingType, ToTypeSourceInfo, ToBeginLoc) = *Imp; |
| 2335 | else |
| 2336 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2337 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2338 | // Create the new typedef node. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2339 | // FIXME: ToUnderlyingType is not used. |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2340 | TypedefNameDecl *ToTypedef; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2341 | if (IsAlias) { |
| 2342 | if (GetImportedOrCreateDecl<TypeAliasDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2343 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2344 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2345 | return ToTypedef; |
| 2346 | } else if (GetImportedOrCreateDecl<TypedefDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2347 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2348 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2349 | return ToTypedef; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2350 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2351 | ToTypedef->setAccess(D->getAccess()); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2352 | ToTypedef->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2353 | |
| 2354 | // Templated declarations should not appear in DeclContext. |
| 2355 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; |
| 2356 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) |
| 2357 | LexicalDC->addDeclInternal(ToTypedef); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2358 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2359 | return ToTypedef; |
| 2360 | } |
| 2361 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2362 | ExpectedDecl ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2363 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); |
| 2364 | } |
| 2365 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2366 | ExpectedDecl ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2367 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); |
| 2368 | } |
| 2369 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2370 | ExpectedDecl |
| 2371 | ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2372 | // Import the major distinguishing characteristics of this typedef. |
| 2373 | DeclContext *DC, *LexicalDC; |
| 2374 | DeclarationName Name; |
| 2375 | SourceLocation Loc; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2376 | NamedDecl *FoundD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2377 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) |
| 2378 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2379 | if (FoundD) |
| 2380 | return FoundD; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2381 | |
| 2382 | // If this typedef is not in block scope, determine whether we've |
| 2383 | // seen a typedef with the same name (that we can merge with) or any |
| 2384 | // other entity by that name (which name lookup could conflict with). |
| 2385 | if (!DC->isFunctionOrMethod()) { |
| 2386 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 2387 | unsigned IDNS = Decl::IDNS_Ordinary; |
| 2388 | SmallVector<NamedDecl *, 2> FoundDecls; |
| 2389 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2390 | for (auto *FoundDecl : FoundDecls) { |
| 2391 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2392 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2393 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2394 | return Importer.MapImported(D, FoundAlias); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2395 | ConflictingDecls.push_back(FoundDecl); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2396 | } |
| 2397 | |
| 2398 | if (!ConflictingDecls.empty()) { |
| 2399 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2400 | ConflictingDecls.data(), |
| 2401 | ConflictingDecls.size()); |
| 2402 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2403 | return make_error<ImportError>(ImportError::NameConflict); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2404 | } |
| 2405 | } |
| 2406 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2407 | TemplateParameterList *ToTemplateParameters; |
| 2408 | TypeAliasDecl *ToTemplatedDecl; |
| 2409 | if (auto Imp = importSeq(D->getTemplateParameters(), D->getTemplatedDecl())) |
| 2410 | std::tie(ToTemplateParameters, ToTemplatedDecl) = *Imp; |
| 2411 | else |
| 2412 | return Imp.takeError(); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2413 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2414 | TypeAliasTemplateDecl *ToAlias; |
| 2415 | if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2416 | Name, ToTemplateParameters, ToTemplatedDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2417 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2418 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2419 | ToTemplatedDecl->setDescribedAliasTemplate(ToAlias); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2420 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2421 | ToAlias->setAccess(D->getAccess()); |
| 2422 | ToAlias->setLexicalDeclContext(LexicalDC); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2423 | LexicalDC->addDeclInternal(ToAlias); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2424 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2425 | } |
| 2426 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2427 | ExpectedDecl ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2428 | // Import the major distinguishing characteristics of this label. |
| 2429 | DeclContext *DC, *LexicalDC; |
| 2430 | DeclarationName Name; |
| 2431 | SourceLocation Loc; |
| 2432 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2433 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2434 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2435 | if (ToD) |
| 2436 | return ToD; |
| 2437 | |
| 2438 | assert(LexicalDC->isFunctionOrMethod()); |
| 2439 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2440 | LabelDecl *ToLabel; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2441 | if (D->isGnuLocal()) { |
| 2442 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2443 | if (!BeginLocOrErr) |
| 2444 | return BeginLocOrErr.takeError(); |
| 2445 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2446 | Name.getAsIdentifierInfo(), *BeginLocOrErr)) |
| 2447 | return ToLabel; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2448 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2449 | } else { |
| 2450 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2451 | Name.getAsIdentifierInfo())) |
| 2452 | return ToLabel; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2453 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2454 | } |
| 2455 | |
| 2456 | Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt()); |
| 2457 | if (!ToStmtOrErr) |
| 2458 | return ToStmtOrErr.takeError(); |
| 2459 | |
| 2460 | ToLabel->setStmt(*ToStmtOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2461 | ToLabel->setLexicalDeclContext(LexicalDC); |
| 2462 | LexicalDC->addDeclInternal(ToLabel); |
| 2463 | return ToLabel; |
| 2464 | } |
| 2465 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2466 | ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2467 | // Import the major distinguishing characteristics of this enum. |
| 2468 | DeclContext *DC, *LexicalDC; |
| 2469 | DeclarationName Name; |
| 2470 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2471 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2472 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2473 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2474 | if (ToD) |
| 2475 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2476 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2477 | // Figure out what enum name we're looking for. |
| 2478 | unsigned IDNS = Decl::IDNS_Tag; |
| 2479 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2480 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2481 | if (Error Err = importInto( |
| 2482 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2483 | return std::move(Err); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2484 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2485 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2486 | IDNS |= Decl::IDNS_Ordinary; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2487 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2488 | // We may already have an enum of the same name; try to find and match it. |
| 2489 | if (!DC->isFunctionOrMethod() && SearchName) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2490 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2491 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 2492 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2493 | for (auto *FoundDecl : FoundDecls) { |
| 2494 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2495 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2496 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2497 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2498 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2499 | FoundDecl = Tag->getDecl(); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2500 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2501 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2502 | if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) { |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2503 | if (IsStructuralMatch(D, FoundEnum)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2504 | return Importer.MapImported(D, FoundEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2505 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2506 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2507 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2508 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2509 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2510 | if (!ConflictingDecls.empty()) { |
| 2511 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2512 | ConflictingDecls.data(), |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2513 | ConflictingDecls.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2514 | if (!Name) |
| 2515 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2516 | } |
| 2517 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2518 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2519 | SourceLocation ToBeginLoc; |
| 2520 | NestedNameSpecifierLoc ToQualifierLoc; |
| 2521 | QualType ToIntegerType; |
| 2522 | if (auto Imp = importSeq( |
| 2523 | D->getBeginLoc(), D->getQualifierLoc(), D->getIntegerType())) |
| 2524 | std::tie(ToBeginLoc, ToQualifierLoc, ToIntegerType) = *Imp; |
| 2525 | else |
| 2526 | return Imp.takeError(); |
| 2527 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2528 | // Create the enum declaration. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2529 | EnumDecl *D2; |
| 2530 | if (GetImportedOrCreateDecl( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2531 | D2, D, Importer.getToContext(), DC, ToBeginLoc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2532 | Loc, Name.getAsIdentifierInfo(), nullptr, D->isScoped(), |
| 2533 | D->isScopedUsingClassTag(), D->isFixed())) |
| 2534 | return D2; |
| 2535 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2536 | D2->setQualifierInfo(ToQualifierLoc); |
| 2537 | D2->setIntegerType(ToIntegerType); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2538 | D2->setAccess(D->getAccess()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2539 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2540 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2541 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2542 | // Import the definition |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2543 | if (D->isCompleteDefinition()) |
| 2544 | if (Error Err = ImportDefinition(D, D2)) |
| 2545 | return std::move(Err); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2546 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2547 | return D2; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2548 | } |
| 2549 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2550 | ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2551 | bool IsFriendTemplate = false; |
| 2552 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2553 | IsFriendTemplate = |
| 2554 | DCXX->getDescribedClassTemplate() && |
| 2555 | DCXX->getDescribedClassTemplate()->getFriendObjectKind() != |
| 2556 | Decl::FOK_None; |
| 2557 | } |
| 2558 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2559 | // If this record has a definition in the translation unit we're coming from, |
| 2560 | // but this particular declaration is not that definition, import the |
| 2561 | // definition and map to that. |
Douglas Gregor | 0a5a221 | 2010-02-11 01:04:33 +0000 | [diff] [blame] | 2562 | TagDecl *Definition = D->getDefinition(); |
Gabor Marton | a3af567 | 2018-05-23 14:24:02 +0000 | [diff] [blame] | 2563 | if (Definition && Definition != D && |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2564 | // Friend template declaration must be imported on its own. |
| 2565 | !IsFriendTemplate && |
Gabor Marton | a3af567 | 2018-05-23 14:24:02 +0000 | [diff] [blame] | 2566 | // In contrast to a normal CXXRecordDecl, the implicit |
| 2567 | // CXXRecordDecl of ClassTemplateSpecializationDecl is its redeclaration. |
| 2568 | // The definition of the implicit CXXRecordDecl in this case is the |
| 2569 | // ClassTemplateSpecializationDecl itself. Thus, we start with an extra |
| 2570 | // condition in order to be able to import the implict Decl. |
| 2571 | !D->isImplicit()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2572 | ExpectedDecl ImportedDefOrErr = import(Definition); |
| 2573 | if (!ImportedDefOrErr) |
| 2574 | return ImportedDefOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2575 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2576 | return Importer.MapImported(D, *ImportedDefOrErr); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2577 | } |
Gabor Marton | a3af567 | 2018-05-23 14:24:02 +0000 | [diff] [blame] | 2578 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2579 | // Import the major distinguishing characteristics of this record. |
| 2580 | DeclContext *DC, *LexicalDC; |
| 2581 | DeclarationName Name; |
| 2582 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2583 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2584 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2585 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2586 | if (ToD) |
| 2587 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2588 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2589 | // Figure out what structure name we're looking for. |
| 2590 | unsigned IDNS = Decl::IDNS_Tag; |
| 2591 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2592 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2593 | if (Error Err = importInto( |
| 2594 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2595 | return std::move(Err); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2596 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2597 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2598 | IDNS |= Decl::IDNS_Ordinary; |
| 2599 | |
| 2600 | // We may already have a record of the same name; try to find and match it. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2601 | RecordDecl *AdoptDecl = nullptr; |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2602 | RecordDecl *PrevDecl = nullptr; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2603 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2604 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2605 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 2606 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2607 | |
| 2608 | if (!FoundDecls.empty()) { |
| 2609 | // We're going to have to compare D against potentially conflicting Decls, so complete it. |
| 2610 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) |
| 2611 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 2612 | } |
| 2613 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2614 | for (auto *FoundDecl : FoundDecls) { |
| 2615 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2616 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2617 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2618 | Decl *Found = FoundDecl; |
| 2619 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 2620 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2621 | Found = Tag->getDecl(); |
| 2622 | } |
Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2623 | |
| 2624 | if (D->getDescribedTemplate()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2625 | if (auto *Template = dyn_cast<ClassTemplateDecl>(Found)) { |
Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2626 | Found = Template->getTemplatedDecl(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2627 | } else { |
| 2628 | ConflictingDecls.push_back(FoundDecl); |
Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2629 | continue; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2630 | } |
Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2631 | } |
| 2632 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2633 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { |
Aleksei Sidorin | 499de6c | 2018-04-05 15:31:49 +0000 | [diff] [blame] | 2634 | if (!SearchName) { |
Gabor Marton | 0bebf95 | 2018-07-05 09:51:13 +0000 | [diff] [blame] | 2635 | if (!IsStructuralMatch(D, FoundRecord, false)) |
| 2636 | continue; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2637 | } else { |
| 2638 | if (!IsStructuralMatch(D, FoundRecord)) { |
| 2639 | ConflictingDecls.push_back(FoundDecl); |
| 2640 | continue; |
| 2641 | } |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2642 | } |
| 2643 | |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2644 | PrevDecl = FoundRecord; |
| 2645 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2646 | if (RecordDecl *FoundDef = FoundRecord->getDefinition()) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2647 | if ((SearchName && !D->isCompleteDefinition() && !IsFriendTemplate) |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2648 | || (D->isCompleteDefinition() && |
| 2649 | D->isAnonymousStructOrUnion() |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2650 | == FoundDef->isAnonymousStructOrUnion())) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2651 | // The record types structurally match, or the "from" translation |
| 2652 | // unit only had a forward declaration anyway; call it the same |
| 2653 | // function. |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2654 | // FIXME: Structural equivalence check should check for same |
| 2655 | // user-defined methods. |
| 2656 | Importer.MapImported(D, FoundDef); |
| 2657 | if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2658 | auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef); |
| 2659 | assert(FoundCXX && "Record type mismatch"); |
| 2660 | |
| 2661 | if (D->isCompleteDefinition() && !Importer.isMinimalImport()) |
| 2662 | // FoundDef may not have every implicit method that D has |
| 2663 | // because implicit methods are created only if they are used. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2664 | if (Error Err = ImportImplicitMethods(DCXX, FoundCXX)) |
| 2665 | return std::move(Err); |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2666 | } |
| 2667 | return FoundDef; |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2668 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2669 | if (IsFriendTemplate) |
| 2670 | continue; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2671 | } else if (!D->isCompleteDefinition()) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2672 | // We have a forward declaration of this type, so adopt that forward |
| 2673 | // declaration rather than building a new one. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2674 | |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 2675 | // If one or both can be completed from external storage then try one |
| 2676 | // last time to complete and compare them before doing this. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2677 | |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 2678 | if (FoundRecord->hasExternalLexicalStorage() && |
| 2679 | !FoundRecord->isCompleteDefinition()) |
| 2680 | FoundRecord->getASTContext().getExternalSource()->CompleteType(FoundRecord); |
| 2681 | if (D->hasExternalLexicalStorage()) |
| 2682 | D->getASTContext().getExternalSource()->CompleteType(D); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2683 | |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 2684 | if (FoundRecord->isCompleteDefinition() && |
| 2685 | D->isCompleteDefinition() && |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2686 | !IsStructuralMatch(D, FoundRecord)) { |
| 2687 | ConflictingDecls.push_back(FoundDecl); |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 2688 | continue; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2689 | } |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2690 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2691 | AdoptDecl = FoundRecord; |
| 2692 | continue; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2693 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2694 | |
| 2695 | continue; |
| 2696 | } else if (isa<ValueDecl>(Found)) |
| 2697 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2698 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2699 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2700 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2701 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2702 | if (!ConflictingDecls.empty() && SearchName) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2703 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2704 | ConflictingDecls.data(), |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2705 | ConflictingDecls.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2706 | if (!Name) |
| 2707 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2708 | } |
| 2709 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2710 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2711 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2712 | if (!BeginLocOrErr) |
| 2713 | return BeginLocOrErr.takeError(); |
| 2714 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2715 | // Create the record declaration. |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2716 | RecordDecl *D2 = AdoptDecl; |
| 2717 | if (!D2) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2718 | CXXRecordDecl *D2CXX = nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2719 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2720 | if (DCXX->isLambda()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2721 | auto TInfoOrErr = import(DCXX->getLambdaTypeInfo()); |
| 2722 | if (!TInfoOrErr) |
| 2723 | return TInfoOrErr.takeError(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2724 | if (GetImportedOrCreateSpecialDecl( |
| 2725 | D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2726 | DC, *TInfoOrErr, Loc, DCXX->isDependentLambda(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2727 | DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault())) |
| 2728 | return D2CXX; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2729 | ExpectedDecl CDeclOrErr = import(DCXX->getLambdaContextDecl()); |
| 2730 | if (!CDeclOrErr) |
| 2731 | return CDeclOrErr.takeError(); |
| 2732 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), *CDeclOrErr); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2733 | } else if (DCXX->isInjectedClassName()) { |
| 2734 | // We have to be careful to do a similar dance to the one in |
| 2735 | // Sema::ActOnStartCXXMemberDeclarations |
| 2736 | CXXRecordDecl *const PrevDecl = nullptr; |
| 2737 | const bool DelayTypeCreation = true; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2738 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2739 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2740 | Name.getAsIdentifierInfo(), PrevDecl, |
| 2741 | DelayTypeCreation)) |
| 2742 | return D2CXX; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2743 | Importer.getToContext().getTypeDeclType( |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2744 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2745 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2746 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2747 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2748 | Name.getAsIdentifierInfo(), |
| 2749 | cast_or_null<CXXRecordDecl>(PrevDecl))) |
| 2750 | return D2CXX; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2751 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2752 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2753 | D2 = D2CXX; |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2754 | D2->setAccess(D->getAccess()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2755 | D2->setLexicalDeclContext(LexicalDC); |
Gabor Marton | de8bf26 | 2018-05-17 09:46:07 +0000 | [diff] [blame] | 2756 | if (!DCXX->getDescribedClassTemplate() || DCXX->isImplicit()) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2757 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2758 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2759 | if (ClassTemplateDecl *FromDescribed = |
| 2760 | DCXX->getDescribedClassTemplate()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2761 | ClassTemplateDecl *ToDescribed; |
| 2762 | if (Error Err = importInto(ToDescribed, FromDescribed)) |
| 2763 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2764 | D2CXX->setDescribedClassTemplate(ToDescribed); |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2765 | if (!DCXX->isInjectedClassName() && !IsFriendTemplate) { |
Gabor Marton | 5915777e | 2018-06-26 13:44:24 +0000 | [diff] [blame] | 2766 | // In a record describing a template the type should be an |
| 2767 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the |
| 2768 | // previously set type to the correct value here (ToDescribed is not |
| 2769 | // available at record create). |
| 2770 | // FIXME: The previous type is cleared but not removed from |
| 2771 | // ASTContext's internal storage. |
| 2772 | CXXRecordDecl *Injected = nullptr; |
| 2773 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { |
| 2774 | auto *Record = dyn_cast<CXXRecordDecl>(Found); |
| 2775 | if (Record && Record->isInjectedClassName()) { |
| 2776 | Injected = Record; |
| 2777 | break; |
| 2778 | } |
| 2779 | } |
| 2780 | D2CXX->setTypeForDecl(nullptr); |
| 2781 | Importer.getToContext().getInjectedClassNameType(D2CXX, |
| 2782 | ToDescribed->getInjectedClassNameSpecialization()); |
| 2783 | if (Injected) { |
| 2784 | Injected->setTypeForDecl(nullptr); |
| 2785 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); |
| 2786 | } |
| 2787 | } |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2788 | } else if (MemberSpecializationInfo *MemberInfo = |
| 2789 | DCXX->getMemberSpecializationInfo()) { |
| 2790 | TemplateSpecializationKind SK = |
| 2791 | MemberInfo->getTemplateSpecializationKind(); |
| 2792 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2793 | |
| 2794 | if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst)) |
| 2795 | D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK); |
| 2796 | else |
| 2797 | return ToInstOrErr.takeError(); |
| 2798 | |
| 2799 | if (ExpectedSLoc POIOrErr = |
| 2800 | import(MemberInfo->getPointOfInstantiation())) |
| 2801 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( |
| 2802 | *POIOrErr); |
| 2803 | else |
| 2804 | return POIOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2805 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2806 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2807 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2808 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2809 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2810 | Name.getAsIdentifierInfo(), PrevDecl)) |
| 2811 | return D2; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2812 | D2->setLexicalDeclContext(LexicalDC); |
| 2813 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2814 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2815 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2816 | if (auto QualifierLocOrErr = import(D->getQualifierLoc())) |
| 2817 | D2->setQualifierInfo(*QualifierLocOrErr); |
| 2818 | else |
| 2819 | return QualifierLocOrErr.takeError(); |
| 2820 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2821 | if (D->isAnonymousStructOrUnion()) |
| 2822 | D2->setAnonymousStructOrUnion(true); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2823 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2824 | |
| 2825 | Importer.MapImported(D, D2); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2826 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2827 | if (D->isCompleteDefinition()) |
| 2828 | if (Error Err = ImportDefinition(D, D2, IDK_Default)) |
| 2829 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2830 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2831 | return D2; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2832 | } |
| 2833 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2834 | ExpectedDecl ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2835 | // Import the major distinguishing characteristics of this enumerator. |
| 2836 | DeclContext *DC, *LexicalDC; |
| 2837 | DeclarationName Name; |
| 2838 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2839 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2840 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2841 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2842 | if (ToD) |
| 2843 | return ToD; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2844 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2845 | // Determine whether there are any other declarations with the same name and |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2846 | // in the same context. |
| 2847 | if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2848 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2849 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2850 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2851 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2852 | for (auto *FoundDecl : FoundDecls) { |
| 2853 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2854 | continue; |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2855 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2856 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2857 | if (IsStructuralMatch(D, FoundEnumConstant)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2858 | return Importer.MapImported(D, FoundEnumConstant); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2859 | } |
| 2860 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2861 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2862 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2863 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2864 | if (!ConflictingDecls.empty()) { |
| 2865 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2866 | ConflictingDecls.data(), |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2867 | ConflictingDecls.size()); |
| 2868 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2869 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2870 | } |
| 2871 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2872 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2873 | ExpectedType TypeOrErr = import(D->getType()); |
| 2874 | if (!TypeOrErr) |
| 2875 | return TypeOrErr.takeError(); |
| 2876 | |
| 2877 | ExpectedExpr InitOrErr = import(D->getInitExpr()); |
| 2878 | if (!InitOrErr) |
| 2879 | return InitOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2880 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2881 | EnumConstantDecl *ToEnumerator; |
| 2882 | if (GetImportedOrCreateDecl( |
| 2883 | ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2884 | Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2885 | return ToEnumerator; |
| 2886 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2887 | ToEnumerator->setAccess(D->getAccess()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2888 | ToEnumerator->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2889 | LexicalDC->addDeclInternal(ToEnumerator); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2890 | return ToEnumerator; |
| 2891 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2892 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2893 | Error ASTNodeImporter::ImportTemplateInformation( |
| 2894 | FunctionDecl *FromFD, FunctionDecl *ToFD) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2895 | switch (FromFD->getTemplatedKind()) { |
| 2896 | case FunctionDecl::TK_NonTemplate: |
| 2897 | case FunctionDecl::TK_FunctionTemplate: |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2898 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2899 | |
| 2900 | case FunctionDecl::TK_MemberSpecialization: { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2901 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2902 | |
| 2903 | if (Expected<FunctionDecl *> InstFDOrErr = |
| 2904 | import(FromFD->getInstantiatedFromMemberFunction())) |
| 2905 | ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK); |
| 2906 | else |
| 2907 | return InstFDOrErr.takeError(); |
| 2908 | |
| 2909 | if (ExpectedSLoc POIOrErr = import( |
| 2910 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation())) |
| 2911 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr); |
| 2912 | else |
| 2913 | return POIOrErr.takeError(); |
| 2914 | |
| 2915 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2916 | } |
| 2917 | |
| 2918 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2919 | auto FunctionAndArgsOrErr = |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2920 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2921 | if (!FunctionAndArgsOrErr) |
| 2922 | return FunctionAndArgsOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2923 | |
| 2924 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2925 | Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr)); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2926 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2927 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2928 | TemplateArgumentListInfo ToTAInfo; |
| 2929 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2930 | if (FromTAArgsAsWritten) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2931 | if (Error Err = ImportTemplateArgumentListInfo( |
| 2932 | *FromTAArgsAsWritten, ToTAInfo)) |
| 2933 | return Err; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2934 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2935 | ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation()); |
| 2936 | if (!POIOrErr) |
| 2937 | return POIOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2938 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2939 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2940 | ToFD->setFunctionTemplateSpecialization( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2941 | std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr, |
| 2942 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr); |
| 2943 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2944 | } |
| 2945 | |
| 2946 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 2947 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); |
| 2948 | UnresolvedSet<8> TemplDecls; |
| 2949 | unsigned NumTemplates = FromInfo->getNumTemplates(); |
| 2950 | for (unsigned I = 0; I < NumTemplates; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2951 | if (Expected<FunctionTemplateDecl *> ToFTDOrErr = |
| 2952 | import(FromInfo->getTemplate(I))) |
| 2953 | TemplDecls.addDecl(*ToFTDOrErr); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2954 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2955 | return ToFTDOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2956 | } |
| 2957 | |
| 2958 | // Import TemplateArgumentListInfo. |
| 2959 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2960 | if (Error Err = ImportTemplateArgumentListInfo( |
| 2961 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), |
| 2962 | llvm::makeArrayRef( |
| 2963 | FromInfo->getTemplateArgs(), FromInfo->getNumTemplateArgs()), |
| 2964 | ToTAInfo)) |
| 2965 | return Err; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2966 | |
| 2967 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), |
| 2968 | TemplDecls, ToTAInfo); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2969 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2970 | } |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2971 | } |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2972 | llvm_unreachable("All cases should be covered!"); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2973 | } |
| 2974 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2975 | Expected<FunctionDecl *> |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2976 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2977 | auto FunctionAndArgsOrErr = |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2978 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2979 | if (!FunctionAndArgsOrErr) |
| 2980 | return FunctionAndArgsOrErr.takeError(); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2981 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2982 | FunctionTemplateDecl *Template; |
| 2983 | TemplateArgsTy ToTemplArgs; |
| 2984 | std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2985 | void *InsertPos = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2986 | auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2987 | return FoundSpec; |
| 2988 | } |
| 2989 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2990 | ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2991 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2992 | SmallVector<Decl *, 2> Redecls = getCanonicalForwardRedeclChain(D); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2993 | auto RedeclIt = Redecls.begin(); |
| 2994 | // Import the first part of the decl chain. I.e. import all previous |
| 2995 | // declarations starting from the canonical decl. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2996 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 2997 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 2998 | if (!ToRedeclOrErr) |
| 2999 | return ToRedeclOrErr.takeError(); |
| 3000 | } |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3001 | assert(*RedeclIt == D); |
| 3002 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3003 | // Import the major distinguishing characteristics of this function. |
| 3004 | DeclContext *DC, *LexicalDC; |
| 3005 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3006 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3007 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3008 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3009 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3010 | if (ToD) |
| 3011 | return ToD; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3012 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3013 | const FunctionDecl *FoundByLookup = nullptr; |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3014 | FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 3015 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3016 | // If this is a function template specialization, then try to find the same |
| 3017 | // existing specialization in the "to" context. The localUncachedLookup |
| 3018 | // below will not find any specialization, but would find the primary |
| 3019 | // template; thus, we have to skip normal lookup in case of specializations. |
| 3020 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? |
| 3021 | if (D->getTemplatedKind() == |
| 3022 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3023 | auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D); |
| 3024 | if (!FoundFunctionOrErr) |
| 3025 | return FoundFunctionOrErr.takeError(); |
| 3026 | if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) { |
| 3027 | if (D->doesThisDeclarationHaveABody() && FoundFunction->hasBody()) |
| 3028 | return Importer.MapImported(D, FoundFunction); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3029 | FoundByLookup = FoundFunction; |
| 3030 | } |
| 3031 | } |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3032 | // Try to find a function in our own ("to") context with the same name, same |
| 3033 | // type, and in the same context as the function we're importing. |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3034 | else if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3035 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3036 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3037 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3038 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3039 | for (auto *FoundDecl : FoundDecls) { |
| 3040 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3041 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3042 | |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3043 | // If template was found, look at the templated function. |
| 3044 | if (FromFT) { |
| 3045 | if (auto *Template = dyn_cast<FunctionTemplateDecl>(FoundDecl)) |
| 3046 | FoundDecl = Template->getTemplatedDecl(); |
| 3047 | else |
| 3048 | continue; |
| 3049 | } |
| 3050 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3051 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { |
Rafael Espindola | 3ae0005 | 2013-05-13 00:12:11 +0000 | [diff] [blame] | 3052 | if (FoundFunction->hasExternalFormalLinkage() && |
| 3053 | D->hasExternalFormalLinkage()) { |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 3054 | if (IsStructuralMatch(D, FoundFunction)) { |
| 3055 | const FunctionDecl *Definition = nullptr; |
| 3056 | if (D->doesThisDeclarationHaveABody() && |
| 3057 | FoundFunction->hasBody(Definition)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3058 | return Importer.MapImported( |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 3059 | D, const_cast<FunctionDecl *>(Definition)); |
| 3060 | } |
| 3061 | FoundByLookup = FoundFunction; |
| 3062 | break; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3063 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3064 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3065 | // FIXME: Check for overloading more carefully, e.g., by boosting |
| 3066 | // Sema::IsOverload out to the AST library. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3067 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3068 | // Function overloading is okay in C++. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3069 | if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3070 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3071 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3072 | // Complain about inconsistent function types. |
| 3073 | Importer.ToDiag(Loc, diag::err_odr_function_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3074 | << Name << D->getType() << FoundFunction->getType(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3075 | Importer.ToDiag(FoundFunction->getLocation(), |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3076 | diag::note_odr_value_here) |
| 3077 | << FoundFunction->getType(); |
| 3078 | } |
| 3079 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3080 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3081 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3082 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3083 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3084 | if (!ConflictingDecls.empty()) { |
| 3085 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3086 | ConflictingDecls.data(), |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3087 | ConflictingDecls.size()); |
| 3088 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3089 | return make_error<ImportError>(ImportError::NameConflict); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3090 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3091 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3092 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3093 | DeclarationNameInfo NameInfo(Name, Loc); |
| 3094 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3095 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 3096 | return std::move(Err); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3097 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3098 | QualType FromTy = D->getType(); |
| 3099 | bool usedDifferentExceptionSpec = false; |
| 3100 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3101 | if (const auto *FromFPT = D->getType()->getAs<FunctionProtoType>()) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3102 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); |
| 3103 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the |
| 3104 | // FunctionDecl that we are importing the FunctionProtoType for. |
| 3105 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| 3106 | // with a simplified function type and update it afterwards. |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 3107 | if (FromEPI.ExceptionSpec.SourceDecl || |
| 3108 | FromEPI.ExceptionSpec.SourceTemplate || |
| 3109 | FromEPI.ExceptionSpec.NoexceptExpr) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3110 | FunctionProtoType::ExtProtoInfo DefaultEPI; |
| 3111 | FromTy = Importer.getFromContext().getFunctionType( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3112 | FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI); |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3113 | usedDifferentExceptionSpec = true; |
| 3114 | } |
| 3115 | } |
| 3116 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3117 | QualType T; |
| 3118 | TypeSourceInfo *TInfo; |
| 3119 | SourceLocation ToInnerLocStart, ToEndLoc; |
| 3120 | NestedNameSpecifierLoc ToQualifierLoc; |
| 3121 | if (auto Imp = importSeq( |
| 3122 | FromTy, D->getTypeSourceInfo(), D->getInnerLocStart(), |
| 3123 | D->getQualifierLoc(), D->getEndLoc())) |
| 3124 | std::tie(T, TInfo, ToInnerLocStart, ToQualifierLoc, ToEndLoc) = *Imp; |
| 3125 | else |
| 3126 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3127 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3128 | // Import the function parameters. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3129 | SmallVector<ParmVarDecl *, 8> Parameters; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3130 | for (auto P : D->parameters()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3131 | if (Expected<ParmVarDecl *> ToPOrErr = import(P)) |
| 3132 | Parameters.push_back(*ToPOrErr); |
| 3133 | else |
| 3134 | return ToPOrErr.takeError(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3135 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3136 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3137 | // Create the imported function. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3138 | FunctionDecl *ToFunction = nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3139 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3140 | if (GetImportedOrCreateDecl<CXXConstructorDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3141 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3142 | ToInnerLocStart, NameInfo, T, TInfo, |
| 3143 | FromConstructor->isExplicit(), |
| 3144 | D->isInlineSpecified(), D->isImplicit(), D->isConstexpr())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3145 | return ToFunction; |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 3146 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3147 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers); |
| 3148 | // Import first, then allocate memory and copy if there was no error. |
| 3149 | if (Error Err = ImportContainerChecked( |
| 3150 | FromConstructor->inits(), CtorInitializers)) |
| 3151 | return std::move(Err); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3152 | auto **Memory = |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 3153 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 3154 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3155 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 3156 | ToCtor->setCtorInitializers(Memory); |
| 3157 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 3158 | } |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3159 | } else if (isa<CXXDestructorDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3160 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3161 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3162 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| 3163 | D->isImplicit())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3164 | return ToFunction; |
| 3165 | } else if (CXXConversionDecl *FromConversion = |
| 3166 | dyn_cast<CXXConversionDecl>(D)) { |
| 3167 | if (GetImportedOrCreateDecl<CXXConversionDecl>( |
| 3168 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3169 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3170 | FromConversion->isExplicit(), D->isConstexpr(), SourceLocation())) |
| 3171 | return ToFunction; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3172 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3173 | if (GetImportedOrCreateDecl<CXXMethodDecl>( |
| 3174 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3175 | ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3176 | Method->isInlineSpecified(), D->isConstexpr(), SourceLocation())) |
| 3177 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3178 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3179 | if (GetImportedOrCreateDecl(ToFunction, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3180 | ToInnerLocStart, NameInfo, T, TInfo, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3181 | D->getStorageClass(), D->isInlineSpecified(), |
| 3182 | D->hasWrittenPrototype(), D->isConstexpr())) |
| 3183 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3184 | } |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3185 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3186 | ToFunction->setQualifierInfo(ToQualifierLoc); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3187 | ToFunction->setAccess(D->getAccess()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3188 | ToFunction->setLexicalDeclContext(LexicalDC); |
John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 3189 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 3190 | ToFunction->setTrivial(D->isTrivial()); |
| 3191 | ToFunction->setPure(D->isPure()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3192 | ToFunction->setRangeEnd(ToEndLoc); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3193 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3194 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3195 | for (auto *Param : Parameters) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3196 | Param->setOwningFunction(ToFunction); |
| 3197 | ToFunction->addDeclInternal(Param); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3198 | } |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 3199 | ToFunction->setParams(Parameters); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3200 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3201 | if (FoundByLookup) { |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 3202 | auto *Recent = const_cast<FunctionDecl *>( |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3203 | FoundByLookup->getMostRecentDecl()); |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 3204 | ToFunction->setPreviousDecl(Recent); |
| 3205 | } |
| 3206 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3207 | // We need to complete creation of FunctionProtoTypeLoc manually with setting |
| 3208 | // params it refers to. |
| 3209 | if (TInfo) { |
| 3210 | if (auto ProtoLoc = |
| 3211 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { |
| 3212 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) |
| 3213 | ProtoLoc.setParam(I, Parameters[I]); |
| 3214 | } |
| 3215 | } |
| 3216 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3217 | if (usedDifferentExceptionSpec) { |
| 3218 | // Update FunctionProtoType::ExtProtoInfo. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3219 | if (ExpectedType TyOrErr = import(D->getType())) |
| 3220 | ToFunction->setType(*TyOrErr); |
| 3221 | else |
| 3222 | return TyOrErr.takeError(); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 3223 | } |
| 3224 | |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3225 | // Import the describing template function, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3226 | if (FromFT) { |
| 3227 | auto ToFTOrErr = import(FromFT); |
| 3228 | if (!ToFTOrErr) |
| 3229 | return ToFTOrErr.takeError(); |
| 3230 | } |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3231 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3232 | if (D->doesThisDeclarationHaveABody()) { |
| 3233 | if (Stmt *FromBody = D->getBody()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3234 | if (ExpectedStmt ToBodyOrErr = import(FromBody)) |
| 3235 | ToFunction->setBody(*ToBodyOrErr); |
| 3236 | else |
| 3237 | return ToBodyOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3238 | } |
| 3239 | } |
| 3240 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3241 | // FIXME: Other bits to merge? |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3242 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3243 | // If it is a template, import all related things. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3244 | if (Error Err = ImportTemplateInformation(D, ToFunction)) |
| 3245 | return std::move(Err); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3246 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3247 | bool IsFriend = D->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend); |
| 3248 | |
| 3249 | // TODO Can we generalize this approach to other AST nodes as well? |
| 3250 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 3251 | DC->addDeclInternal(ToFunction); |
| 3252 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3253 | LexicalDC->addDeclInternal(ToFunction); |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3254 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3255 | // Friend declaration's lexical context is the befriending class, but the |
| 3256 | // semantic context is the enclosing scope of the befriending class. |
| 3257 | // We want the friend functions to be found in the semantic context by lookup. |
| 3258 | // FIXME should we handle this generically in VisitFriendDecl? |
| 3259 | // In Other cases when LexicalDC != DC we don't want it to be added, |
| 3260 | // e.g out-of-class definitions like void B::f() {} . |
| 3261 | if (LexicalDC != DC && IsFriend) { |
| 3262 | DC->makeDeclVisibleInContext(ToFunction); |
| 3263 | } |
| 3264 | |
Gabor Marton | 7a0841e | 2018-10-29 10:18:28 +0000 | [diff] [blame] | 3265 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) |
| 3266 | ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod); |
| 3267 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3268 | // Import the rest of the chain. I.e. import all subsequent declarations. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3269 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3270 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 3271 | if (!ToRedeclOrErr) |
| 3272 | return ToRedeclOrErr.takeError(); |
| 3273 | } |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3274 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3275 | return ToFunction; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3276 | } |
| 3277 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3278 | ExpectedDecl ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3279 | return VisitFunctionDecl(D); |
| 3280 | } |
| 3281 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3282 | ExpectedDecl ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3283 | return VisitCXXMethodDecl(D); |
| 3284 | } |
| 3285 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3286 | ExpectedDecl ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3287 | return VisitCXXMethodDecl(D); |
| 3288 | } |
| 3289 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3290 | ExpectedDecl ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3291 | return VisitCXXMethodDecl(D); |
| 3292 | } |
| 3293 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3294 | ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3295 | // Import the major distinguishing characteristics of a variable. |
| 3296 | DeclContext *DC, *LexicalDC; |
| 3297 | DeclarationName Name; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3298 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3299 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3300 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3301 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3302 | if (ToD) |
| 3303 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3304 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3305 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3306 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3307 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3308 | for (auto *FoundDecl : FoundDecls) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3309 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3310 | // For anonymous fields, match up by index. |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3311 | if (!Name && |
| 3312 | ASTImporter::getFieldIndex(D) != |
| 3313 | ASTImporter::getFieldIndex(FoundField)) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3314 | continue; |
| 3315 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3316 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3317 | FoundField->getType())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3318 | Importer.MapImported(D, FoundField); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3319 | // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the |
| 3320 | // initializer of a FieldDecl might not had been instantiated in the |
| 3321 | // "To" context. However, the "From" context might instantiated that, |
| 3322 | // thus we have to merge that. |
| 3323 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
| 3324 | // We don't have yet the initializer set. |
| 3325 | if (FoundField->hasInClassInitializer() && |
| 3326 | !FoundField->getInClassInitializer()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3327 | if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) |
| 3328 | FoundField->setInClassInitializer(*ToInitializerOrErr); |
| 3329 | else { |
| 3330 | // We can't return error here, |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3331 | // since we already mapped D as imported. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3332 | // FIXME: warning message? |
| 3333 | consumeError(ToInitializerOrErr.takeError()); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3334 | return FoundField; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3335 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3336 | } |
| 3337 | } |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3338 | return FoundField; |
| 3339 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3340 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3341 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3342 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 3343 | << Name << D->getType() << FoundField->getType(); |
| 3344 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3345 | << FoundField->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3346 | |
| 3347 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3348 | } |
| 3349 | } |
| 3350 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3351 | QualType ToType; |
| 3352 | TypeSourceInfo *ToTInfo; |
| 3353 | Expr *ToBitWidth; |
| 3354 | SourceLocation ToInnerLocStart; |
| 3355 | Expr *ToInitializer; |
| 3356 | if (auto Imp = importSeq( |
| 3357 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), |
| 3358 | D->getInnerLocStart(), D->getInClassInitializer())) |
| 3359 | std::tie( |
| 3360 | ToType, ToTInfo, ToBitWidth, ToInnerLocStart, ToInitializer) = *Imp; |
| 3361 | else |
| 3362 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3363 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3364 | FieldDecl *ToField; |
| 3365 | if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3366 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3367 | ToType, ToTInfo, ToBitWidth, D->isMutable(), |
| 3368 | D->getInClassInitStyle())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3369 | return ToField; |
| 3370 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3371 | ToField->setAccess(D->getAccess()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3372 | ToField->setLexicalDeclContext(LexicalDC); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3373 | if (ToInitializer) |
| 3374 | ToField->setInClassInitializer(ToInitializer); |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3375 | ToField->setImplicit(D->isImplicit()); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3376 | LexicalDC->addDeclInternal(ToField); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3377 | return ToField; |
| 3378 | } |
| 3379 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3380 | ExpectedDecl ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3381 | // Import the major distinguishing characteristics of a variable. |
| 3382 | DeclContext *DC, *LexicalDC; |
| 3383 | DeclarationName Name; |
| 3384 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3385 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3386 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3387 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3388 | if (ToD) |
| 3389 | return ToD; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3390 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3391 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3392 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3393 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3394 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3395 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3396 | // For anonymous indirect fields, match up by index. |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3397 | if (!Name && |
| 3398 | ASTImporter::getFieldIndex(D) != |
| 3399 | ASTImporter::getFieldIndex(FoundField)) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3400 | continue; |
| 3401 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3402 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3403 | FoundField->getType(), |
David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 3404 | !Name.isEmpty())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3405 | Importer.MapImported(D, FoundField); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3406 | return FoundField; |
| 3407 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3408 | |
| 3409 | // If there are more anonymous fields to check, continue. |
| 3410 | if (!Name && I < N-1) |
| 3411 | continue; |
| 3412 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3413 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3414 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 3415 | << Name << D->getType() << FoundField->getType(); |
| 3416 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3417 | << FoundField->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3418 | |
| 3419 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3420 | } |
| 3421 | } |
| 3422 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3423 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3424 | auto TypeOrErr = import(D->getType()); |
| 3425 | if (!TypeOrErr) |
| 3426 | return TypeOrErr.takeError(); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3427 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3428 | auto **NamedChain = |
| 3429 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3430 | |
| 3431 | unsigned i = 0; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3432 | for (auto *PI : D->chain()) |
| 3433 | if (Expected<NamedDecl *> ToD = import(PI)) |
| 3434 | NamedChain[i++] = *ToD; |
| 3435 | else |
| 3436 | return ToD.takeError(); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3437 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3438 | llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()}; |
| 3439 | IndirectFieldDecl *ToIndirectField; |
| 3440 | if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3441 | Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3442 | // FIXME here we leak `NamedChain` which is allocated before |
| 3443 | return ToIndirectField; |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 3444 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3445 | for (const auto *Attr : D->attrs()) |
| 3446 | ToIndirectField->addAttr(Importer.Import(Attr)); |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 3447 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3448 | ToIndirectField->setAccess(D->getAccess()); |
| 3449 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3450 | LexicalDC->addDeclInternal(ToIndirectField); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3451 | return ToIndirectField; |
| 3452 | } |
| 3453 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3454 | ExpectedDecl ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3455 | // Import the major distinguishing characteristics of a declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3456 | DeclContext *DC, *LexicalDC; |
| 3457 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 3458 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3459 | |
| 3460 | // Determine whether we've already imported this decl. |
| 3461 | // FriendDecl is not a NamedDecl so we cannot use localUncachedLookup. |
| 3462 | auto *RD = cast<CXXRecordDecl>(DC); |
| 3463 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3464 | |
| 3465 | while (ImportedFriend) { |
| 3466 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 3467 | if (IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(), |
| 3468 | /*Complain=*/false)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3469 | return Importer.MapImported(D, ImportedFriend); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3470 | |
| 3471 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| 3472 | if (Importer.IsStructurallyEquivalent( |
| 3473 | D->getFriendType()->getType(), |
| 3474 | ImportedFriend->getFriendType()->getType(), true)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3475 | return Importer.MapImported(D, ImportedFriend); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3476 | } |
| 3477 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 3478 | } |
| 3479 | |
| 3480 | // Not found. Create it. |
| 3481 | FriendDecl::FriendUnion ToFU; |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3482 | if (NamedDecl *FriendD = D->getFriendDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3483 | NamedDecl *ToFriendD; |
| 3484 | if (Error Err = importInto(ToFriendD, FriendD)) |
| 3485 | return std::move(Err); |
| 3486 | |
| 3487 | if (FriendD->getFriendObjectKind() != Decl::FOK_None && |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3488 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) |
| 3489 | ToFriendD->setObjectOfFriendDecl(false); |
| 3490 | |
| 3491 | ToFU = ToFriendD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3492 | } else { // The friend is a type, not a decl. |
| 3493 | if (auto TSIOrErr = import(D->getFriendType())) |
| 3494 | ToFU = *TSIOrErr; |
| 3495 | else |
| 3496 | return TSIOrErr.takeError(); |
| 3497 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3498 | |
| 3499 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3500 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3501 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3502 | if (auto ListOrErr = ImportTemplateParameterList(FromTPLists[I])) |
| 3503 | ToTPLists[I] = *ListOrErr; |
| 3504 | else |
| 3505 | return ListOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3506 | } |
| 3507 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3508 | auto LocationOrErr = import(D->getLocation()); |
| 3509 | if (!LocationOrErr) |
| 3510 | return LocationOrErr.takeError(); |
| 3511 | auto FriendLocOrErr = import(D->getFriendLoc()); |
| 3512 | if (!FriendLocOrErr) |
| 3513 | return FriendLocOrErr.takeError(); |
| 3514 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3515 | FriendDecl *FrD; |
| 3516 | if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3517 | *LocationOrErr, ToFU, |
| 3518 | *FriendLocOrErr, ToTPLists)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3519 | return FrD; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3520 | |
| 3521 | FrD->setAccess(D->getAccess()); |
| 3522 | FrD->setLexicalDeclContext(LexicalDC); |
| 3523 | LexicalDC->addDeclInternal(FrD); |
| 3524 | return FrD; |
| 3525 | } |
| 3526 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3527 | ExpectedDecl ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3528 | // Import the major distinguishing characteristics of an ivar. |
| 3529 | DeclContext *DC, *LexicalDC; |
| 3530 | DeclarationName Name; |
| 3531 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3532 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3533 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3534 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3535 | if (ToD) |
| 3536 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3537 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3538 | // Determine whether we've already imported this ivar |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3539 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3540 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3541 | for (auto *FoundDecl : FoundDecls) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3542 | if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3543 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3544 | FoundIvar->getType())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3545 | Importer.MapImported(D, FoundIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3546 | return FoundIvar; |
| 3547 | } |
| 3548 | |
| 3549 | Importer.ToDiag(Loc, diag::err_odr_ivar_type_inconsistent) |
| 3550 | << Name << D->getType() << FoundIvar->getType(); |
| 3551 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) |
| 3552 | << FoundIvar->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3553 | |
| 3554 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3555 | } |
| 3556 | } |
| 3557 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3558 | QualType ToType; |
| 3559 | TypeSourceInfo *ToTypeSourceInfo; |
| 3560 | Expr *ToBitWidth; |
| 3561 | SourceLocation ToInnerLocStart; |
| 3562 | if (auto Imp = importSeq( |
| 3563 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), D->getInnerLocStart())) |
| 3564 | std::tie(ToType, ToTypeSourceInfo, ToBitWidth, ToInnerLocStart) = *Imp; |
| 3565 | else |
| 3566 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3567 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3568 | ObjCIvarDecl *ToIvar; |
| 3569 | if (GetImportedOrCreateDecl( |
| 3570 | ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3571 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3572 | ToType, ToTypeSourceInfo, |
| 3573 | D->getAccessControl(),ToBitWidth, D->getSynthesize())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3574 | return ToIvar; |
| 3575 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3576 | ToIvar->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3577 | LexicalDC->addDeclInternal(ToIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3578 | return ToIvar; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3579 | } |
| 3580 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3581 | ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) { |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3582 | |
| 3583 | SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D); |
| 3584 | auto RedeclIt = Redecls.begin(); |
| 3585 | // Import the first part of the decl chain. I.e. import all previous |
| 3586 | // declarations starting from the canonical decl. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3587 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 3588 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3589 | if (!RedeclOrErr) |
| 3590 | return RedeclOrErr.takeError(); |
| 3591 | } |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3592 | assert(*RedeclIt == D); |
| 3593 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3594 | // Import the major distinguishing characteristics of a variable. |
| 3595 | DeclContext *DC, *LexicalDC; |
| 3596 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3597 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3598 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3599 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3600 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3601 | if (ToD) |
| 3602 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3603 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3604 | // Try to find a variable in our own ("to") context with the same name and |
| 3605 | // in the same context as the variable we're importing. |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3606 | VarDecl *FoundByLookup = nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3607 | if (D->isFileVarDecl()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3608 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3609 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3610 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3611 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3612 | for (auto *FoundDecl : FoundDecls) { |
| 3613 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3614 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3615 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3616 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3617 | // We have found a variable that we may need to merge with. Check it. |
Rafael Espindola | 3ae0005 | 2013-05-13 00:12:11 +0000 | [diff] [blame] | 3618 | if (FoundVar->hasExternalFormalLinkage() && |
| 3619 | D->hasExternalFormalLinkage()) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3620 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3621 | FoundVar->getType())) { |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3622 | |
| 3623 | // The VarDecl in the "From" context has a definition, but in the |
| 3624 | // "To" context we already have a definition. |
| 3625 | VarDecl *FoundDef = FoundVar->getDefinition(); |
| 3626 | if (D->isThisDeclarationADefinition() && FoundDef) |
| 3627 | // FIXME Check for ODR error if the two definitions have |
| 3628 | // different initializers? |
| 3629 | return Importer.MapImported(D, FoundDef); |
| 3630 | |
| 3631 | // The VarDecl in the "From" context has an initializer, but in the |
| 3632 | // "To" context we already have an initializer. |
| 3633 | const VarDecl *FoundDInit = nullptr; |
| 3634 | if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit)) |
| 3635 | // FIXME Diagnose ODR error if the two initializers are different? |
| 3636 | return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit)); |
| 3637 | |
| 3638 | FoundByLookup = FoundVar; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3639 | break; |
| 3640 | } |
| 3641 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3642 | const ArrayType *FoundArray |
| 3643 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 3644 | const ArrayType *TArray |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3645 | = Importer.getToContext().getAsArrayType(D->getType()); |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3646 | if (FoundArray && TArray) { |
| 3647 | if (isa<IncompleteArrayType>(FoundArray) && |
| 3648 | isa<ConstantArrayType>(TArray)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3649 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3650 | if (auto TyOrErr = import(D->getType())) |
| 3651 | FoundVar->setType(*TyOrErr); |
| 3652 | else |
| 3653 | return TyOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3654 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3655 | FoundByLookup = FoundVar; |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3656 | break; |
| 3657 | } else if (isa<IncompleteArrayType>(TArray) && |
| 3658 | isa<ConstantArrayType>(FoundArray)) { |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3659 | FoundByLookup = FoundVar; |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3660 | break; |
Douglas Gregor | 2fbe558 | 2010-02-10 17:16:49 +0000 | [diff] [blame] | 3661 | } |
| 3662 | } |
| 3663 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3664 | Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3665 | << Name << D->getType() << FoundVar->getType(); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3666 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 3667 | << FoundVar->getType(); |
| 3668 | } |
| 3669 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3670 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3671 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3672 | } |
| 3673 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3674 | if (!ConflictingDecls.empty()) { |
| 3675 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3676 | ConflictingDecls.data(), |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3677 | ConflictingDecls.size()); |
| 3678 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3679 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3680 | } |
| 3681 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3682 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3683 | QualType ToType; |
| 3684 | TypeSourceInfo *ToTypeSourceInfo; |
| 3685 | SourceLocation ToInnerLocStart; |
| 3686 | NestedNameSpecifierLoc ToQualifierLoc; |
| 3687 | if (auto Imp = importSeq( |
| 3688 | D->getType(), D->getTypeSourceInfo(), D->getInnerLocStart(), |
| 3689 | D->getQualifierLoc())) |
| 3690 | std::tie(ToType, ToTypeSourceInfo, ToInnerLocStart, ToQualifierLoc) = *Imp; |
| 3691 | else |
| 3692 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3693 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3694 | // Create the imported variable. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3695 | VarDecl *ToVar; |
| 3696 | if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3697 | ToInnerLocStart, Loc, |
| 3698 | Name.getAsIdentifierInfo(), |
| 3699 | ToType, ToTypeSourceInfo, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3700 | D->getStorageClass())) |
| 3701 | return ToVar; |
| 3702 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3703 | ToVar->setQualifierInfo(ToQualifierLoc); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3704 | ToVar->setAccess(D->getAccess()); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3705 | ToVar->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3706 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3707 | if (FoundByLookup) { |
| 3708 | auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl()); |
| 3709 | ToVar->setPreviousDecl(Recent); |
| 3710 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3711 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3712 | if (Error Err = ImportInitializer(D, ToVar)) |
| 3713 | return std::move(Err); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3714 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3715 | if (D->isConstexpr()) |
| 3716 | ToVar->setConstexpr(true); |
| 3717 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3718 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 3719 | DC->addDeclInternal(ToVar); |
| 3720 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
| 3721 | LexicalDC->addDeclInternal(ToVar); |
| 3722 | |
| 3723 | // Import the rest of the chain. I.e. import all subsequent declarations. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3724 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3725 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3726 | if (!RedeclOrErr) |
| 3727 | return RedeclOrErr.takeError(); |
| 3728 | } |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3729 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3730 | return ToVar; |
| 3731 | } |
| 3732 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3733 | ExpectedDecl ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3734 | // Parameters are created in the translation unit's context, then moved |
| 3735 | // into the function declaration's context afterward. |
| 3736 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3737 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3738 | DeclarationName ToDeclName; |
| 3739 | SourceLocation ToLocation; |
| 3740 | QualType ToType; |
| 3741 | if (auto Imp = importSeq(D->getDeclName(), D->getLocation(), D->getType())) |
| 3742 | std::tie(ToDeclName, ToLocation, ToType) = *Imp; |
| 3743 | else |
| 3744 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3745 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3746 | // Create the imported parameter. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3747 | ImplicitParamDecl *ToParm = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3748 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
| 3749 | ToLocation, ToDeclName.getAsIdentifierInfo(), |
| 3750 | ToType, D->getParameterKind())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3751 | return ToParm; |
| 3752 | return ToParm; |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3753 | } |
| 3754 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3755 | ExpectedDecl ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3756 | // Parameters are created in the translation unit's context, then moved |
| 3757 | // into the function declaration's context afterward. |
| 3758 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3759 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3760 | DeclarationName ToDeclName; |
| 3761 | SourceLocation ToLocation, ToInnerLocStart; |
| 3762 | QualType ToType; |
| 3763 | TypeSourceInfo *ToTypeSourceInfo; |
| 3764 | if (auto Imp = importSeq( |
| 3765 | D->getDeclName(), D->getLocation(), D->getType(), D->getInnerLocStart(), |
| 3766 | D->getTypeSourceInfo())) |
| 3767 | std::tie( |
| 3768 | ToDeclName, ToLocation, ToType, ToInnerLocStart, |
| 3769 | ToTypeSourceInfo) = *Imp; |
| 3770 | else |
| 3771 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3772 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3773 | ParmVarDecl *ToParm; |
| 3774 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3775 | ToInnerLocStart, ToLocation, |
| 3776 | ToDeclName.getAsIdentifierInfo(), ToType, |
| 3777 | ToTypeSourceInfo, D->getStorageClass(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3778 | /*DefaultArg*/ nullptr)) |
| 3779 | return ToParm; |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3780 | |
| 3781 | // Set the default argument. |
John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 3782 | ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg()); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3783 | ToParm->setKNRPromoted(D->isKNRPromoted()); |
| 3784 | |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3785 | if (D->hasUninstantiatedDefaultArg()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3786 | if (auto ToDefArgOrErr = import(D->getUninstantiatedDefaultArg())) |
| 3787 | ToParm->setUninstantiatedDefaultArg(*ToDefArgOrErr); |
| 3788 | else |
| 3789 | return ToDefArgOrErr.takeError(); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3790 | } else if (D->hasUnparsedDefaultArg()) { |
| 3791 | ToParm->setUnparsedDefaultArg(); |
| 3792 | } else if (D->hasDefaultArg()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3793 | if (auto ToDefArgOrErr = import(D->getDefaultArg())) |
| 3794 | ToParm->setDefaultArg(*ToDefArgOrErr); |
| 3795 | else |
| 3796 | return ToDefArgOrErr.takeError(); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3797 | } |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3798 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3799 | if (D->isObjCMethodParameter()) { |
| 3800 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); |
| 3801 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); |
| 3802 | } else { |
| 3803 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), |
| 3804 | D->getFunctionScopeIndex()); |
| 3805 | } |
| 3806 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3807 | return ToParm; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3808 | } |
| 3809 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3810 | ExpectedDecl ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3811 | // Import the major distinguishing characteristics of a method. |
| 3812 | DeclContext *DC, *LexicalDC; |
| 3813 | DeclarationName Name; |
| 3814 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3815 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3816 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3817 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3818 | if (ToD) |
| 3819 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3820 | |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3821 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3822 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3823 | for (auto *FoundDecl : FoundDecls) { |
| 3824 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3825 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 3826 | continue; |
| 3827 | |
| 3828 | // Check return types. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3829 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 3830 | FoundMethod->getReturnType())) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3831 | Importer.ToDiag(Loc, diag::err_odr_objc_method_result_type_inconsistent) |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3832 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 3833 | << FoundMethod->getReturnType(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3834 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3835 | diag::note_odr_objc_method_here) |
| 3836 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3837 | |
| 3838 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3839 | } |
| 3840 | |
| 3841 | // Check the number of parameters. |
| 3842 | if (D->param_size() != FoundMethod->param_size()) { |
| 3843 | Importer.ToDiag(Loc, diag::err_odr_objc_method_num_params_inconsistent) |
| 3844 | << D->isInstanceMethod() << Name |
| 3845 | << D->param_size() << FoundMethod->param_size(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3846 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3847 | diag::note_odr_objc_method_here) |
| 3848 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3849 | |
| 3850 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3851 | } |
| 3852 | |
| 3853 | // Check parameter types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3854 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3855 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 3856 | P != PEnd; ++P, ++FoundP) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3857 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3858 | (*FoundP)->getType())) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3859 | Importer.FromDiag((*P)->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3860 | diag::err_odr_objc_method_param_type_inconsistent) |
| 3861 | << D->isInstanceMethod() << Name |
| 3862 | << (*P)->getType() << (*FoundP)->getType(); |
| 3863 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 3864 | << (*FoundP)->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3865 | |
| 3866 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3867 | } |
| 3868 | } |
| 3869 | |
| 3870 | // Check variadic/non-variadic. |
| 3871 | // Check the number of parameters. |
| 3872 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
| 3873 | Importer.ToDiag(Loc, diag::err_odr_objc_method_variadic_inconsistent) |
| 3874 | << D->isInstanceMethod() << Name; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3875 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3876 | diag::note_odr_objc_method_here) |
| 3877 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3878 | |
| 3879 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3880 | } |
| 3881 | |
| 3882 | // FIXME: Any other bits we need to merge? |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3883 | return Importer.MapImported(D, FoundMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3884 | } |
| 3885 | } |
| 3886 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3887 | SourceLocation ToEndLoc; |
| 3888 | QualType ToReturnType; |
| 3889 | TypeSourceInfo *ToReturnTypeSourceInfo; |
| 3890 | if (auto Imp = importSeq( |
| 3891 | D->getEndLoc(), D->getReturnType(), D->getReturnTypeSourceInfo())) |
| 3892 | std::tie(ToEndLoc, ToReturnType, ToReturnTypeSourceInfo) = *Imp; |
| 3893 | else |
| 3894 | return Imp.takeError(); |
Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 3895 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3896 | ObjCMethodDecl *ToMethod; |
| 3897 | if (GetImportedOrCreateDecl( |
| 3898 | ToMethod, D, Importer.getToContext(), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3899 | ToEndLoc, Name.getObjCSelector(), ToReturnType, |
| 3900 | ToReturnTypeSourceInfo, DC, D->isInstanceMethod(), D->isVariadic(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3901 | D->isPropertyAccessor(), D->isImplicit(), D->isDefined(), |
| 3902 | D->getImplementationControl(), D->hasRelatedResultType())) |
| 3903 | return ToMethod; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3904 | |
| 3905 | // FIXME: When we decide to merge method definitions, we'll need to |
| 3906 | // deal with implicit parameters. |
| 3907 | |
| 3908 | // Import the parameters |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3909 | SmallVector<ParmVarDecl *, 5> ToParams; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3910 | for (auto *FromP : D->parameters()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3911 | if (Expected<ParmVarDecl *> ToPOrErr = import(FromP)) |
| 3912 | ToParams.push_back(*ToPOrErr); |
| 3913 | else |
| 3914 | return ToPOrErr.takeError(); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3915 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3916 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3917 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3918 | for (auto *ToParam : ToParams) { |
| 3919 | ToParam->setOwningFunction(ToMethod); |
| 3920 | ToMethod->addDeclInternal(ToParam); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3921 | } |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3922 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3923 | SmallVector<SourceLocation, 12> FromSelLocs; |
| 3924 | D->getSelectorLocs(FromSelLocs); |
| 3925 | SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size()); |
| 3926 | if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs)) |
| 3927 | return std::move(Err); |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3928 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3929 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3930 | |
| 3931 | ToMethod->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3932 | LexicalDC->addDeclInternal(ToMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3933 | return ToMethod; |
| 3934 | } |
| 3935 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3936 | ExpectedDecl ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3937 | // Import the major distinguishing characteristics of a category. |
| 3938 | DeclContext *DC, *LexicalDC; |
| 3939 | DeclarationName Name; |
| 3940 | SourceLocation Loc; |
| 3941 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3942 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3943 | return std::move(Err); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3944 | if (ToD) |
| 3945 | return ToD; |
| 3946 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3947 | SourceLocation ToVarianceLoc, ToLocation, ToColonLoc; |
| 3948 | TypeSourceInfo *ToTypeSourceInfo; |
| 3949 | if (auto Imp = importSeq( |
| 3950 | D->getVarianceLoc(), D->getLocation(), D->getColonLoc(), |
| 3951 | D->getTypeSourceInfo())) |
| 3952 | std::tie(ToVarianceLoc, ToLocation, ToColonLoc, ToTypeSourceInfo) = *Imp; |
| 3953 | else |
| 3954 | return Imp.takeError(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3955 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3956 | ObjCTypeParamDecl *Result; |
| 3957 | if (GetImportedOrCreateDecl( |
| 3958 | Result, D, Importer.getToContext(), DC, D->getVariance(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3959 | ToVarianceLoc, D->getIndex(), |
| 3960 | ToLocation, Name.getAsIdentifierInfo(), |
| 3961 | ToColonLoc, ToTypeSourceInfo)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3962 | return Result; |
| 3963 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3964 | Result->setLexicalDeclContext(LexicalDC); |
| 3965 | return Result; |
| 3966 | } |
| 3967 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3968 | ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3969 | // Import the major distinguishing characteristics of a category. |
| 3970 | DeclContext *DC, *LexicalDC; |
| 3971 | DeclarationName Name; |
| 3972 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3973 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3974 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3975 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3976 | if (ToD) |
| 3977 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3978 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3979 | ObjCInterfaceDecl *ToInterface; |
| 3980 | if (Error Err = importInto(ToInterface, D->getClassInterface())) |
| 3981 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3982 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3983 | // Determine if we've already encountered this category. |
| 3984 | ObjCCategoryDecl *MergeWithCategory |
| 3985 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 3986 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 3987 | if (!ToCategory) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3988 | SourceLocation ToAtStartLoc, ToCategoryNameLoc; |
| 3989 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; |
| 3990 | if (auto Imp = importSeq( |
| 3991 | D->getAtStartLoc(), D->getCategoryNameLoc(), |
| 3992 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) |
| 3993 | std::tie( |
| 3994 | ToAtStartLoc, ToCategoryNameLoc, |
| 3995 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; |
| 3996 | else |
| 3997 | return Imp.takeError(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3998 | |
| 3999 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4000 | ToAtStartLoc, Loc, |
| 4001 | ToCategoryNameLoc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4002 | Name.getAsIdentifierInfo(), ToInterface, |
| 4003 | /*TypeParamList=*/nullptr, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4004 | ToIvarLBraceLoc, |
| 4005 | ToIvarRBraceLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4006 | return ToCategory; |
| 4007 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4008 | ToCategory->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4009 | LexicalDC->addDeclInternal(ToCategory); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4010 | // Import the type parameter list after MapImported, to avoid |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4011 | // loops when bringing in their DeclContext. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4012 | if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList())) |
| 4013 | ToCategory->setTypeParamList(*PListOrErr); |
| 4014 | else |
| 4015 | return PListOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4016 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4017 | // Import protocols |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4018 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4019 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4020 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 4021 | = D->protocol_loc_begin(); |
| 4022 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 4023 | FromProtoEnd = D->protocol_end(); |
| 4024 | FromProto != FromProtoEnd; |
| 4025 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4026 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4027 | Protocols.push_back(*ToProtoOrErr); |
| 4028 | else |
| 4029 | return ToProtoOrErr.takeError(); |
| 4030 | |
| 4031 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4032 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4033 | else |
| 4034 | return ToProtoLocOrErr.takeError(); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4035 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4036 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4037 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4038 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 4039 | ProtocolLocs.data(), Importer.getToContext()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4040 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4041 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4042 | Importer.MapImported(D, ToCategory); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4043 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4044 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4045 | // Import all of the members of this category. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4046 | if (Error Err = ImportDeclContext(D)) |
| 4047 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4048 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4049 | // If we have an implementation, import it as well. |
| 4050 | if (D->getImplementation()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4051 | if (Expected<ObjCCategoryImplDecl *> ToImplOrErr = |
| 4052 | import(D->getImplementation())) |
| 4053 | ToCategory->setImplementation(*ToImplOrErr); |
| 4054 | else |
| 4055 | return ToImplOrErr.takeError(); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4056 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4057 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4058 | return ToCategory; |
| 4059 | } |
| 4060 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4061 | Error ASTNodeImporter::ImportDefinition( |
| 4062 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4063 | if (To->getDefinition()) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4064 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4065 | if (Error Err = ImportDeclContext(From)) |
| 4066 | return Err; |
| 4067 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4068 | } |
| 4069 | |
| 4070 | // Start the protocol definition |
| 4071 | To->startDefinition(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4072 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4073 | // Import protocols |
| 4074 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4075 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4076 | ObjCProtocolDecl::protocol_loc_iterator FromProtoLoc = |
| 4077 | From->protocol_loc_begin(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4078 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4079 | FromProtoEnd = From->protocol_end(); |
| 4080 | FromProto != FromProtoEnd; |
| 4081 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4082 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4083 | Protocols.push_back(*ToProtoOrErr); |
| 4084 | else |
| 4085 | return ToProtoOrErr.takeError(); |
| 4086 | |
| 4087 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4088 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4089 | else |
| 4090 | return ToProtoLocOrErr.takeError(); |
| 4091 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4092 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4093 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4094 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4095 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4096 | ProtocolLocs.data(), Importer.getToContext()); |
| 4097 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4098 | if (shouldForceImportDeclContext(Kind)) { |
| 4099 | // Import all of the members of this protocol. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4100 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4101 | return Err; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4102 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4103 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4104 | } |
| 4105 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4106 | ExpectedDecl ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4107 | // 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] | 4108 | // from, but this particular declaration is not that definition, import the |
| 4109 | // definition and map to that. |
| 4110 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 4111 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4112 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4113 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4114 | else |
| 4115 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4116 | } |
| 4117 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4118 | // Import the major distinguishing characteristics of a protocol. |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4119 | DeclContext *DC, *LexicalDC; |
| 4120 | DeclarationName Name; |
| 4121 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4122 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4123 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4124 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4125 | if (ToD) |
| 4126 | return ToD; |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4127 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4128 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4129 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4130 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4131 | for (auto *FoundDecl : FoundDecls) { |
| 4132 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4133 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4134 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4135 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4136 | break; |
| 4137 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4138 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4139 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4140 | if (!ToProto) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4141 | auto ToAtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4142 | if (!ToAtBeginLocOrErr) |
| 4143 | return ToAtBeginLocOrErr.takeError(); |
| 4144 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4145 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, |
| 4146 | Name.getAsIdentifierInfo(), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4147 | *ToAtBeginLocOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4148 | /*PrevDecl=*/nullptr)) |
| 4149 | return ToProto; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4150 | ToProto->setLexicalDeclContext(LexicalDC); |
| 4151 | LexicalDC->addDeclInternal(ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4152 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4153 | |
| 4154 | Importer.MapImported(D, ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4155 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4156 | if (D->isThisDeclarationADefinition()) |
| 4157 | if (Error Err = ImportDefinition(D, ToProto)) |
| 4158 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4159 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4160 | return ToProto; |
| 4161 | } |
| 4162 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4163 | ExpectedDecl ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 4164 | DeclContext *DC, *LexicalDC; |
| 4165 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4166 | return std::move(Err); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4167 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4168 | ExpectedSLoc ExternLocOrErr = import(D->getExternLoc()); |
| 4169 | if (!ExternLocOrErr) |
| 4170 | return ExternLocOrErr.takeError(); |
| 4171 | |
| 4172 | ExpectedSLoc LangLocOrErr = import(D->getLocation()); |
| 4173 | if (!LangLocOrErr) |
| 4174 | return LangLocOrErr.takeError(); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4175 | |
| 4176 | bool HasBraces = D->hasBraces(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4177 | |
| 4178 | LinkageSpecDecl *ToLinkageSpec; |
| 4179 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4180 | *ExternLocOrErr, *LangLocOrErr, |
| 4181 | D->getLanguage(), HasBraces)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4182 | return ToLinkageSpec; |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4183 | |
| 4184 | if (HasBraces) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4185 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); |
| 4186 | if (!RBraceLocOrErr) |
| 4187 | return RBraceLocOrErr.takeError(); |
| 4188 | ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4189 | } |
| 4190 | |
| 4191 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 4192 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 4193 | |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4194 | return ToLinkageSpec; |
| 4195 | } |
| 4196 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4197 | ExpectedDecl ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4198 | DeclContext *DC, *LexicalDC; |
| 4199 | DeclarationName Name; |
| 4200 | SourceLocation Loc; |
| 4201 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4202 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4203 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4204 | if (ToD) |
| 4205 | return ToD; |
| 4206 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4207 | SourceLocation ToLoc, ToUsingLoc; |
| 4208 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4209 | if (auto Imp = importSeq( |
| 4210 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc())) |
| 4211 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc) = *Imp; |
| 4212 | else |
| 4213 | return Imp.takeError(); |
| 4214 | |
| 4215 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4216 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4217 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4218 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4219 | UsingDecl *ToUsing; |
| 4220 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4221 | ToUsingLoc, ToQualifierLoc, NameInfo, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4222 | D->hasTypename())) |
| 4223 | return ToUsing; |
| 4224 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4225 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4226 | LexicalDC->addDeclInternal(ToUsing); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4227 | |
| 4228 | if (NamedDecl *FromPattern = |
| 4229 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4230 | if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern)) |
| 4231 | Importer.getToContext().setInstantiatedFromUsingDecl( |
| 4232 | ToUsing, *ToPatternOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4233 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4234 | return ToPatternOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4235 | } |
| 4236 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4237 | for (UsingShadowDecl *FromShadow : D->shadows()) { |
| 4238 | if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow)) |
| 4239 | ToUsing->addShadowDecl(*ToShadowOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4240 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4241 | // FIXME: We return error here but the definition is already created |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4242 | // and available with lookups. How to fix this?.. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4243 | return ToShadowOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4244 | } |
| 4245 | return ToUsing; |
| 4246 | } |
| 4247 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4248 | ExpectedDecl ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4249 | DeclContext *DC, *LexicalDC; |
| 4250 | DeclarationName Name; |
| 4251 | SourceLocation Loc; |
| 4252 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4253 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4254 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4255 | if (ToD) |
| 4256 | return ToD; |
| 4257 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4258 | Expected<UsingDecl *> ToUsingOrErr = import(D->getUsingDecl()); |
| 4259 | if (!ToUsingOrErr) |
| 4260 | return ToUsingOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4261 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4262 | Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl()); |
| 4263 | if (!ToTargetOrErr) |
| 4264 | return ToTargetOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4265 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4266 | UsingShadowDecl *ToShadow; |
| 4267 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4268 | *ToUsingOrErr, *ToTargetOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4269 | return ToShadow; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4270 | |
| 4271 | ToShadow->setLexicalDeclContext(LexicalDC); |
| 4272 | ToShadow->setAccess(D->getAccess()); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4273 | |
| 4274 | if (UsingShadowDecl *FromPattern = |
| 4275 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4276 | if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern)) |
| 4277 | Importer.getToContext().setInstantiatedFromUsingShadowDecl( |
| 4278 | ToShadow, *ToPatternOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4279 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4280 | // FIXME: We return error here but the definition is already created |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4281 | // and available with lookups. How to fix this?.. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4282 | return ToPatternOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4283 | } |
| 4284 | |
| 4285 | LexicalDC->addDeclInternal(ToShadow); |
| 4286 | |
| 4287 | return ToShadow; |
| 4288 | } |
| 4289 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4290 | ExpectedDecl ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4291 | DeclContext *DC, *LexicalDC; |
| 4292 | DeclarationName Name; |
| 4293 | SourceLocation Loc; |
| 4294 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4295 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4296 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4297 | if (ToD) |
| 4298 | return ToD; |
| 4299 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4300 | auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor()); |
| 4301 | if (!ToComAncestorOrErr) |
| 4302 | return ToComAncestorOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4303 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4304 | NamespaceDecl *ToNominatedNamespace; |
| 4305 | SourceLocation ToUsingLoc, ToNamespaceKeyLocation, ToIdentLocation; |
| 4306 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4307 | if (auto Imp = importSeq( |
| 4308 | D->getNominatedNamespace(), D->getUsingLoc(), |
| 4309 | D->getNamespaceKeyLocation(), D->getQualifierLoc(), |
| 4310 | D->getIdentLocation())) |
| 4311 | std::tie( |
| 4312 | ToNominatedNamespace, ToUsingLoc, ToNamespaceKeyLocation, |
| 4313 | ToQualifierLoc, ToIdentLocation) = *Imp; |
| 4314 | else |
| 4315 | return Imp.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4316 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4317 | UsingDirectiveDecl *ToUsingDir; |
| 4318 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4319 | ToUsingLoc, |
| 4320 | ToNamespaceKeyLocation, |
| 4321 | ToQualifierLoc, |
| 4322 | ToIdentLocation, |
| 4323 | ToNominatedNamespace, *ToComAncestorOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4324 | return ToUsingDir; |
| 4325 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4326 | ToUsingDir->setLexicalDeclContext(LexicalDC); |
| 4327 | LexicalDC->addDeclInternal(ToUsingDir); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4328 | |
| 4329 | return ToUsingDir; |
| 4330 | } |
| 4331 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4332 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4333 | UnresolvedUsingValueDecl *D) { |
| 4334 | DeclContext *DC, *LexicalDC; |
| 4335 | DeclarationName Name; |
| 4336 | SourceLocation Loc; |
| 4337 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4338 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4339 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4340 | if (ToD) |
| 4341 | return ToD; |
| 4342 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4343 | SourceLocation ToLoc, ToUsingLoc, ToEllipsisLoc; |
| 4344 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4345 | if (auto Imp = importSeq( |
| 4346 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc(), |
| 4347 | D->getEllipsisLoc())) |
| 4348 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; |
| 4349 | else |
| 4350 | return Imp.takeError(); |
| 4351 | |
| 4352 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4353 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4354 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4355 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4356 | UnresolvedUsingValueDecl *ToUsingValue; |
| 4357 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4358 | ToUsingLoc, ToQualifierLoc, NameInfo, |
| 4359 | ToEllipsisLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4360 | return ToUsingValue; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4361 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4362 | ToUsingValue->setAccess(D->getAccess()); |
| 4363 | ToUsingValue->setLexicalDeclContext(LexicalDC); |
| 4364 | LexicalDC->addDeclInternal(ToUsingValue); |
| 4365 | |
| 4366 | return ToUsingValue; |
| 4367 | } |
| 4368 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4369 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4370 | UnresolvedUsingTypenameDecl *D) { |
| 4371 | DeclContext *DC, *LexicalDC; |
| 4372 | DeclarationName Name; |
| 4373 | SourceLocation Loc; |
| 4374 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4375 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4376 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4377 | if (ToD) |
| 4378 | return ToD; |
| 4379 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4380 | SourceLocation ToUsingLoc, ToTypenameLoc, ToEllipsisLoc; |
| 4381 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4382 | if (auto Imp = importSeq( |
| 4383 | D->getUsingLoc(), D->getTypenameLoc(), D->getQualifierLoc(), |
| 4384 | D->getEllipsisLoc())) |
| 4385 | std::tie(ToUsingLoc, ToTypenameLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; |
| 4386 | else |
| 4387 | return Imp.takeError(); |
| 4388 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4389 | UnresolvedUsingTypenameDecl *ToUsing; |
| 4390 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4391 | ToUsingLoc, ToTypenameLoc, |
| 4392 | ToQualifierLoc, Loc, Name, ToEllipsisLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4393 | return ToUsing; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4394 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4395 | ToUsing->setAccess(D->getAccess()); |
| 4396 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4397 | LexicalDC->addDeclInternal(ToUsing); |
| 4398 | |
| 4399 | return ToUsing; |
| 4400 | } |
| 4401 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4402 | |
| 4403 | Error ASTNodeImporter::ImportDefinition( |
| 4404 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4405 | if (To->getDefinition()) { |
| 4406 | // Check consistency of superclass. |
| 4407 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 4408 | if (FromSuper) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4409 | if (auto FromSuperOrErr = import(FromSuper)) |
| 4410 | FromSuper = *FromSuperOrErr; |
| 4411 | else |
| 4412 | return FromSuperOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4413 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4414 | |
| 4415 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4416 | if ((bool)FromSuper != (bool)ToSuper || |
| 4417 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4418 | Importer.ToDiag(To->getLocation(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4419 | diag::err_odr_objc_superclass_inconsistent) |
| 4420 | << To->getDeclName(); |
| 4421 | if (ToSuper) |
| 4422 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 4423 | << To->getSuperClass()->getDeclName(); |
| 4424 | else |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4425 | Importer.ToDiag(To->getLocation(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4426 | diag::note_odr_objc_missing_superclass); |
| 4427 | if (From->getSuperClass()) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4428 | Importer.FromDiag(From->getSuperClassLoc(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4429 | diag::note_odr_objc_superclass) |
| 4430 | << From->getSuperClass()->getDeclName(); |
| 4431 | else |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4432 | Importer.FromDiag(From->getLocation(), |
| 4433 | diag::note_odr_objc_missing_superclass); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4434 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4435 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4436 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4437 | if (Error Err = ImportDeclContext(From)) |
| 4438 | return Err; |
| 4439 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4440 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4441 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4442 | // Start the definition. |
| 4443 | To->startDefinition(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4444 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4445 | // If this class has a superclass, import it. |
| 4446 | if (From->getSuperClass()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4447 | if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo())) |
| 4448 | To->setSuperClass(*SuperTInfoOrErr); |
| 4449 | else |
| 4450 | return SuperTInfoOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4451 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4452 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4453 | // Import protocols |
| 4454 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4455 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4456 | ObjCInterfaceDecl::protocol_loc_iterator FromProtoLoc = |
| 4457 | From->protocol_loc_begin(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4458 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4459 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4460 | FromProtoEnd = From->protocol_end(); |
| 4461 | FromProto != FromProtoEnd; |
| 4462 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4463 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4464 | Protocols.push_back(*ToProtoOrErr); |
| 4465 | else |
| 4466 | return ToProtoOrErr.takeError(); |
| 4467 | |
| 4468 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4469 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4470 | else |
| 4471 | return ToProtoLocOrErr.takeError(); |
| 4472 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4473 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4474 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4475 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4476 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4477 | ProtocolLocs.data(), Importer.getToContext()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4478 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4479 | // Import categories. When the categories themselves are imported, they'll |
| 4480 | // hook themselves into this interface. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4481 | for (auto *Cat : From->known_categories()) { |
| 4482 | auto ToCatOrErr = import(Cat); |
| 4483 | if (!ToCatOrErr) |
| 4484 | return ToCatOrErr.takeError(); |
| 4485 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4486 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4487 | // If we have an @implementation, import it as well. |
| 4488 | if (From->getImplementation()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4489 | if (Expected<ObjCImplementationDecl *> ToImplOrErr = |
| 4490 | import(From->getImplementation())) |
| 4491 | To->setImplementation(*ToImplOrErr); |
| 4492 | else |
| 4493 | return ToImplOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4494 | } |
| 4495 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4496 | if (shouldForceImportDeclContext(Kind)) { |
| 4497 | // Import all of the members of this class. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4498 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4499 | return Err; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4500 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4501 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4502 | } |
| 4503 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4504 | Expected<ObjCTypeParamList *> |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4505 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 4506 | if (!list) |
| 4507 | return nullptr; |
| 4508 | |
| 4509 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4510 | for (auto *fromTypeParam : *list) { |
| 4511 | if (auto toTypeParamOrErr = import(fromTypeParam)) |
| 4512 | toTypeParams.push_back(*toTypeParamOrErr); |
| 4513 | else |
| 4514 | return toTypeParamOrErr.takeError(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4515 | } |
| 4516 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4517 | auto LAngleLocOrErr = import(list->getLAngleLoc()); |
| 4518 | if (!LAngleLocOrErr) |
| 4519 | return LAngleLocOrErr.takeError(); |
| 4520 | |
| 4521 | auto RAngleLocOrErr = import(list->getRAngleLoc()); |
| 4522 | if (!RAngleLocOrErr) |
| 4523 | return RAngleLocOrErr.takeError(); |
| 4524 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4525 | return ObjCTypeParamList::create(Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4526 | *LAngleLocOrErr, |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4527 | toTypeParams, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4528 | *RAngleLocOrErr); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4529 | } |
| 4530 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4531 | ExpectedDecl ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4532 | // If this class has a definition in the translation unit we're coming from, |
| 4533 | // but this particular declaration is not that definition, import the |
| 4534 | // definition and map to that. |
| 4535 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 4536 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4537 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4538 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4539 | else |
| 4540 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4541 | } |
| 4542 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4543 | // Import the major distinguishing characteristics of an @interface. |
| 4544 | DeclContext *DC, *LexicalDC; |
| 4545 | DeclarationName Name; |
| 4546 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4547 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4548 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4549 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4550 | if (ToD) |
| 4551 | return ToD; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4552 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4553 | // Look for an existing interface with the same name. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4554 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4555 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4556 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4557 | for (auto *FoundDecl : FoundDecls) { |
| 4558 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4559 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4560 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4561 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4562 | break; |
| 4563 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4564 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4565 | // Create an interface declaration, if one does not already exist. |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4566 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4567 | if (!ToIface) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4568 | ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4569 | if (!AtBeginLocOrErr) |
| 4570 | return AtBeginLocOrErr.takeError(); |
| 4571 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4572 | if (GetImportedOrCreateDecl( |
| 4573 | ToIface, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4574 | *AtBeginLocOrErr, Name.getAsIdentifierInfo(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4575 | /*TypeParamList=*/nullptr, |
| 4576 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) |
| 4577 | return ToIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4578 | ToIface->setLexicalDeclContext(LexicalDC); |
| 4579 | LexicalDC->addDeclInternal(ToIface); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4580 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4581 | Importer.MapImported(D, ToIface); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4582 | // Import the type parameter list after MapImported, to avoid |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4583 | // loops when bringing in their DeclContext. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4584 | if (auto ToPListOrErr = |
| 4585 | ImportObjCTypeParamList(D->getTypeParamListAsWritten())) |
| 4586 | ToIface->setTypeParamList(*ToPListOrErr); |
| 4587 | else |
| 4588 | return ToPListOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4589 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4590 | if (D->isThisDeclarationADefinition()) |
| 4591 | if (Error Err = ImportDefinition(D, ToIface)) |
| 4592 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4593 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4594 | return ToIface; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4595 | } |
| 4596 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4597 | ExpectedDecl |
| 4598 | ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 4599 | ObjCCategoryDecl *Category; |
| 4600 | if (Error Err = importInto(Category, D->getCategoryDecl())) |
| 4601 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4602 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4603 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 4604 | if (!ToImpl) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4605 | DeclContext *DC, *LexicalDC; |
| 4606 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4607 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4608 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4609 | SourceLocation ToLocation, ToAtStartLoc, ToCategoryNameLoc; |
| 4610 | if (auto Imp = importSeq( |
| 4611 | D->getLocation(), D->getAtStartLoc(), D->getCategoryNameLoc())) |
| 4612 | std::tie(ToLocation, ToAtStartLoc, ToCategoryNameLoc) = *Imp; |
| 4613 | else |
| 4614 | return Imp.takeError(); |
| 4615 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4616 | if (GetImportedOrCreateDecl( |
| 4617 | ToImpl, D, Importer.getToContext(), DC, |
| 4618 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4619 | ToLocation, ToAtStartLoc, ToCategoryNameLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4620 | return ToImpl; |
| 4621 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4622 | ToImpl->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4623 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4624 | Category->setImplementation(ToImpl); |
| 4625 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4626 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4627 | Importer.MapImported(D, ToImpl); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4628 | if (Error Err = ImportDeclContext(D)) |
| 4629 | return std::move(Err); |
| 4630 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4631 | return ToImpl; |
| 4632 | } |
| 4633 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4634 | ExpectedDecl |
| 4635 | ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4636 | // Find the corresponding interface. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4637 | ObjCInterfaceDecl *Iface; |
| 4638 | if (Error Err = importInto(Iface, D->getClassInterface())) |
| 4639 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4640 | |
| 4641 | // Import the superclass, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4642 | ObjCInterfaceDecl *Super; |
| 4643 | if (Error Err = importInto(Super, D->getSuperClass())) |
| 4644 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4645 | |
| 4646 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 4647 | if (!Impl) { |
| 4648 | // We haven't imported an implementation yet. Create a new @implementation |
| 4649 | // now. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4650 | DeclContext *DC, *LexicalDC; |
| 4651 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4652 | return std::move(Err); |
| 4653 | |
| 4654 | SourceLocation ToLocation, ToAtStartLoc, ToSuperClassLoc; |
| 4655 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; |
| 4656 | if (auto Imp = importSeq( |
| 4657 | D->getLocation(), D->getAtStartLoc(), D->getSuperClassLoc(), |
| 4658 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) |
| 4659 | std::tie( |
| 4660 | ToLocation, ToAtStartLoc, ToSuperClassLoc, |
| 4661 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; |
| 4662 | else |
| 4663 | return Imp.takeError(); |
| 4664 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4665 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4666 | DC, Iface, Super, |
| 4667 | ToLocation, |
| 4668 | ToAtStartLoc, |
| 4669 | ToSuperClassLoc, |
| 4670 | ToIvarLBraceLoc, |
| 4671 | ToIvarRBraceLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4672 | return Impl; |
| 4673 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4674 | Impl->setLexicalDeclContext(LexicalDC); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4675 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4676 | // Associate the implementation with the class it implements. |
| 4677 | Iface->setImplementation(Impl); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4678 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4679 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4680 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4681 | |
| 4682 | // Verify that the existing @implementation has the same superclass. |
| 4683 | if ((Super && !Impl->getSuperClass()) || |
| 4684 | (!Super && Impl->getSuperClass()) || |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4685 | (Super && Impl->getSuperClass() && |
| 4686 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 4687 | Impl->getSuperClass()))) { |
| 4688 | Importer.ToDiag(Impl->getLocation(), |
| 4689 | diag::err_odr_objc_superclass_inconsistent) |
| 4690 | << Iface->getDeclName(); |
| 4691 | // FIXME: It would be nice to have the location of the superclass |
| 4692 | // below. |
| 4693 | if (Impl->getSuperClass()) |
| 4694 | Importer.ToDiag(Impl->getLocation(), |
| 4695 | diag::note_odr_objc_superclass) |
| 4696 | << Impl->getSuperClass()->getDeclName(); |
| 4697 | else |
| 4698 | Importer.ToDiag(Impl->getLocation(), |
| 4699 | diag::note_odr_objc_missing_superclass); |
| 4700 | if (D->getSuperClass()) |
| 4701 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4702 | diag::note_odr_objc_superclass) |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4703 | << D->getSuperClass()->getDeclName(); |
| 4704 | else |
| 4705 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4706 | diag::note_odr_objc_missing_superclass); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4707 | |
| 4708 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4709 | } |
| 4710 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4711 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4712 | // Import all of the members of this @implementation. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4713 | if (Error Err = ImportDeclContext(D)) |
| 4714 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4715 | |
| 4716 | return Impl; |
| 4717 | } |
| 4718 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4719 | ExpectedDecl ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4720 | // Import the major distinguishing characteristics of an @property. |
| 4721 | DeclContext *DC, *LexicalDC; |
| 4722 | DeclarationName Name; |
| 4723 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4724 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4725 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4726 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4727 | if (ToD) |
| 4728 | return ToD; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4729 | |
| 4730 | // Check whether we have already imported this property. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4731 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4732 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4733 | for (auto *FoundDecl : FoundDecls) { |
| 4734 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4735 | // Check property types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4736 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4737 | FoundProp->getType())) { |
| 4738 | Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent) |
| 4739 | << Name << D->getType() << FoundProp->getType(); |
| 4740 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 4741 | << FoundProp->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4742 | |
| 4743 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4744 | } |
| 4745 | |
| 4746 | // FIXME: Check property attributes, getters, setters, etc.? |
| 4747 | |
| 4748 | // Consider these properties to be equivalent. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4749 | Importer.MapImported(D, FoundProp); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4750 | return FoundProp; |
| 4751 | } |
| 4752 | } |
| 4753 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4754 | QualType ToType; |
| 4755 | TypeSourceInfo *ToTypeSourceInfo; |
| 4756 | SourceLocation ToAtLoc, ToLParenLoc; |
| 4757 | if (auto Imp = importSeq( |
| 4758 | D->getType(), D->getTypeSourceInfo(), D->getAtLoc(), D->getLParenLoc())) |
| 4759 | std::tie(ToType, ToTypeSourceInfo, ToAtLoc, ToLParenLoc) = *Imp; |
| 4760 | else |
| 4761 | return Imp.takeError(); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4762 | |
| 4763 | // Create the new property. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4764 | ObjCPropertyDecl *ToProperty; |
| 4765 | if (GetImportedOrCreateDecl( |
| 4766 | ToProperty, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4767 | Name.getAsIdentifierInfo(), ToAtLoc, |
| 4768 | ToLParenLoc, ToType, |
| 4769 | ToTypeSourceInfo, D->getPropertyImplementation())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4770 | return ToProperty; |
| 4771 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4772 | Selector ToGetterName, ToSetterName; |
| 4773 | SourceLocation ToGetterNameLoc, ToSetterNameLoc; |
| 4774 | ObjCMethodDecl *ToGetterMethodDecl, *ToSetterMethodDecl; |
| 4775 | ObjCIvarDecl *ToPropertyIvarDecl; |
| 4776 | if (auto Imp = importSeq( |
| 4777 | D->getGetterName(), D->getSetterName(), |
| 4778 | D->getGetterNameLoc(), D->getSetterNameLoc(), |
| 4779 | D->getGetterMethodDecl(), D->getSetterMethodDecl(), |
| 4780 | D->getPropertyIvarDecl())) |
| 4781 | std::tie( |
| 4782 | ToGetterName, ToSetterName, |
| 4783 | ToGetterNameLoc, ToSetterNameLoc, |
| 4784 | ToGetterMethodDecl, ToSetterMethodDecl, |
| 4785 | ToPropertyIvarDecl) = *Imp; |
| 4786 | else |
| 4787 | return Imp.takeError(); |
| 4788 | |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4789 | ToProperty->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4790 | LexicalDC->addDeclInternal(ToProperty); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4791 | |
| 4792 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 4793 | ToProperty->setPropertyAttributesAsWritten( |
| 4794 | D->getPropertyAttributesAsWritten()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4795 | ToProperty->setGetterName(ToGetterName, ToGetterNameLoc); |
| 4796 | ToProperty->setSetterName(ToSetterName, ToSetterNameLoc); |
| 4797 | ToProperty->setGetterMethodDecl(ToGetterMethodDecl); |
| 4798 | ToProperty->setSetterMethodDecl(ToSetterMethodDecl); |
| 4799 | ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4800 | return ToProperty; |
| 4801 | } |
| 4802 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4803 | ExpectedDecl |
| 4804 | ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 4805 | ObjCPropertyDecl *Property; |
| 4806 | if (Error Err = importInto(Property, D->getPropertyDecl())) |
| 4807 | return std::move(Err); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4808 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4809 | DeclContext *DC, *LexicalDC; |
| 4810 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4811 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4812 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4813 | auto *InImpl = cast<ObjCImplDecl>(LexicalDC); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4814 | |
| 4815 | // Import the ivar (for an @synthesize). |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4816 | ObjCIvarDecl *Ivar = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4817 | if (Error Err = importInto(Ivar, D->getPropertyIvarDecl())) |
| 4818 | return std::move(Err); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4819 | |
| 4820 | ObjCPropertyImplDecl *ToImpl |
Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 4821 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 4822 | Property->getQueryKind()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4823 | if (!ToImpl) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4824 | SourceLocation ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc; |
| 4825 | if (auto Imp = importSeq( |
| 4826 | D->getBeginLoc(), D->getLocation(), D->getPropertyIvarDeclLoc())) |
| 4827 | std::tie(ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc) = *Imp; |
| 4828 | else |
| 4829 | return Imp.takeError(); |
| 4830 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4831 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4832 | ToBeginLoc, |
| 4833 | ToLocation, Property, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4834 | D->getPropertyImplementation(), Ivar, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4835 | ToPropertyIvarDeclLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4836 | return ToImpl; |
| 4837 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4838 | ToImpl->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4839 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4840 | } else { |
| 4841 | // Check that we have the same kind of property implementation (@synthesize |
| 4842 | // vs. @dynamic). |
| 4843 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4844 | Importer.ToDiag(ToImpl->getLocation(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4845 | diag::err_odr_objc_property_impl_kind_inconsistent) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4846 | << Property->getDeclName() |
| 4847 | << (ToImpl->getPropertyImplementation() |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4848 | == ObjCPropertyImplDecl::Dynamic); |
| 4849 | Importer.FromDiag(D->getLocation(), |
| 4850 | diag::note_odr_objc_property_impl_kind) |
| 4851 | << D->getPropertyDecl()->getDeclName() |
| 4852 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4853 | |
| 4854 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4855 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4856 | |
| 4857 | // For @synthesize, check that we have the same |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4858 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 4859 | Ivar != ToImpl->getPropertyIvarDecl()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4860 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4861 | diag::err_odr_objc_synthesize_ivar_inconsistent) |
| 4862 | << Property->getDeclName() |
| 4863 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 4864 | << Ivar->getDeclName(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4865 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4866 | diag::note_odr_objc_synthesize_ivar_here) |
| 4867 | << D->getPropertyIvarDecl()->getDeclName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4868 | |
| 4869 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4870 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4871 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4872 | // Merge the existing implementation with the new implementation. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4873 | Importer.MapImported(D, ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4874 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4875 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4876 | return ToImpl; |
| 4877 | } |
| 4878 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4879 | ExpectedDecl |
| 4880 | ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4881 | // For template arguments, we adopt the translation unit as our declaration |
| 4882 | // context. This context will be fixed when the actual template declaration |
| 4883 | // is created. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4884 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4885 | // FIXME: Import default argument. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4886 | |
| 4887 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 4888 | if (!BeginLocOrErr) |
| 4889 | return BeginLocOrErr.takeError(); |
| 4890 | |
| 4891 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 4892 | if (!LocationOrErr) |
| 4893 | return LocationOrErr.takeError(); |
| 4894 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4895 | TemplateTypeParmDecl *ToD = nullptr; |
| 4896 | (void)GetImportedOrCreateDecl( |
| 4897 | ToD, D, Importer.getToContext(), |
| 4898 | Importer.getToContext().getTranslationUnitDecl(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4899 | *BeginLocOrErr, *LocationOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4900 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), |
| 4901 | D->wasDeclaredWithTypename(), D->isParameterPack()); |
| 4902 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4903 | } |
| 4904 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4905 | ExpectedDecl |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4906 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4907 | DeclarationName ToDeclName; |
| 4908 | SourceLocation ToLocation, ToInnerLocStart; |
| 4909 | QualType ToType; |
| 4910 | TypeSourceInfo *ToTypeSourceInfo; |
| 4911 | if (auto Imp = importSeq( |
| 4912 | D->getDeclName(), D->getLocation(), D->getType(), D->getTypeSourceInfo(), |
| 4913 | D->getInnerLocStart())) |
| 4914 | std::tie( |
| 4915 | ToDeclName, ToLocation, ToType, ToTypeSourceInfo, |
| 4916 | ToInnerLocStart) = *Imp; |
| 4917 | else |
| 4918 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4919 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4920 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4921 | |
| 4922 | NonTypeTemplateParmDecl *ToD = nullptr; |
| 4923 | (void)GetImportedOrCreateDecl( |
| 4924 | ToD, D, Importer.getToContext(), |
| 4925 | Importer.getToContext().getTranslationUnitDecl(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4926 | ToInnerLocStart, ToLocation, D->getDepth(), |
| 4927 | D->getPosition(), ToDeclName.getAsIdentifierInfo(), ToType, |
| 4928 | D->isParameterPack(), ToTypeSourceInfo); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4929 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4930 | } |
| 4931 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4932 | ExpectedDecl |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4933 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 4934 | // Import the name of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4935 | auto NameOrErr = import(D->getDeclName()); |
| 4936 | if (!NameOrErr) |
| 4937 | return NameOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4938 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4939 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4940 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 4941 | if (!LocationOrErr) |
| 4942 | return LocationOrErr.takeError(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4943 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4944 | // Import template parameters. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4945 | auto TemplateParamsOrErr = ImportTemplateParameterList( |
| 4946 | D->getTemplateParameters()); |
| 4947 | if (!TemplateParamsOrErr) |
| 4948 | return TemplateParamsOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4949 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4950 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4951 | |
| 4952 | TemplateTemplateParmDecl *ToD = nullptr; |
| 4953 | (void)GetImportedOrCreateDecl( |
| 4954 | ToD, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4955 | Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr, |
| 4956 | D->getDepth(), D->getPosition(), D->isParameterPack(), |
| 4957 | (*NameOrErr).getAsIdentifierInfo(), |
| 4958 | *TemplateParamsOrErr); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4959 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4960 | } |
| 4961 | |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4962 | // Returns the definition for a (forward) declaration of a ClassTemplateDecl, if |
| 4963 | // it has any definition in the redecl chain. |
| 4964 | static ClassTemplateDecl *getDefinition(ClassTemplateDecl *D) { |
| 4965 | CXXRecordDecl *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); |
| 4966 | if (!ToTemplatedDef) |
| 4967 | return nullptr; |
| 4968 | ClassTemplateDecl *TemplateWithDef = |
| 4969 | ToTemplatedDef->getDescribedClassTemplate(); |
| 4970 | return TemplateWithDef; |
| 4971 | } |
| 4972 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4973 | ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4974 | bool IsFriend = D->getFriendObjectKind() != Decl::FOK_None; |
| 4975 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4976 | // If this record has a definition in the translation unit we're coming from, |
| 4977 | // but this particular declaration is not that definition, import the |
| 4978 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4979 | auto *Definition = |
| 4980 | cast_or_null<CXXRecordDecl>(D->getTemplatedDecl()->getDefinition()); |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4981 | if (Definition && Definition != D->getTemplatedDecl() && !IsFriend) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4982 | if (ExpectedDecl ImportedDefOrErr = import( |
| 4983 | Definition->getDescribedClassTemplate())) |
| 4984 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4985 | else |
| 4986 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4987 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4988 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4989 | // Import the major distinguishing characteristics of this class template. |
| 4990 | DeclContext *DC, *LexicalDC; |
| 4991 | DeclarationName Name; |
| 4992 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4993 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4994 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4995 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4996 | if (ToD) |
| 4997 | return ToD; |
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 | // We may already have a template of the same name; try to find and match it. |
| 5000 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5001 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 5002 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 5003 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5004 | for (auto *FoundDecl : FoundDecls) { |
| 5005 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5006 | continue; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5007 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5008 | Decl *Found = FoundDecl; |
| 5009 | if (auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found)) { |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5010 | |
| 5011 | // The class to be imported is a definition. |
| 5012 | if (D->isThisDeclarationADefinition()) { |
| 5013 | // Lookup will find the fwd decl only if that is more recent than the |
| 5014 | // definition. So, try to get the definition if that is available in |
| 5015 | // the redecl chain. |
| 5016 | ClassTemplateDecl *TemplateWithDef = getDefinition(FoundTemplate); |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5017 | if (TemplateWithDef) |
| 5018 | FoundTemplate = TemplateWithDef; |
| 5019 | else |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5020 | continue; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5021 | } |
| 5022 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5023 | if (IsStructuralMatch(D, FoundTemplate)) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5024 | if (!IsFriend) { |
| 5025 | Importer.MapImported(D->getTemplatedDecl(), |
| 5026 | FoundTemplate->getTemplatedDecl()); |
| 5027 | return Importer.MapImported(D, FoundTemplate); |
| 5028 | } |
Aleksei Sidorin | 761c224 | 2018-05-15 11:09:07 +0000 | [diff] [blame] | 5029 | |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5030 | continue; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5031 | } |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5032 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5033 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5034 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5035 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5036 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5037 | if (!ConflictingDecls.empty()) { |
| 5038 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5039 | ConflictingDecls.data(), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5040 | ConflictingDecls.size()); |
| 5041 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5042 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5043 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5044 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5045 | } |
| 5046 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5047 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); |
| 5048 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5049 | // Create the declaration that is being templated. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5050 | CXXRecordDecl *ToTemplated; |
| 5051 | if (Error Err = importInto(ToTemplated, FromTemplated)) |
| 5052 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5053 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5054 | // Create the class template declaration itself. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5055 | auto TemplateParamsOrErr = ImportTemplateParameterList( |
| 5056 | D->getTemplateParameters()); |
| 5057 | if (!TemplateParamsOrErr) |
| 5058 | return TemplateParamsOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5059 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5060 | ClassTemplateDecl *D2; |
| 5061 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5062 | *TemplateParamsOrErr, ToTemplated)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5063 | return D2; |
| 5064 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5065 | ToTemplated->setDescribedClassTemplate(D2); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5066 | |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5067 | if (ToTemplated->getPreviousDecl()) { |
| 5068 | assert( |
| 5069 | ToTemplated->getPreviousDecl()->getDescribedClassTemplate() && |
| 5070 | "Missing described template"); |
| 5071 | D2->setPreviousDecl( |
| 5072 | ToTemplated->getPreviousDecl()->getDescribedClassTemplate()); |
| 5073 | } |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5074 | D2->setAccess(D->getAccess()); |
| 5075 | D2->setLexicalDeclContext(LexicalDC); |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5076 | if (!IsFriend) |
| 5077 | LexicalDC->addDeclInternal(D2); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5078 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5079 | if (FromTemplated->isCompleteDefinition() && |
| 5080 | !ToTemplated->isCompleteDefinition()) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5081 | // FIXME: Import definition! |
| 5082 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5083 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5084 | return D2; |
| 5085 | } |
| 5086 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5087 | ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5088 | ClassTemplateSpecializationDecl *D) { |
| 5089 | // If this record has a definition in the translation unit we're coming from, |
| 5090 | // but this particular declaration is not that definition, import the |
| 5091 | // definition and map to that. |
| 5092 | TagDecl *Definition = D->getDefinition(); |
| 5093 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5094 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 5095 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5096 | else |
| 5097 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5098 | } |
| 5099 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5100 | ClassTemplateDecl *ClassTemplate; |
| 5101 | if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate())) |
| 5102 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5103 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5104 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5105 | DeclContext *DC, *LexicalDC; |
| 5106 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5107 | return std::move(Err); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5108 | |
| 5109 | // Import template arguments. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5110 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5111 | if (Error Err = ImportTemplateArguments( |
| 5112 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5113 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5114 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5115 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5116 | void *InsertPos = nullptr; |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5117 | ClassTemplateSpecializationDecl *D2 = nullptr; |
| 5118 | ClassTemplatePartialSpecializationDecl *PartialSpec = |
| 5119 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D); |
| 5120 | if (PartialSpec) |
| 5121 | D2 = ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos); |
| 5122 | else |
| 5123 | D2 = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
| 5124 | ClassTemplateSpecializationDecl * const PrevDecl = D2; |
| 5125 | RecordDecl *FoundDef = D2 ? D2->getDefinition() : nullptr; |
| 5126 | if (FoundDef) { |
| 5127 | if (!D->isCompleteDefinition()) { |
| 5128 | // The "From" translation unit only had a forward declaration; call it |
| 5129 | // the same declaration. |
| 5130 | // TODO Handle the redecl chain properly! |
| 5131 | return Importer.MapImported(D, FoundDef); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5132 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5133 | |
| 5134 | if (IsStructuralMatch(D, FoundDef)) { |
| 5135 | |
| 5136 | Importer.MapImported(D, FoundDef); |
| 5137 | |
| 5138 | // Import those those default field initializers which have been |
| 5139 | // instantiated in the "From" context, but not in the "To" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5140 | for (auto *FromField : D->fields()) { |
| 5141 | auto ToOrErr = import(FromField); |
| 5142 | if (!ToOrErr) |
| 5143 | // FIXME: return the error? |
| 5144 | consumeError(ToOrErr.takeError()); |
| 5145 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5146 | |
| 5147 | // Import those methods which have been instantiated in the |
| 5148 | // "From" context, but not in the "To" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5149 | for (CXXMethodDecl *FromM : D->methods()) { |
| 5150 | auto ToOrErr = import(FromM); |
| 5151 | if (!ToOrErr) |
| 5152 | // FIXME: return the error? |
| 5153 | consumeError(ToOrErr.takeError()); |
| 5154 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5155 | |
| 5156 | // TODO Import instantiated default arguments. |
| 5157 | // TODO Import instantiated exception specifications. |
| 5158 | // |
| 5159 | // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint what |
| 5160 | // else could be fused during an AST merge. |
| 5161 | |
| 5162 | return FoundDef; |
| 5163 | } |
| 5164 | } else { // We either couldn't find any previous specialization in the "To" |
| 5165 | // context, or we found one but without definition. Let's create a |
| 5166 | // new specialization and register that at the class template. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5167 | |
| 5168 | // Import the location of this declaration. |
| 5169 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5170 | if (!BeginLocOrErr) |
| 5171 | return BeginLocOrErr.takeError(); |
| 5172 | ExpectedSLoc IdLocOrErr = import(D->getLocation()); |
| 5173 | if (!IdLocOrErr) |
| 5174 | return IdLocOrErr.takeError(); |
| 5175 | |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5176 | if (PartialSpec) { |
| 5177 | // Import TemplateArgumentListInfo. |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5178 | TemplateArgumentListInfo ToTAInfo; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5179 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5180 | if (Error Err = ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) |
| 5181 | return std::move(Err); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5182 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5183 | QualType CanonInjType; |
| 5184 | if (Error Err = importInto( |
| 5185 | CanonInjType, PartialSpec->getInjectedSpecializationType())) |
| 5186 | return std::move(Err); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5187 | CanonInjType = CanonInjType.getCanonicalType(); |
| 5188 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5189 | auto ToTPListOrErr = ImportTemplateParameterList( |
| 5190 | PartialSpec->getTemplateParameters()); |
| 5191 | if (!ToTPListOrErr) |
| 5192 | return ToTPListOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5193 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5194 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5195 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| 5196 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, ClassTemplate, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5197 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5198 | ToTAInfo, CanonInjType, |
| 5199 | cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl))) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5200 | return D2; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5201 | |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5202 | // Update InsertPos, because preceding import calls may have invalidated |
| 5203 | // it by adding new specializations. |
| 5204 | if (!ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos)) |
| 5205 | // Add this partial specialization to the class template. |
| 5206 | ClassTemplate->AddPartialSpecialization( |
| 5207 | cast<ClassTemplatePartialSpecializationDecl>(D2), InsertPos); |
| 5208 | |
| 5209 | } else { // Not a partial specialization. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5210 | if (GetImportedOrCreateDecl( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5211 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| 5212 | *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs, |
| 5213 | PrevDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5214 | return D2; |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5215 | |
| 5216 | // Update InsertPos, because preceding import calls may have invalidated |
| 5217 | // it by adding new specializations. |
| 5218 | if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos)) |
| 5219 | // Add this specialization to the class template. |
| 5220 | ClassTemplate->AddSpecialization(D2, InsertPos); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5221 | } |
| 5222 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5223 | D2->setSpecializationKind(D->getSpecializationKind()); |
| 5224 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5225 | // Import the qualifier, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5226 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5227 | D2->setQualifierInfo(*LocOrErr); |
| 5228 | else |
| 5229 | return LocOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5230 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5231 | if (auto *TSI = D->getTypeAsWritten()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5232 | if (auto TInfoOrErr = import(TSI)) |
| 5233 | D2->setTypeAsWritten(*TInfoOrErr); |
| 5234 | else |
| 5235 | return TInfoOrErr.takeError(); |
| 5236 | |
| 5237 | if (auto LocOrErr = import(D->getTemplateKeywordLoc())) |
| 5238 | D2->setTemplateKeywordLoc(*LocOrErr); |
| 5239 | else |
| 5240 | return LocOrErr.takeError(); |
| 5241 | |
| 5242 | if (auto LocOrErr = import(D->getExternLoc())) |
| 5243 | D2->setExternLoc(*LocOrErr); |
| 5244 | else |
| 5245 | return LocOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5246 | } |
| 5247 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5248 | if (D->getPointOfInstantiation().isValid()) { |
| 5249 | if (auto POIOrErr = import(D->getPointOfInstantiation())) |
| 5250 | D2->setPointOfInstantiation(*POIOrErr); |
| 5251 | else |
| 5252 | return POIOrErr.takeError(); |
| 5253 | } |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5254 | |
| 5255 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 5256 | |
Gabor Marton | b14056b | 2018-05-25 11:21:24 +0000 | [diff] [blame] | 5257 | // Set the context of this specialization/instantiation. |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5258 | D2->setLexicalDeclContext(LexicalDC); |
Gabor Marton | b14056b | 2018-05-25 11:21:24 +0000 | [diff] [blame] | 5259 | |
| 5260 | // Add to the DC only if it was an explicit specialization/instantiation. |
| 5261 | if (D2->isExplicitInstantiationOrSpecialization()) { |
| 5262 | LexicalDC->addDeclInternal(D2); |
| 5263 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5264 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5265 | if (D->isCompleteDefinition()) |
| 5266 | if (Error Err = ImportDefinition(D, D2)) |
| 5267 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5268 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5269 | return D2; |
| 5270 | } |
| 5271 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5272 | ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5273 | // If this variable has a definition in the translation unit we're coming |
| 5274 | // from, |
| 5275 | // but this particular declaration is not that definition, import the |
| 5276 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5277 | auto *Definition = |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5278 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); |
| 5279 | if (Definition && Definition != D->getTemplatedDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5280 | if (ExpectedDecl ImportedDefOrErr = import( |
| 5281 | Definition->getDescribedVarTemplate())) |
| 5282 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5283 | else |
| 5284 | return ImportedDefOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5285 | } |
| 5286 | |
| 5287 | // Import the major distinguishing characteristics of this variable template. |
| 5288 | DeclContext *DC, *LexicalDC; |
| 5289 | DeclarationName Name; |
| 5290 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5291 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5292 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5293 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5294 | if (ToD) |
| 5295 | return ToD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5296 | |
| 5297 | // We may already have a template of the same name; try to find and match it. |
| 5298 | assert(!DC->isFunctionOrMethod() && |
| 5299 | "Variable templates cannot be declared at function scope"); |
| 5300 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 5301 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 5302 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5303 | for (auto *FoundDecl : FoundDecls) { |
| 5304 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5305 | continue; |
| 5306 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5307 | Decl *Found = FoundDecl; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5308 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5309 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 5310 | // The variable templates structurally match; call it the same template. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5311 | Importer.MapImported(D->getTemplatedDecl(), |
| 5312 | FoundTemplate->getTemplatedDecl()); |
| 5313 | return Importer.MapImported(D, FoundTemplate); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5314 | } |
| 5315 | } |
| 5316 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5317 | ConflictingDecls.push_back(FoundDecl); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5318 | } |
| 5319 | |
| 5320 | if (!ConflictingDecls.empty()) { |
| 5321 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 5322 | ConflictingDecls.data(), |
| 5323 | ConflictingDecls.size()); |
| 5324 | } |
| 5325 | |
| 5326 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5327 | // FIXME: Is it possible to get other error than name conflict? |
| 5328 | // (Put this `if` into the previous `if`?) |
| 5329 | return make_error<ImportError>(ImportError::NameConflict); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5330 | |
| 5331 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 5332 | |
| 5333 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5334 | // FIXME: Value not used? |
| 5335 | ExpectedType TypeOrErr = import(DTemplated->getType()); |
| 5336 | if (!TypeOrErr) |
| 5337 | return TypeOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5338 | |
| 5339 | // Create the declaration that is being templated. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5340 | VarDecl *ToTemplated; |
| 5341 | if (Error Err = importInto(ToTemplated, DTemplated)) |
| 5342 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5343 | |
| 5344 | // Create the variable template declaration itself. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5345 | auto TemplateParamsOrErr = ImportTemplateParameterList( |
| 5346 | D->getTemplateParameters()); |
| 5347 | if (!TemplateParamsOrErr) |
| 5348 | return TemplateParamsOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5349 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5350 | VarTemplateDecl *ToVarTD; |
| 5351 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5352 | Name, *TemplateParamsOrErr, ToTemplated)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5353 | return ToVarTD; |
| 5354 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5355 | ToTemplated->setDescribedVarTemplate(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5356 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5357 | ToVarTD->setAccess(D->getAccess()); |
| 5358 | ToVarTD->setLexicalDeclContext(LexicalDC); |
| 5359 | LexicalDC->addDeclInternal(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5360 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5361 | if (DTemplated->isThisDeclarationADefinition() && |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5362 | !ToTemplated->isThisDeclarationADefinition()) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5363 | // FIXME: Import definition! |
| 5364 | } |
| 5365 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5366 | return ToVarTD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5367 | } |
| 5368 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5369 | ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5370 | VarTemplateSpecializationDecl *D) { |
| 5371 | // If this record has a definition in the translation unit we're coming from, |
| 5372 | // but this particular declaration is not that definition, import the |
| 5373 | // definition and map to that. |
| 5374 | VarDecl *Definition = D->getDefinition(); |
| 5375 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5376 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 5377 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5378 | else |
| 5379 | return ImportedDefOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5380 | } |
| 5381 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5382 | VarTemplateDecl *VarTemplate; |
| 5383 | if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate())) |
| 5384 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5385 | |
| 5386 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5387 | DeclContext *DC, *LexicalDC; |
| 5388 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5389 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5390 | |
| 5391 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5392 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5393 | if (!BeginLocOrErr) |
| 5394 | return BeginLocOrErr.takeError(); |
| 5395 | |
| 5396 | auto IdLocOrErr = import(D->getLocation()); |
| 5397 | if (!IdLocOrErr) |
| 5398 | return IdLocOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5399 | |
| 5400 | // Import template arguments. |
| 5401 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5402 | if (Error Err = ImportTemplateArguments( |
| 5403 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5404 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5405 | |
| 5406 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5407 | void *InsertPos = nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5408 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 5409 | TemplateArgs, InsertPos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5410 | if (D2) { |
| 5411 | // We already have a variable template specialization with these template |
| 5412 | // arguments. |
| 5413 | |
| 5414 | // FIXME: Check for specialization vs. instantiation errors. |
| 5415 | |
| 5416 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 5417 | if (!D->isThisDeclarationADefinition() || |
| 5418 | IsStructuralMatch(D, FoundDef)) { |
| 5419 | // The record types structurally match, or the "from" translation |
| 5420 | // unit only had a forward declaration anyway; call it the same |
| 5421 | // variable. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5422 | return Importer.MapImported(D, FoundDef); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5423 | } |
| 5424 | } |
| 5425 | } else { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5426 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5427 | QualType T; |
| 5428 | if (Error Err = importInto(T, D->getType())) |
| 5429 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5430 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5431 | auto TInfoOrErr = import(D->getTypeSourceInfo()); |
| 5432 | if (!TInfoOrErr) |
| 5433 | return TInfoOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5434 | |
| 5435 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5436 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5437 | D->getTemplateArgsInfo(), ToTAInfo)) |
| 5438 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5439 | |
| 5440 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5441 | // Create a new specialization. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5442 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { |
| 5443 | // Import TemplateArgumentListInfo |
| 5444 | TemplateArgumentListInfo ArgInfos; |
| 5445 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); |
| 5446 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5447 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5448 | *FromTAArgsAsWritten, ArgInfos)) |
| 5449 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5450 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5451 | auto ToTPListOrErr = ImportTemplateParameterList( |
| 5452 | FromPartial->getTemplateParameters()); |
| 5453 | if (!ToTPListOrErr) |
| 5454 | return ToTPListOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5455 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5456 | PartVarSpecDecl *ToPartial; |
| 5457 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5458 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, |
| 5459 | VarTemplate, T, *TInfoOrErr, |
| 5460 | D->getStorageClass(), TemplateArgs, ArgInfos)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5461 | return ToPartial; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5462 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5463 | if (Expected<PartVarSpecDecl *> ToInstOrErr = import( |
| 5464 | FromPartial->getInstantiatedFromMember())) |
| 5465 | ToPartial->setInstantiatedFromMember(*ToInstOrErr); |
| 5466 | else |
| 5467 | return ToInstOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5468 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5469 | if (FromPartial->isMemberSpecialization()) |
| 5470 | ToPartial->setMemberSpecialization(); |
| 5471 | |
| 5472 | D2 = ToPartial; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5473 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5474 | } else { // Full specialization |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5475 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, |
| 5476 | *BeginLocOrErr, *IdLocOrErr, VarTemplate, |
| 5477 | T, *TInfoOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5478 | D->getStorageClass(), TemplateArgs)) |
| 5479 | return D2; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5480 | } |
| 5481 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5482 | if (D->getPointOfInstantiation().isValid()) { |
| 5483 | if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation())) |
| 5484 | D2->setPointOfInstantiation(*POIOrErr); |
| 5485 | else |
| 5486 | return POIOrErr.takeError(); |
| 5487 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5488 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5489 | D2->setSpecializationKind(D->getSpecializationKind()); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5490 | D2->setTemplateArgsInfo(ToTAInfo); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5491 | |
| 5492 | // Add this specialization to the class template. |
| 5493 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 5494 | |
| 5495 | // Import the qualifier, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5496 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5497 | D2->setQualifierInfo(*LocOrErr); |
| 5498 | else |
| 5499 | return LocOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5500 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5501 | if (D->isConstexpr()) |
| 5502 | D2->setConstexpr(true); |
| 5503 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5504 | // Add the specialization to this context. |
| 5505 | D2->setLexicalDeclContext(LexicalDC); |
| 5506 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5507 | |
| 5508 | D2->setAccess(D->getAccess()); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5509 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5510 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5511 | if (Error Err = ImportInitializer(D, D2)) |
| 5512 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5513 | |
| 5514 | return D2; |
| 5515 | } |
| 5516 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5517 | ExpectedDecl |
| 5518 | ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5519 | DeclContext *DC, *LexicalDC; |
| 5520 | DeclarationName Name; |
| 5521 | SourceLocation Loc; |
| 5522 | NamedDecl *ToD; |
| 5523 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5524 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5525 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5526 | |
| 5527 | if (ToD) |
| 5528 | return ToD; |
| 5529 | |
| 5530 | // Try to find a function in our own ("to") context with the same name, same |
| 5531 | // type, and in the same context as the function we're importing. |
| 5532 | if (!LexicalDC->isFunctionOrMethod()) { |
| 5533 | unsigned IDNS = Decl::IDNS_Ordinary; |
| 5534 | SmallVector<NamedDecl *, 2> FoundDecls; |
| 5535 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5536 | for (auto *FoundDecl : FoundDecls) { |
| 5537 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5538 | continue; |
| 5539 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5540 | if (auto *FoundFunction = |
| 5541 | dyn_cast<FunctionTemplateDecl>(FoundDecl)) { |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5542 | if (FoundFunction->hasExternalFormalLinkage() && |
| 5543 | D->hasExternalFormalLinkage()) { |
| 5544 | if (IsStructuralMatch(D, FoundFunction)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5545 | Importer.MapImported(D, FoundFunction); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5546 | // FIXME: Actually try to merge the body and other attributes. |
| 5547 | return FoundFunction; |
| 5548 | } |
| 5549 | } |
| 5550 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5551 | // TODO: handle conflicting names |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5552 | } |
| 5553 | } |
| 5554 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5555 | auto ParamsOrErr = ImportTemplateParameterList( |
| 5556 | D->getTemplateParameters()); |
| 5557 | if (!ParamsOrErr) |
| 5558 | return ParamsOrErr.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5559 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5560 | FunctionDecl *TemplatedFD; |
| 5561 | if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl())) |
| 5562 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5563 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5564 | FunctionTemplateDecl *ToFunc; |
| 5565 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5566 | *ParamsOrErr, TemplatedFD)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5567 | return ToFunc; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5568 | |
| 5569 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); |
| 5570 | ToFunc->setAccess(D->getAccess()); |
| 5571 | ToFunc->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5572 | |
| 5573 | LexicalDC->addDeclInternal(ToFunc); |
| 5574 | return ToFunc; |
| 5575 | } |
| 5576 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5577 | //---------------------------------------------------------------------------- |
| 5578 | // Import Statements |
| 5579 | //---------------------------------------------------------------------------- |
| 5580 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5581 | ExpectedStmt ASTNodeImporter::VisitStmt(Stmt *S) { |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5582 | Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node) |
| 5583 | << S->getStmtClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5584 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5585 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5586 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5587 | |
| 5588 | ExpectedStmt ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5589 | SmallVector<IdentifierInfo *, 4> Names; |
| 5590 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 5591 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5592 | // ToII is nullptr when no symbolic name is given for output operand |
| 5593 | // see ParseStmtAsm::ParseAsmOperandsOpt |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5594 | Names.push_back(ToII); |
| 5595 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5596 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5597 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 5598 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5599 | // ToII is nullptr when no symbolic name is given for input operand |
| 5600 | // see ParseStmtAsm::ParseAsmOperandsOpt |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5601 | Names.push_back(ToII); |
| 5602 | } |
| 5603 | |
| 5604 | SmallVector<StringLiteral *, 4> Clobbers; |
| 5605 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5606 | if (auto ClobberOrErr = import(S->getClobberStringLiteral(I))) |
| 5607 | Clobbers.push_back(*ClobberOrErr); |
| 5608 | else |
| 5609 | return ClobberOrErr.takeError(); |
| 5610 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5611 | } |
| 5612 | |
| 5613 | SmallVector<StringLiteral *, 4> Constraints; |
| 5614 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5615 | if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I))) |
| 5616 | Constraints.push_back(*OutputOrErr); |
| 5617 | else |
| 5618 | return OutputOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5619 | } |
| 5620 | |
| 5621 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5622 | if (auto InputOrErr = import(S->getInputConstraintLiteral(I))) |
| 5623 | Constraints.push_back(*InputOrErr); |
| 5624 | else |
| 5625 | return InputOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5626 | } |
| 5627 | |
| 5628 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5629 | if (Error Err = ImportContainerChecked(S->outputs(), Exprs)) |
| 5630 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5631 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5632 | if (Error Err = ImportArrayChecked( |
| 5633 | S->inputs(), Exprs.begin() + S->getNumOutputs())) |
| 5634 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5635 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5636 | ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc()); |
| 5637 | if (!AsmLocOrErr) |
| 5638 | return AsmLocOrErr.takeError(); |
| 5639 | auto AsmStrOrErr = import(S->getAsmString()); |
| 5640 | if (!AsmStrOrErr) |
| 5641 | return AsmStrOrErr.takeError(); |
| 5642 | ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc()); |
| 5643 | if (!RParenLocOrErr) |
| 5644 | return RParenLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5645 | |
| 5646 | return new (Importer.getToContext()) GCCAsmStmt( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5647 | Importer.getToContext(), |
| 5648 | *AsmLocOrErr, |
| 5649 | S->isSimple(), |
| 5650 | S->isVolatile(), |
| 5651 | S->getNumOutputs(), |
| 5652 | S->getNumInputs(), |
| 5653 | Names.data(), |
| 5654 | Constraints.data(), |
| 5655 | Exprs.data(), |
| 5656 | *AsmStrOrErr, |
| 5657 | S->getNumClobbers(), |
| 5658 | Clobbers.data(), |
| 5659 | *RParenLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5660 | } |
| 5661 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5662 | ExpectedStmt ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| 5663 | auto Imp = importSeq(S->getDeclGroup(), S->getBeginLoc(), S->getEndLoc()); |
| 5664 | if (!Imp) |
| 5665 | return Imp.takeError(); |
| 5666 | |
| 5667 | DeclGroupRef ToDG; |
| 5668 | SourceLocation ToBeginLoc, ToEndLoc; |
| 5669 | std::tie(ToDG, ToBeginLoc, ToEndLoc) = *Imp; |
| 5670 | |
| 5671 | return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5672 | } |
| 5673 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5674 | ExpectedStmt ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 5675 | ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc()); |
| 5676 | if (!ToSemiLocOrErr) |
| 5677 | return ToSemiLocOrErr.takeError(); |
| 5678 | return new (Importer.getToContext()) NullStmt( |
| 5679 | *ToSemiLocOrErr, S->hasLeadingEmptyMacro()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5680 | } |
| 5681 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5682 | ExpectedStmt ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5683 | SmallVector<Stmt *, 8> ToStmts(S->size()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5684 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5685 | if (Error Err = ImportContainerChecked(S->body(), ToStmts)) |
| 5686 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5687 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5688 | ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc()); |
| 5689 | if (!ToLBracLocOrErr) |
| 5690 | return ToLBracLocOrErr.takeError(); |
| 5691 | |
| 5692 | ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc()); |
| 5693 | if (!ToRBracLocOrErr) |
| 5694 | return ToRBracLocOrErr.takeError(); |
| 5695 | |
| 5696 | return CompoundStmt::Create( |
| 5697 | Importer.getToContext(), ToStmts, |
| 5698 | *ToLBracLocOrErr, *ToRBracLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5699 | } |
| 5700 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5701 | ExpectedStmt ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| 5702 | auto Imp = importSeq( |
| 5703 | S->getLHS(), S->getRHS(), S->getSubStmt(), S->getCaseLoc(), |
| 5704 | S->getEllipsisLoc(), S->getColonLoc()); |
| 5705 | if (!Imp) |
| 5706 | return Imp.takeError(); |
| 5707 | |
| 5708 | Expr *ToLHS, *ToRHS; |
| 5709 | Stmt *ToSubStmt; |
| 5710 | SourceLocation ToCaseLoc, ToEllipsisLoc, ToColonLoc; |
| 5711 | std::tie(ToLHS, ToRHS, ToSubStmt, ToCaseLoc, ToEllipsisLoc, ToColonLoc) = |
| 5712 | *Imp; |
| 5713 | |
Bruno Ricci | 5b3057175 | 2018-10-28 12:30:53 +0000 | [diff] [blame] | 5714 | auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS, |
| 5715 | ToCaseLoc, ToEllipsisLoc, ToColonLoc); |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5716 | ToStmt->setSubStmt(ToSubStmt); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5717 | |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5718 | return ToStmt; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5719 | } |
| 5720 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5721 | ExpectedStmt ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| 5722 | auto Imp = importSeq(S->getDefaultLoc(), S->getColonLoc(), S->getSubStmt()); |
| 5723 | if (!Imp) |
| 5724 | return Imp.takeError(); |
| 5725 | |
| 5726 | SourceLocation ToDefaultLoc, ToColonLoc; |
| 5727 | Stmt *ToSubStmt; |
| 5728 | std::tie(ToDefaultLoc, ToColonLoc, ToSubStmt) = *Imp; |
| 5729 | |
| 5730 | return new (Importer.getToContext()) DefaultStmt( |
| 5731 | ToDefaultLoc, ToColonLoc, ToSubStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5732 | } |
| 5733 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5734 | ExpectedStmt ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| 5735 | auto Imp = importSeq(S->getIdentLoc(), S->getDecl(), S->getSubStmt()); |
| 5736 | if (!Imp) |
| 5737 | return Imp.takeError(); |
| 5738 | |
| 5739 | SourceLocation ToIdentLoc; |
| 5740 | LabelDecl *ToLabelDecl; |
| 5741 | Stmt *ToSubStmt; |
| 5742 | std::tie(ToIdentLoc, ToLabelDecl, ToSubStmt) = *Imp; |
| 5743 | |
| 5744 | return new (Importer.getToContext()) LabelStmt( |
| 5745 | ToIdentLoc, ToLabelDecl, ToSubStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5746 | } |
| 5747 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5748 | ExpectedStmt ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { |
| 5749 | ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc()); |
| 5750 | if (!ToAttrLocOrErr) |
| 5751 | return ToAttrLocOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5752 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 5753 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5754 | if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs)) |
| 5755 | return std::move(Err); |
| 5756 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 5757 | if (!ToSubStmtOrErr) |
| 5758 | return ToSubStmtOrErr.takeError(); |
| 5759 | |
| 5760 | return AttributedStmt::Create( |
| 5761 | Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5762 | } |
| 5763 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5764 | ExpectedStmt ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| 5765 | auto Imp = importSeq( |
| 5766 | S->getIfLoc(), S->getInit(), S->getConditionVariable(), S->getCond(), |
| 5767 | S->getThen(), S->getElseLoc(), S->getElse()); |
| 5768 | if (!Imp) |
| 5769 | return Imp.takeError(); |
| 5770 | |
| 5771 | SourceLocation ToIfLoc, ToElseLoc; |
| 5772 | Stmt *ToInit, *ToThen, *ToElse; |
| 5773 | VarDecl *ToConditionVariable; |
| 5774 | Expr *ToCond; |
| 5775 | std::tie( |
| 5776 | ToIfLoc, ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, ToElse) = |
| 5777 | *Imp; |
| 5778 | |
Bruno Ricci | b1cc94b | 2018-10-27 21:12:20 +0000 | [diff] [blame] | 5779 | return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->isConstexpr(), |
| 5780 | ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, |
| 5781 | ToElse); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5782 | } |
| 5783 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5784 | ExpectedStmt ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
| 5785 | auto Imp = importSeq( |
| 5786 | S->getInit(), S->getConditionVariable(), S->getCond(), |
| 5787 | S->getBody(), S->getSwitchLoc()); |
| 5788 | if (!Imp) |
| 5789 | return Imp.takeError(); |
| 5790 | |
| 5791 | Stmt *ToInit, *ToBody; |
| 5792 | VarDecl *ToConditionVariable; |
| 5793 | Expr *ToCond; |
| 5794 | SourceLocation ToSwitchLoc; |
| 5795 | std::tie(ToInit, ToConditionVariable, ToCond, ToBody, ToSwitchLoc) = *Imp; |
| 5796 | |
Bruno Ricci | e2806f8 | 2018-10-29 16:12:37 +0000 | [diff] [blame] | 5797 | auto *ToStmt = SwitchStmt::Create(Importer.getToContext(), ToInit, |
| 5798 | ToConditionVariable, ToCond); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5799 | ToStmt->setBody(ToBody); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5800 | ToStmt->setSwitchLoc(ToSwitchLoc); |
| 5801 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5802 | // Now we have to re-chain the cases. |
| 5803 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 5804 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 5805 | SC = SC->getNextSwitchCase()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5806 | Expected<SwitchCase *> ToSCOrErr = import(SC); |
| 5807 | if (!ToSCOrErr) |
| 5808 | return ToSCOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5809 | if (LastChainedSwitchCase) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5810 | LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5811 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5812 | ToStmt->setSwitchCaseList(*ToSCOrErr); |
| 5813 | LastChainedSwitchCase = *ToSCOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5814 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5815 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5816 | return ToStmt; |
| 5817 | } |
| 5818 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5819 | ExpectedStmt ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| 5820 | auto Imp = importSeq( |
| 5821 | S->getConditionVariable(), S->getCond(), S->getBody(), S->getWhileLoc()); |
| 5822 | if (!Imp) |
| 5823 | return Imp.takeError(); |
| 5824 | |
| 5825 | VarDecl *ToConditionVariable; |
| 5826 | Expr *ToCond; |
| 5827 | Stmt *ToBody; |
| 5828 | SourceLocation ToWhileLoc; |
| 5829 | std::tie(ToConditionVariable, ToCond, ToBody, ToWhileLoc) = *Imp; |
| 5830 | |
Bruno Ricci | bacf751 | 2018-10-30 13:42:41 +0000 | [diff] [blame] | 5831 | return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond, |
| 5832 | ToBody, ToWhileLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5833 | } |
| 5834 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5835 | ExpectedStmt ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| 5836 | auto Imp = importSeq( |
| 5837 | S->getBody(), S->getCond(), S->getDoLoc(), S->getWhileLoc(), |
| 5838 | S->getRParenLoc()); |
| 5839 | if (!Imp) |
| 5840 | return Imp.takeError(); |
| 5841 | |
| 5842 | Stmt *ToBody; |
| 5843 | Expr *ToCond; |
| 5844 | SourceLocation ToDoLoc, ToWhileLoc, ToRParenLoc; |
| 5845 | std::tie(ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc) = *Imp; |
| 5846 | |
| 5847 | return new (Importer.getToContext()) DoStmt( |
| 5848 | ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5849 | } |
| 5850 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5851 | ExpectedStmt ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| 5852 | auto Imp = importSeq( |
| 5853 | S->getInit(), S->getCond(), S->getConditionVariable(), S->getInc(), |
| 5854 | S->getBody(), S->getForLoc(), S->getLParenLoc(), S->getRParenLoc()); |
| 5855 | if (!Imp) |
| 5856 | return Imp.takeError(); |
| 5857 | |
| 5858 | Stmt *ToInit; |
| 5859 | Expr *ToCond, *ToInc; |
| 5860 | VarDecl *ToConditionVariable; |
| 5861 | Stmt *ToBody; |
| 5862 | SourceLocation ToForLoc, ToLParenLoc, ToRParenLoc; |
| 5863 | std::tie( |
| 5864 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, |
| 5865 | ToLParenLoc, ToRParenLoc) = *Imp; |
| 5866 | |
| 5867 | return new (Importer.getToContext()) ForStmt( |
| 5868 | Importer.getToContext(), |
| 5869 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc, |
| 5870 | ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5871 | } |
| 5872 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5873 | ExpectedStmt ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| 5874 | auto Imp = importSeq(S->getLabel(), S->getGotoLoc(), S->getLabelLoc()); |
| 5875 | if (!Imp) |
| 5876 | return Imp.takeError(); |
| 5877 | |
| 5878 | LabelDecl *ToLabel; |
| 5879 | SourceLocation ToGotoLoc, ToLabelLoc; |
| 5880 | std::tie(ToLabel, ToGotoLoc, ToLabelLoc) = *Imp; |
| 5881 | |
| 5882 | return new (Importer.getToContext()) GotoStmt( |
| 5883 | ToLabel, ToGotoLoc, ToLabelLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5884 | } |
| 5885 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5886 | ExpectedStmt ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 5887 | auto Imp = importSeq(S->getGotoLoc(), S->getStarLoc(), S->getTarget()); |
| 5888 | if (!Imp) |
| 5889 | return Imp.takeError(); |
| 5890 | |
| 5891 | SourceLocation ToGotoLoc, ToStarLoc; |
| 5892 | Expr *ToTarget; |
| 5893 | std::tie(ToGotoLoc, ToStarLoc, ToTarget) = *Imp; |
| 5894 | |
| 5895 | return new (Importer.getToContext()) IndirectGotoStmt( |
| 5896 | ToGotoLoc, ToStarLoc, ToTarget); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5897 | } |
| 5898 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5899 | ExpectedStmt ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 5900 | ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc()); |
| 5901 | if (!ToContinueLocOrErr) |
| 5902 | return ToContinueLocOrErr.takeError(); |
| 5903 | return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5904 | } |
| 5905 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5906 | ExpectedStmt ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 5907 | auto ToBreakLocOrErr = import(S->getBreakLoc()); |
| 5908 | if (!ToBreakLocOrErr) |
| 5909 | return ToBreakLocOrErr.takeError(); |
| 5910 | return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5911 | } |
| 5912 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5913 | ExpectedStmt ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| 5914 | auto Imp = importSeq( |
| 5915 | S->getReturnLoc(), S->getRetValue(), S->getNRVOCandidate()); |
| 5916 | if (!Imp) |
| 5917 | return Imp.takeError(); |
| 5918 | |
| 5919 | SourceLocation ToReturnLoc; |
| 5920 | Expr *ToRetValue; |
| 5921 | const VarDecl *ToNRVOCandidate; |
| 5922 | std::tie(ToReturnLoc, ToRetValue, ToNRVOCandidate) = *Imp; |
| 5923 | |
Bruno Ricci | 023b1d1 | 2018-10-30 14:40:49 +0000 | [diff] [blame] | 5924 | return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue, |
| 5925 | ToNRVOCandidate); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5926 | } |
| 5927 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5928 | ExpectedStmt ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| 5929 | auto Imp = importSeq( |
| 5930 | S->getCatchLoc(), S->getExceptionDecl(), S->getHandlerBlock()); |
| 5931 | if (!Imp) |
| 5932 | return Imp.takeError(); |
| 5933 | |
| 5934 | SourceLocation ToCatchLoc; |
| 5935 | VarDecl *ToExceptionDecl; |
| 5936 | Stmt *ToHandlerBlock; |
| 5937 | std::tie(ToCatchLoc, ToExceptionDecl, ToHandlerBlock) = *Imp; |
| 5938 | |
| 5939 | return new (Importer.getToContext()) CXXCatchStmt ( |
| 5940 | ToCatchLoc, ToExceptionDecl, ToHandlerBlock); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5941 | } |
| 5942 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5943 | ExpectedStmt ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 5944 | ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc()); |
| 5945 | if (!ToTryLocOrErr) |
| 5946 | return ToTryLocOrErr.takeError(); |
| 5947 | |
| 5948 | ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock()); |
| 5949 | if (!ToTryBlockOrErr) |
| 5950 | return ToTryBlockOrErr.takeError(); |
| 5951 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5952 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 5953 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 5954 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5955 | if (auto ToHandlerOrErr = import(FromHandler)) |
| 5956 | ToHandlers[HI] = *ToHandlerOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5957 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5958 | return ToHandlerOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5959 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5960 | |
| 5961 | return CXXTryStmt::Create( |
| 5962 | Importer.getToContext(), *ToTryLocOrErr,*ToTryBlockOrErr, ToHandlers); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5963 | } |
| 5964 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5965 | ExpectedStmt ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
| 5966 | auto Imp1 = importSeq( |
| 5967 | S->getInit(), S->getRangeStmt(), S->getBeginStmt(), S->getEndStmt(), |
| 5968 | S->getCond(), S->getInc(), S->getLoopVarStmt(), S->getBody()); |
| 5969 | if (!Imp1) |
| 5970 | return Imp1.takeError(); |
| 5971 | auto Imp2 = importSeq( |
| 5972 | S->getForLoc(), S->getCoawaitLoc(), S->getColonLoc(), S->getRParenLoc()); |
| 5973 | if (!Imp2) |
| 5974 | return Imp2.takeError(); |
| 5975 | |
| 5976 | DeclStmt *ToRangeStmt, *ToBeginStmt, *ToEndStmt, *ToLoopVarStmt; |
| 5977 | Expr *ToCond, *ToInc; |
| 5978 | Stmt *ToInit, *ToBody; |
| 5979 | std::tie( |
| 5980 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 5981 | ToBody) = *Imp1; |
| 5982 | SourceLocation ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc; |
| 5983 | std::tie(ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc) = *Imp2; |
| 5984 | |
| 5985 | return new (Importer.getToContext()) CXXForRangeStmt( |
| 5986 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 5987 | ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc); |
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 |
| 5991 | ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 5992 | auto Imp = importSeq( |
| 5993 | S->getElement(), S->getCollection(), S->getBody(), |
| 5994 | S->getForLoc(), S->getRParenLoc()); |
| 5995 | if (!Imp) |
| 5996 | return Imp.takeError(); |
| 5997 | |
| 5998 | Stmt *ToElement, *ToBody; |
| 5999 | Expr *ToCollection; |
| 6000 | SourceLocation ToForLoc, ToRParenLoc; |
| 6001 | std::tie(ToElement, ToCollection, ToBody, ToForLoc, ToRParenLoc) = *Imp; |
| 6002 | |
| 6003 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement, |
| 6004 | ToCollection, |
| 6005 | ToBody, |
| 6006 | ToForLoc, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6007 | ToRParenLoc); |
| 6008 | } |
| 6009 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6010 | ExpectedStmt ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 6011 | auto Imp = importSeq( |
| 6012 | S->getAtCatchLoc(), S->getRParenLoc(), S->getCatchParamDecl(), |
| 6013 | S->getCatchBody()); |
| 6014 | if (!Imp) |
| 6015 | return Imp.takeError(); |
| 6016 | |
| 6017 | SourceLocation ToAtCatchLoc, ToRParenLoc; |
| 6018 | VarDecl *ToCatchParamDecl; |
| 6019 | Stmt *ToCatchBody; |
| 6020 | std::tie(ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody) = *Imp; |
| 6021 | |
| 6022 | return new (Importer.getToContext()) ObjCAtCatchStmt ( |
| 6023 | ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6024 | } |
| 6025 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6026 | ExpectedStmt ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 6027 | ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc()); |
| 6028 | if (!ToAtFinallyLocOrErr) |
| 6029 | return ToAtFinallyLocOrErr.takeError(); |
| 6030 | ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody()); |
| 6031 | if (!ToAtFinallyStmtOrErr) |
| 6032 | return ToAtFinallyStmtOrErr.takeError(); |
| 6033 | return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr, |
| 6034 | *ToAtFinallyStmtOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6035 | } |
| 6036 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6037 | ExpectedStmt ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 6038 | auto Imp = importSeq( |
| 6039 | S->getAtTryLoc(), S->getTryBody(), S->getFinallyStmt()); |
| 6040 | if (!Imp) |
| 6041 | return Imp.takeError(); |
| 6042 | |
| 6043 | SourceLocation ToAtTryLoc; |
| 6044 | Stmt *ToTryBody, *ToFinallyStmt; |
| 6045 | std::tie(ToAtTryLoc, ToTryBody, ToFinallyStmt) = *Imp; |
| 6046 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6047 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 6048 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 6049 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6050 | if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt)) |
| 6051 | ToCatchStmts[CI] = *ToCatchStmtOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6052 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6053 | return ToCatchStmtOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6054 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6055 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6056 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6057 | ToAtTryLoc, ToTryBody, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6058 | ToCatchStmts.begin(), ToCatchStmts.size(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6059 | ToFinallyStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6060 | } |
| 6061 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6062 | ExpectedStmt ASTNodeImporter::VisitObjCAtSynchronizedStmt |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6063 | (ObjCAtSynchronizedStmt *S) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6064 | auto Imp = importSeq( |
| 6065 | S->getAtSynchronizedLoc(), S->getSynchExpr(), S->getSynchBody()); |
| 6066 | if (!Imp) |
| 6067 | return Imp.takeError(); |
| 6068 | |
| 6069 | SourceLocation ToAtSynchronizedLoc; |
| 6070 | Expr *ToSynchExpr; |
| 6071 | Stmt *ToSynchBody; |
| 6072 | std::tie(ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody) = *Imp; |
| 6073 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6074 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 6075 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 6076 | } |
| 6077 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6078 | ExpectedStmt ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 6079 | ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc()); |
| 6080 | if (!ToThrowLocOrErr) |
| 6081 | return ToThrowLocOrErr.takeError(); |
| 6082 | ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr()); |
| 6083 | if (!ToThrowExprOrErr) |
| 6084 | return ToThrowExprOrErr.takeError(); |
| 6085 | return new (Importer.getToContext()) ObjCAtThrowStmt( |
| 6086 | *ToThrowLocOrErr, *ToThrowExprOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6087 | } |
| 6088 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6089 | ExpectedStmt ASTNodeImporter::VisitObjCAutoreleasePoolStmt( |
| 6090 | ObjCAutoreleasePoolStmt *S) { |
| 6091 | ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc()); |
| 6092 | if (!ToAtLocOrErr) |
| 6093 | return ToAtLocOrErr.takeError(); |
| 6094 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 6095 | if (!ToSubStmtOrErr) |
| 6096 | return ToSubStmtOrErr.takeError(); |
| 6097 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr, |
| 6098 | *ToSubStmtOrErr); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6099 | } |
| 6100 | |
| 6101 | //---------------------------------------------------------------------------- |
| 6102 | // Import Expressions |
| 6103 | //---------------------------------------------------------------------------- |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6104 | ExpectedStmt ASTNodeImporter::VisitExpr(Expr *E) { |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6105 | Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node) |
| 6106 | << E->getStmtClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6107 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6108 | } |
| 6109 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6110 | ExpectedStmt ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| 6111 | auto Imp = importSeq( |
| 6112 | E->getBuiltinLoc(), E->getSubExpr(), E->getWrittenTypeInfo(), |
| 6113 | E->getRParenLoc(), E->getType()); |
| 6114 | if (!Imp) |
| 6115 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6116 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6117 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6118 | Expr *ToSubExpr; |
| 6119 | TypeSourceInfo *ToWrittenTypeInfo; |
| 6120 | QualType ToType; |
| 6121 | std::tie(ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType) = |
| 6122 | *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6123 | |
| 6124 | return new (Importer.getToContext()) VAArgExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6125 | ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType, |
| 6126 | E->isMicrosoftABI()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6127 | } |
| 6128 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6129 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6130 | ExpectedStmt ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 6131 | ExpectedType TypeOrErr = import(E->getType()); |
| 6132 | if (!TypeOrErr) |
| 6133 | return TypeOrErr.takeError(); |
| 6134 | |
| 6135 | ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc()); |
| 6136 | if (!BeginLocOrErr) |
| 6137 | return BeginLocOrErr.takeError(); |
| 6138 | |
| 6139 | return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6140 | } |
| 6141 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6142 | ExpectedStmt ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { |
| 6143 | auto Imp = importSeq( |
| 6144 | E->getBeginLoc(), E->getType(), E->getFunctionName()); |
| 6145 | if (!Imp) |
| 6146 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6147 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6148 | SourceLocation ToBeginLoc; |
| 6149 | QualType ToType; |
| 6150 | StringLiteral *ToFunctionName; |
| 6151 | std::tie(ToBeginLoc, ToType, ToFunctionName) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6152 | |
Bruno Ricci | 17ff026 | 2018-10-27 19:21:19 +0000 | [diff] [blame] | 6153 | return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType, |
| 6154 | E->getIdentKind(), ToFunctionName); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6155 | } |
| 6156 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6157 | ExpectedStmt ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
| 6158 | auto Imp = importSeq( |
| 6159 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDecl(), |
| 6160 | E->getLocation(), E->getType()); |
| 6161 | if (!Imp) |
| 6162 | return Imp.takeError(); |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6163 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6164 | NestedNameSpecifierLoc ToQualifierLoc; |
| 6165 | SourceLocation ToTemplateKeywordLoc, ToLocation; |
| 6166 | ValueDecl *ToDecl; |
| 6167 | QualType ToType; |
| 6168 | std::tie(ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, ToLocation, ToType) = |
| 6169 | *Imp; |
| 6170 | |
| 6171 | NamedDecl *ToFoundD = nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6172 | if (E->getDecl() != E->getFoundDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6173 | auto FoundDOrErr = import(E->getFoundDecl()); |
| 6174 | if (!FoundDOrErr) |
| 6175 | return FoundDOrErr.takeError(); |
| 6176 | ToFoundD = *FoundDOrErr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6177 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6178 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6179 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6180 | TemplateArgumentListInfo *ToResInfo = nullptr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6181 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6182 | if (Error Err = |
| 6183 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 6184 | return std::move(Err); |
| 6185 | ToResInfo = &ToTAInfo; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6186 | } |
| 6187 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6188 | auto *ToE = DeclRefExpr::Create( |
| 6189 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, |
| 6190 | E->refersToEnclosingVariableOrCapture(), ToLocation, ToType, |
| 6191 | E->getValueKind(), ToFoundD, ToResInfo); |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 6192 | if (E->hadMultipleCandidates()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6193 | ToE->setHadMultipleCandidates(true); |
| 6194 | return ToE; |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 6195 | } |
| 6196 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6197 | ExpectedStmt ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 6198 | ExpectedType TypeOrErr = import(E->getType()); |
| 6199 | if (!TypeOrErr) |
| 6200 | return TypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6201 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6202 | return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6203 | } |
| 6204 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6205 | ExpectedStmt ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { |
| 6206 | ExpectedExpr ToInitOrErr = import(E->getInit()); |
| 6207 | if (!ToInitOrErr) |
| 6208 | return ToInitOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6209 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6210 | ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc()); |
| 6211 | if (!ToEqualOrColonLocOrErr) |
| 6212 | return ToEqualOrColonLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6213 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6214 | SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6215 | // List elements from the second, the first is Init itself |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6216 | for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) { |
| 6217 | if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I))) |
| 6218 | ToIndexExprs[I - 1] = *ToArgOrErr; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6219 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6220 | return ToArgOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6221 | } |
| 6222 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6223 | SmallVector<Designator, 4> ToDesignators(E->size()); |
| 6224 | if (Error Err = ImportContainerChecked(E->designators(), ToDesignators)) |
| 6225 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6226 | |
| 6227 | return DesignatedInitExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6228 | Importer.getToContext(), ToDesignators, |
| 6229 | ToIndexExprs, *ToEqualOrColonLocOrErr, |
| 6230 | E->usesGNUSyntax(), *ToInitOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6231 | } |
| 6232 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6233 | ExpectedStmt |
| 6234 | ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 6235 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6236 | if (!ToTypeOrErr) |
| 6237 | return ToTypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6238 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6239 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6240 | if (!ToLocationOrErr) |
| 6241 | return ToLocationOrErr.takeError(); |
| 6242 | |
| 6243 | return new (Importer.getToContext()) CXXNullPtrLiteralExpr( |
| 6244 | *ToTypeOrErr, *ToLocationOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6245 | } |
| 6246 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6247 | ExpectedStmt ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 6248 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6249 | if (!ToTypeOrErr) |
| 6250 | return ToTypeOrErr.takeError(); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6251 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6252 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6253 | if (!ToLocationOrErr) |
| 6254 | return ToLocationOrErr.takeError(); |
| 6255 | |
| 6256 | return IntegerLiteral::Create( |
| 6257 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6258 | } |
| 6259 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6260 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6261 | ExpectedStmt ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 6262 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6263 | if (!ToTypeOrErr) |
| 6264 | return ToTypeOrErr.takeError(); |
| 6265 | |
| 6266 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6267 | if (!ToLocationOrErr) |
| 6268 | return ToLocationOrErr.takeError(); |
| 6269 | |
| 6270 | return FloatingLiteral::Create( |
| 6271 | Importer.getToContext(), E->getValue(), E->isExact(), |
| 6272 | *ToTypeOrErr, *ToLocationOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6273 | } |
| 6274 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6275 | ExpectedStmt ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) { |
| 6276 | auto ToTypeOrErr = import(E->getType()); |
| 6277 | if (!ToTypeOrErr) |
| 6278 | return ToTypeOrErr.takeError(); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6279 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6280 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6281 | if (!ToSubExprOrErr) |
| 6282 | return ToSubExprOrErr.takeError(); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6283 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6284 | return new (Importer.getToContext()) ImaginaryLiteral( |
| 6285 | *ToSubExprOrErr, *ToTypeOrErr); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6286 | } |
| 6287 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6288 | ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 6289 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6290 | if (!ToTypeOrErr) |
| 6291 | return ToTypeOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6292 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6293 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6294 | if (!ToLocationOrErr) |
| 6295 | return ToLocationOrErr.takeError(); |
| 6296 | |
| 6297 | return new (Importer.getToContext()) CharacterLiteral( |
| 6298 | E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr); |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 6299 | } |
| 6300 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6301 | ExpectedStmt ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 6302 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6303 | if (!ToTypeOrErr) |
| 6304 | return ToTypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6305 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6306 | SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated()); |
| 6307 | if (Error Err = ImportArrayChecked( |
| 6308 | E->tokloc_begin(), E->tokloc_end(), ToLocations.begin())) |
| 6309 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6310 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6311 | return StringLiteral::Create( |
| 6312 | Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(), |
| 6313 | *ToTypeOrErr, ToLocations.data(), ToLocations.size()); |
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::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 6317 | auto Imp = importSeq( |
| 6318 | E->getLParenLoc(), E->getTypeSourceInfo(), E->getType(), |
| 6319 | E->getInitializer()); |
| 6320 | if (!Imp) |
| 6321 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6322 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6323 | SourceLocation ToLParenLoc; |
| 6324 | TypeSourceInfo *ToTypeSourceInfo; |
| 6325 | QualType ToType; |
| 6326 | Expr *ToInitializer; |
| 6327 | std::tie(ToLParenLoc, ToTypeSourceInfo, ToType, ToInitializer) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6328 | |
| 6329 | return new (Importer.getToContext()) CompoundLiteralExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6330 | ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(), |
| 6331 | ToInitializer, E->isFileScope()); |
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 | ExpectedStmt ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { |
| 6335 | auto Imp = importSeq( |
| 6336 | E->getBuiltinLoc(), E->getType(), E->getRParenLoc()); |
| 6337 | if (!Imp) |
| 6338 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6339 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6340 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6341 | QualType ToType; |
| 6342 | std::tie(ToBuiltinLoc, ToType, ToRParenLoc) = *Imp; |
| 6343 | |
| 6344 | SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs()); |
| 6345 | if (Error Err = ImportArrayChecked( |
| 6346 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 6347 | ToExprs.begin())) |
| 6348 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6349 | |
| 6350 | return new (Importer.getToContext()) AtomicExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6351 | ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6352 | } |
| 6353 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6354 | ExpectedStmt ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 6355 | auto Imp = importSeq( |
| 6356 | E->getAmpAmpLoc(), E->getLabelLoc(), E->getLabel(), E->getType()); |
| 6357 | if (!Imp) |
| 6358 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6359 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6360 | SourceLocation ToAmpAmpLoc, ToLabelLoc; |
| 6361 | LabelDecl *ToLabel; |
| 6362 | QualType ToType; |
| 6363 | std::tie(ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6364 | |
| 6365 | return new (Importer.getToContext()) AddrLabelExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6366 | ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6367 | } |
| 6368 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6369 | ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| 6370 | auto Imp = importSeq(E->getLParen(), E->getRParen(), E->getSubExpr()); |
| 6371 | if (!Imp) |
| 6372 | return Imp.takeError(); |
| 6373 | |
| 6374 | SourceLocation ToLParen, ToRParen; |
| 6375 | Expr *ToSubExpr; |
| 6376 | std::tie(ToLParen, ToRParen, ToSubExpr) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6377 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6378 | return new (Importer.getToContext()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6379 | ParenExpr(ToLParen, ToRParen, ToSubExpr); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6380 | } |
| 6381 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6382 | ExpectedStmt ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 6383 | SmallVector<Expr *, 4> ToExprs(E->getNumExprs()); |
| 6384 | if (Error Err = ImportContainerChecked(E->exprs(), ToExprs)) |
| 6385 | return std::move(Err); |
| 6386 | |
| 6387 | ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc()); |
| 6388 | if (!ToLParenLocOrErr) |
| 6389 | return ToLParenLocOrErr.takeError(); |
| 6390 | |
| 6391 | ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc()); |
| 6392 | if (!ToRParenLocOrErr) |
| 6393 | return ToRParenLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6394 | |
| 6395 | return new (Importer.getToContext()) ParenListExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6396 | Importer.getToContext(), *ToLParenLocOrErr, ToExprs, *ToRParenLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6397 | } |
| 6398 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6399 | ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| 6400 | auto Imp = importSeq( |
| 6401 | E->getSubStmt(), E->getType(), E->getLParenLoc(), E->getRParenLoc()); |
| 6402 | if (!Imp) |
| 6403 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6404 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6405 | CompoundStmt *ToSubStmt; |
| 6406 | QualType ToType; |
| 6407 | SourceLocation ToLParenLoc, ToRParenLoc; |
| 6408 | std::tie(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6409 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6410 | return new (Importer.getToContext()) StmtExpr( |
| 6411 | ToSubStmt, ToType, ToLParenLoc, ToRParenLoc); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6412 | } |
| 6413 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6414 | ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| 6415 | auto Imp = importSeq( |
| 6416 | E->getSubExpr(), E->getType(), E->getOperatorLoc()); |
| 6417 | if (!Imp) |
| 6418 | return Imp.takeError(); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6419 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6420 | Expr *ToSubExpr; |
| 6421 | QualType ToType; |
| 6422 | SourceLocation ToOperatorLoc; |
| 6423 | std::tie(ToSubExpr, ToType, ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6424 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6425 | return new (Importer.getToContext()) UnaryOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6426 | ToSubExpr, E->getOpcode(), ToType, E->getValueKind(), E->getObjectKind(), |
| 6427 | ToOperatorLoc, E->canOverflow()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6428 | } |
| 6429 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6430 | ExpectedStmt |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6431 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6432 | auto Imp = importSeq(E->getType(), E->getOperatorLoc(), E->getRParenLoc()); |
| 6433 | if (!Imp) |
| 6434 | return Imp.takeError(); |
| 6435 | |
| 6436 | QualType ToType; |
| 6437 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 6438 | std::tie(ToType, ToOperatorLoc, ToRParenLoc) = *Imp; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6439 | |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6440 | if (E->isArgumentType()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6441 | Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr = |
| 6442 | import(E->getArgumentTypeInfo()); |
| 6443 | if (!ToArgumentTypeInfoOrErr) |
| 6444 | return ToArgumentTypeInfoOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6445 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6446 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6447 | E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc, |
| 6448 | ToRParenLoc); |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6449 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6450 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6451 | ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr()); |
| 6452 | if (!ToArgumentExprOrErr) |
| 6453 | return ToArgumentExprOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6454 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6455 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6456 | E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc); |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6457 | } |
| 6458 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6459 | ExpectedStmt ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| 6460 | auto Imp = importSeq( |
| 6461 | E->getLHS(), E->getRHS(), E->getType(), E->getOperatorLoc()); |
| 6462 | if (!Imp) |
| 6463 | return Imp.takeError(); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6464 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6465 | Expr *ToLHS, *ToRHS; |
| 6466 | QualType ToType; |
| 6467 | SourceLocation ToOperatorLoc; |
| 6468 | std::tie(ToLHS, ToRHS, ToType, ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6469 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6470 | return new (Importer.getToContext()) BinaryOperator( |
| 6471 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6472 | E->getObjectKind(), ToOperatorLoc, E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6473 | } |
| 6474 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6475 | ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| 6476 | auto Imp = importSeq( |
| 6477 | E->getCond(), E->getQuestionLoc(), E->getLHS(), E->getColonLoc(), |
| 6478 | E->getRHS(), E->getType()); |
| 6479 | if (!Imp) |
| 6480 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6481 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6482 | Expr *ToCond, *ToLHS, *ToRHS; |
| 6483 | SourceLocation ToQuestionLoc, ToColonLoc; |
| 6484 | QualType ToType; |
| 6485 | std::tie(ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6486 | |
| 6487 | return new (Importer.getToContext()) ConditionalOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6488 | ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType, |
| 6489 | E->getValueKind(), E->getObjectKind()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6490 | } |
| 6491 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6492 | ExpectedStmt ASTNodeImporter::VisitBinaryConditionalOperator( |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6493 | BinaryConditionalOperator *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6494 | auto Imp = importSeq( |
| 6495 | E->getCommon(), E->getOpaqueValue(), E->getCond(), E->getTrueExpr(), |
| 6496 | E->getFalseExpr(), E->getQuestionLoc(), E->getColonLoc(), E->getType()); |
| 6497 | if (!Imp) |
| 6498 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6499 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6500 | Expr *ToCommon, *ToCond, *ToTrueExpr, *ToFalseExpr; |
| 6501 | OpaqueValueExpr *ToOpaqueValue; |
| 6502 | SourceLocation ToQuestionLoc, ToColonLoc; |
| 6503 | QualType ToType; |
| 6504 | std::tie( |
| 6505 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, ToQuestionLoc, |
| 6506 | ToColonLoc, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6507 | |
| 6508 | return new (Importer.getToContext()) BinaryConditionalOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6509 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, |
| 6510 | ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(), |
| 6511 | E->getObjectKind()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6512 | } |
| 6513 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6514 | ExpectedStmt ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 6515 | auto Imp = importSeq( |
| 6516 | E->getBeginLoc(), E->getQueriedTypeSourceInfo(), |
| 6517 | E->getDimensionExpression(), E->getEndLoc(), E->getType()); |
| 6518 | if (!Imp) |
| 6519 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6520 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6521 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6522 | TypeSourceInfo *ToQueriedTypeSourceInfo; |
| 6523 | Expr *ToDimensionExpression; |
| 6524 | QualType ToType; |
| 6525 | std::tie( |
| 6526 | ToBeginLoc, ToQueriedTypeSourceInfo, ToDimensionExpression, ToEndLoc, |
| 6527 | ToType) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6528 | |
| 6529 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6530 | ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(), |
| 6531 | ToDimensionExpression, ToEndLoc, ToType); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6532 | } |
| 6533 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6534 | ExpectedStmt ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 6535 | auto Imp = importSeq( |
| 6536 | E->getBeginLoc(), E->getQueriedExpression(), E->getEndLoc(), E->getType()); |
| 6537 | if (!Imp) |
| 6538 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6539 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6540 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6541 | Expr *ToQueriedExpression; |
| 6542 | QualType ToType; |
| 6543 | std::tie(ToBeginLoc, ToQueriedExpression, ToEndLoc, ToType) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6544 | |
| 6545 | return new (Importer.getToContext()) ExpressionTraitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6546 | ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(), |
| 6547 | ToEndLoc, ToType); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6548 | } |
| 6549 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6550 | ExpectedStmt ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| 6551 | auto Imp = importSeq( |
| 6552 | E->getLocation(), E->getType(), E->getSourceExpr()); |
| 6553 | if (!Imp) |
| 6554 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6555 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6556 | SourceLocation ToLocation; |
| 6557 | QualType ToType; |
| 6558 | Expr *ToSourceExpr; |
| 6559 | std::tie(ToLocation, ToType, ToSourceExpr) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6560 | |
| 6561 | return new (Importer.getToContext()) OpaqueValueExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6562 | ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6563 | } |
| 6564 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6565 | ExpectedStmt ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 6566 | auto Imp = importSeq( |
| 6567 | E->getLHS(), E->getRHS(), E->getType(), E->getRBracketLoc()); |
| 6568 | if (!Imp) |
| 6569 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6570 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6571 | Expr *ToLHS, *ToRHS; |
| 6572 | SourceLocation ToRBracketLoc; |
| 6573 | QualType ToType; |
| 6574 | std::tie(ToLHS, ToRHS, ToType, ToRBracketLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6575 | |
| 6576 | return new (Importer.getToContext()) ArraySubscriptExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6577 | ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(), |
| 6578 | ToRBracketLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6579 | } |
| 6580 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6581 | ExpectedStmt |
| 6582 | ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 6583 | auto Imp = importSeq( |
| 6584 | E->getLHS(), E->getRHS(), E->getType(), E->getComputationLHSType(), |
| 6585 | E->getComputationResultType(), E->getOperatorLoc()); |
| 6586 | if (!Imp) |
| 6587 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6588 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6589 | Expr *ToLHS, *ToRHS; |
| 6590 | QualType ToType, ToComputationLHSType, ToComputationResultType; |
| 6591 | SourceLocation ToOperatorLoc; |
| 6592 | std::tie(ToLHS, ToRHS, ToType, ToComputationLHSType, ToComputationResultType, |
| 6593 | ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6594 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6595 | return new (Importer.getToContext()) CompoundAssignOperator( |
| 6596 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6597 | E->getObjectKind(), ToComputationLHSType, ToComputationResultType, |
| 6598 | ToOperatorLoc, E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6599 | } |
| 6600 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6601 | Expected<CXXCastPath> |
| 6602 | ASTNodeImporter::ImportCastPath(CastExpr *CE) { |
| 6603 | CXXCastPath Path; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6604 | 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] | 6605 | if (auto SpecOrErr = import(*I)) |
| 6606 | Path.push_back(*SpecOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6607 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6608 | return SpecOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6609 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6610 | return Path; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6611 | } |
| 6612 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6613 | ExpectedStmt ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 6614 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6615 | if (!ToTypeOrErr) |
| 6616 | return ToTypeOrErr.takeError(); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6617 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6618 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6619 | if (!ToSubExprOrErr) |
| 6620 | return ToSubExprOrErr.takeError(); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6621 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6622 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6623 | if (!ToBasePathOrErr) |
| 6624 | return ToBasePathOrErr.takeError(); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6625 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6626 | return ImplicitCastExpr::Create( |
| 6627 | Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr, |
| 6628 | &(*ToBasePathOrErr), E->getValueKind()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6629 | } |
| 6630 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6631 | ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
| 6632 | auto Imp1 = importSeq( |
| 6633 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten()); |
| 6634 | if (!Imp1) |
| 6635 | return Imp1.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6636 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6637 | QualType ToType; |
| 6638 | Expr *ToSubExpr; |
| 6639 | TypeSourceInfo *ToTypeInfoAsWritten; |
| 6640 | std::tie(ToType, ToSubExpr, ToTypeInfoAsWritten) = *Imp1; |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6641 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6642 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6643 | if (!ToBasePathOrErr) |
| 6644 | return ToBasePathOrErr.takeError(); |
| 6645 | CXXCastPath *ToBasePath = &(*ToBasePathOrErr); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6646 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6647 | switch (E->getStmtClass()) { |
| 6648 | case Stmt::CStyleCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6649 | auto *CCE = cast<CStyleCastExpr>(E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6650 | ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc()); |
| 6651 | if (!ToLParenLocOrErr) |
| 6652 | return ToLParenLocOrErr.takeError(); |
| 6653 | ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc()); |
| 6654 | if (!ToRParenLocOrErr) |
| 6655 | return ToRParenLocOrErr.takeError(); |
| 6656 | return CStyleCastExpr::Create( |
| 6657 | Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(), |
| 6658 | ToSubExpr, ToBasePath, ToTypeInfoAsWritten, *ToLParenLocOrErr, |
| 6659 | *ToRParenLocOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6660 | } |
| 6661 | |
| 6662 | case Stmt::CXXFunctionalCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6663 | auto *FCE = cast<CXXFunctionalCastExpr>(E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6664 | ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc()); |
| 6665 | if (!ToLParenLocOrErr) |
| 6666 | return ToLParenLocOrErr.takeError(); |
| 6667 | ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc()); |
| 6668 | if (!ToRParenLocOrErr) |
| 6669 | return ToRParenLocOrErr.takeError(); |
| 6670 | return CXXFunctionalCastExpr::Create( |
| 6671 | Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten, |
| 6672 | E->getCastKind(), ToSubExpr, ToBasePath, *ToLParenLocOrErr, |
| 6673 | *ToRParenLocOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6674 | } |
| 6675 | |
| 6676 | case Stmt::ObjCBridgedCastExprClass: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6677 | auto *OCE = cast<ObjCBridgedCastExpr>(E); |
| 6678 | ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc()); |
| 6679 | if (!ToLParenLocOrErr) |
| 6680 | return ToLParenLocOrErr.takeError(); |
| 6681 | ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc()); |
| 6682 | if (!ToBridgeKeywordLocOrErr) |
| 6683 | return ToBridgeKeywordLocOrErr.takeError(); |
| 6684 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 6685 | *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), |
| 6686 | *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6687 | } |
| 6688 | default: |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6689 | llvm_unreachable("Cast expression of unsupported type!"); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6690 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6691 | } |
| 6692 | } |
| 6693 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6694 | ExpectedStmt ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *E) { |
| 6695 | SmallVector<OffsetOfNode, 4> ToNodes; |
| 6696 | for (int I = 0, N = E->getNumComponents(); I < N; ++I) { |
| 6697 | const OffsetOfNode &FromNode = E->getComponent(I); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6698 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6699 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6700 | if (FromNode.getKind() != OffsetOfNode::Base) { |
| 6701 | auto Imp = importSeq(FromNode.getBeginLoc(), FromNode.getEndLoc()); |
| 6702 | if (!Imp) |
| 6703 | return Imp.takeError(); |
| 6704 | std::tie(ToBeginLoc, ToEndLoc) = *Imp; |
| 6705 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6706 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6707 | switch (FromNode.getKind()) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6708 | case OffsetOfNode::Array: |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6709 | ToNodes.push_back( |
| 6710 | OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6711 | break; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6712 | case OffsetOfNode::Base: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6713 | auto ToBSOrErr = import(FromNode.getBase()); |
| 6714 | if (!ToBSOrErr) |
| 6715 | return ToBSOrErr.takeError(); |
| 6716 | ToNodes.push_back(OffsetOfNode(*ToBSOrErr)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6717 | break; |
| 6718 | } |
| 6719 | case OffsetOfNode::Field: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6720 | auto ToFieldOrErr = import(FromNode.getField()); |
| 6721 | if (!ToFieldOrErr) |
| 6722 | return ToFieldOrErr.takeError(); |
| 6723 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6724 | break; |
| 6725 | } |
| 6726 | case OffsetOfNode::Identifier: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6727 | IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName()); |
| 6728 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6729 | break; |
| 6730 | } |
| 6731 | } |
| 6732 | } |
| 6733 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6734 | SmallVector<Expr *, 4> ToExprs(E->getNumExpressions()); |
| 6735 | for (int I = 0, N = E->getNumExpressions(); I < N; ++I) { |
| 6736 | ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I)); |
| 6737 | if (!ToIndexExprOrErr) |
| 6738 | return ToIndexExprOrErr.takeError(); |
| 6739 | ToExprs[I] = *ToIndexExprOrErr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6740 | } |
| 6741 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6742 | auto Imp = importSeq( |
| 6743 | E->getType(), E->getTypeSourceInfo(), E->getOperatorLoc(), |
| 6744 | E->getRParenLoc()); |
| 6745 | if (!Imp) |
| 6746 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6747 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6748 | QualType ToType; |
| 6749 | TypeSourceInfo *ToTypeSourceInfo; |
| 6750 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 6751 | std::tie(ToType, ToTypeSourceInfo, ToOperatorLoc, ToRParenLoc) = *Imp; |
| 6752 | |
| 6753 | return OffsetOfExpr::Create( |
| 6754 | Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes, |
| 6755 | ToExprs, ToRParenLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6756 | } |
| 6757 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6758 | ExpectedStmt ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 6759 | auto Imp = importSeq( |
| 6760 | E->getType(), E->getOperand(), E->getBeginLoc(), E->getEndLoc()); |
| 6761 | if (!Imp) |
| 6762 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6763 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6764 | QualType ToType; |
| 6765 | Expr *ToOperand; |
| 6766 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6767 | std::tie(ToType, ToOperand, ToBeginLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6768 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6769 | CanThrowResult ToCanThrow; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6770 | if (E->isValueDependent()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6771 | ToCanThrow = CT_Dependent; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6772 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6773 | ToCanThrow = E->getValue() ? CT_Can : CT_Cannot; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6774 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6775 | return new (Importer.getToContext()) CXXNoexceptExpr( |
| 6776 | ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6777 | } |
| 6778 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6779 | ExpectedStmt ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| 6780 | auto Imp = importSeq(E->getSubExpr(), E->getType(), E->getThrowLoc()); |
| 6781 | if (!Imp) |
| 6782 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6783 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6784 | Expr *ToSubExpr; |
| 6785 | QualType ToType; |
| 6786 | SourceLocation ToThrowLoc; |
| 6787 | std::tie(ToSubExpr, ToType, ToThrowLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6788 | |
| 6789 | return new (Importer.getToContext()) CXXThrowExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6790 | ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6791 | } |
| 6792 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6793 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| 6794 | ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation()); |
| 6795 | if (!ToUsedLocOrErr) |
| 6796 | return ToUsedLocOrErr.takeError(); |
| 6797 | |
| 6798 | auto ToParamOrErr = import(E->getParam()); |
| 6799 | if (!ToParamOrErr) |
| 6800 | return ToParamOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6801 | |
| 6802 | return CXXDefaultArgExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6803 | Importer.getToContext(), *ToUsedLocOrErr, *ToParamOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6804 | } |
| 6805 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6806 | ExpectedStmt |
| 6807 | ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| 6808 | auto Imp = importSeq( |
| 6809 | E->getType(), E->getTypeSourceInfo(), E->getRParenLoc()); |
| 6810 | if (!Imp) |
| 6811 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6812 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6813 | QualType ToType; |
| 6814 | TypeSourceInfo *ToTypeSourceInfo; |
| 6815 | SourceLocation ToRParenLoc; |
| 6816 | std::tie(ToType, ToTypeSourceInfo, ToRParenLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6817 | |
| 6818 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6819 | ToType, ToTypeSourceInfo, ToRParenLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6820 | } |
| 6821 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6822 | ExpectedStmt |
| 6823 | ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 6824 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6825 | if (!ToSubExprOrErr) |
| 6826 | return ToSubExprOrErr.takeError(); |
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 | auto ToDtorOrErr = import(E->getTemporary()->getDestructor()); |
| 6829 | if (!ToDtorOrErr) |
| 6830 | return ToDtorOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6831 | |
| 6832 | ASTContext &ToCtx = Importer.getToContext(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6833 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr); |
| 6834 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6835 | } |
| 6836 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6837 | ExpectedStmt |
| 6838 | ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { |
| 6839 | auto Imp = importSeq( |
| 6840 | E->getConstructor(), E->getType(), E->getTypeSourceInfo(), |
| 6841 | E->getParenOrBraceRange()); |
| 6842 | if (!Imp) |
| 6843 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6844 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6845 | CXXConstructorDecl *ToConstructor; |
| 6846 | QualType ToType; |
| 6847 | TypeSourceInfo *ToTypeSourceInfo; |
| 6848 | SourceRange ToParenOrBraceRange; |
| 6849 | std::tie(ToConstructor, ToType, ToTypeSourceInfo, ToParenOrBraceRange) = *Imp; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6850 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6851 | SmallVector<Expr *, 8> ToArgs(E->getNumArgs()); |
| 6852 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 6853 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6854 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6855 | return new (Importer.getToContext()) CXXTemporaryObjectExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6856 | Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs, |
| 6857 | ToParenOrBraceRange, E->hadMultipleCandidates(), |
| 6858 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 6859 | E->requiresZeroInitialization()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6860 | } |
| 6861 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6862 | ExpectedStmt |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6863 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6864 | auto Imp = importSeq( |
| 6865 | E->getType(), E->GetTemporaryExpr(), E->getExtendingDecl()); |
| 6866 | if (!Imp) |
| 6867 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6868 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6869 | QualType ToType; |
| 6870 | Expr *ToTemporaryExpr; |
| 6871 | const ValueDecl *ToExtendingDecl; |
| 6872 | std::tie(ToType, ToTemporaryExpr, ToExtendingDecl) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6873 | |
| 6874 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6875 | ToType, ToTemporaryExpr, E->isBoundToLvalueReference()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6876 | |
| 6877 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6878 | ToMTE->setExtendingDecl(ToExtendingDecl, E->getManglingNumber()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6879 | return ToMTE; |
| 6880 | } |
| 6881 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6882 | ExpectedStmt ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { |
| 6883 | auto Imp = importSeq( |
| 6884 | E->getType(), E->getPattern(), E->getEllipsisLoc()); |
| 6885 | if (!Imp) |
| 6886 | return Imp.takeError(); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6887 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6888 | QualType ToType; |
| 6889 | Expr *ToPattern; |
| 6890 | SourceLocation ToEllipsisLoc; |
| 6891 | std::tie(ToType, ToPattern, ToEllipsisLoc) = *Imp; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6892 | |
| 6893 | return new (Importer.getToContext()) PackExpansionExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6894 | ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions()); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6895 | } |
| 6896 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6897 | ExpectedStmt ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { |
| 6898 | auto Imp = importSeq( |
| 6899 | E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc()); |
| 6900 | if (!Imp) |
| 6901 | return Imp.takeError(); |
| 6902 | |
| 6903 | SourceLocation ToOperatorLoc, ToPackLoc, ToRParenLoc; |
| 6904 | NamedDecl *ToPack; |
| 6905 | std::tie(ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc) = *Imp; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6906 | |
| 6907 | Optional<unsigned> Length; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6908 | if (!E->isValueDependent()) |
| 6909 | Length = E->getPackLength(); |
| 6910 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6911 | SmallVector<TemplateArgument, 8> ToPartialArguments; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6912 | if (E->isPartiallySubstituted()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6913 | if (Error Err = ImportTemplateArguments( |
| 6914 | E->getPartialArguments().data(), |
| 6915 | E->getPartialArguments().size(), |
| 6916 | ToPartialArguments)) |
| 6917 | return std::move(Err); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6918 | } |
| 6919 | |
| 6920 | return SizeOfPackExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6921 | Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc, |
| 6922 | Length, ToPartialArguments); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6923 | } |
| 6924 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6925 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6926 | ExpectedStmt ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) { |
| 6927 | auto Imp = importSeq( |
| 6928 | E->getOperatorNew(), E->getOperatorDelete(), E->getTypeIdParens(), |
| 6929 | E->getArraySize(), E->getInitializer(), E->getType(), |
| 6930 | E->getAllocatedTypeSourceInfo(), E->getSourceRange(), |
| 6931 | E->getDirectInitRange()); |
| 6932 | if (!Imp) |
| 6933 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6934 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6935 | FunctionDecl *ToOperatorNew, *ToOperatorDelete; |
| 6936 | SourceRange ToTypeIdParens, ToSourceRange, ToDirectInitRange; |
| 6937 | Expr *ToArraySize, *ToInitializer; |
| 6938 | QualType ToType; |
| 6939 | TypeSourceInfo *ToAllocatedTypeSourceInfo; |
| 6940 | std::tie( |
| 6941 | ToOperatorNew, ToOperatorDelete, ToTypeIdParens, ToArraySize, ToInitializer, |
| 6942 | ToType, ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6943 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6944 | SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs()); |
| 6945 | if (Error Err = |
| 6946 | ImportContainerChecked(E->placement_arguments(), ToPlacementArgs)) |
| 6947 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6948 | |
| 6949 | return new (Importer.getToContext()) CXXNewExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6950 | Importer.getToContext(), E->isGlobalNew(), ToOperatorNew, |
| 6951 | ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(), |
| 6952 | ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(), |
| 6953 | ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange, |
| 6954 | ToDirectInitRange); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6955 | } |
| 6956 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6957 | ExpectedStmt ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 6958 | auto Imp = importSeq( |
| 6959 | E->getType(), E->getOperatorDelete(), E->getArgument(), E->getBeginLoc()); |
| 6960 | if (!Imp) |
| 6961 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6962 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6963 | QualType ToType; |
| 6964 | FunctionDecl *ToOperatorDelete; |
| 6965 | Expr *ToArgument; |
| 6966 | SourceLocation ToBeginLoc; |
| 6967 | std::tie(ToType, ToOperatorDelete, ToArgument, ToBeginLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6968 | |
| 6969 | return new (Importer.getToContext()) CXXDeleteExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6970 | ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(), |
| 6971 | E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument, |
| 6972 | ToBeginLoc); |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6973 | } |
| 6974 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6975 | ExpectedStmt ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| 6976 | auto Imp = importSeq( |
| 6977 | E->getType(), E->getLocation(), E->getConstructor(), |
| 6978 | E->getParenOrBraceRange()); |
| 6979 | if (!Imp) |
| 6980 | return Imp.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6981 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6982 | QualType ToType; |
| 6983 | SourceLocation ToLocation; |
| 6984 | CXXConstructorDecl *ToConstructor; |
| 6985 | SourceRange ToParenOrBraceRange; |
| 6986 | std::tie(ToType, ToLocation, ToConstructor, ToParenOrBraceRange) = *Imp; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6987 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6988 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6989 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 6990 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6991 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6992 | return CXXConstructExpr::Create( |
| 6993 | Importer.getToContext(), ToType, ToLocation, ToConstructor, |
| 6994 | E->isElidable(), ToArgs, E->hadMultipleCandidates(), |
| 6995 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 6996 | E->requiresZeroInitialization(), E->getConstructionKind(), |
| 6997 | ToParenOrBraceRange); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6998 | } |
| 6999 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7000 | ExpectedStmt ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *E) { |
| 7001 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7002 | if (!ToSubExprOrErr) |
| 7003 | return ToSubExprOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7004 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7005 | SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects()); |
| 7006 | if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects)) |
| 7007 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7008 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7009 | return ExprWithCleanups::Create( |
| 7010 | Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(), |
| 7011 | ToObjects); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7012 | } |
| 7013 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7014 | ExpectedStmt ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 7015 | auto Imp = importSeq( |
| 7016 | E->getCallee(), E->getType(), E->getRParenLoc()); |
| 7017 | if (!Imp) |
| 7018 | return Imp.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7019 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7020 | Expr *ToCallee; |
| 7021 | QualType ToType; |
| 7022 | SourceLocation ToRParenLoc; |
| 7023 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7024 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7025 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7026 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7027 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7028 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7029 | return new (Importer.getToContext()) CXXMemberCallExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7030 | Importer.getToContext(), ToCallee, ToArgs, ToType, E->getValueKind(), |
| 7031 | ToRParenLoc); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7032 | } |
| 7033 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7034 | ExpectedStmt ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 7035 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7036 | if (!ToTypeOrErr) |
| 7037 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7038 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7039 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7040 | if (!ToLocationOrErr) |
| 7041 | return ToLocationOrErr.takeError(); |
| 7042 | |
| 7043 | return new (Importer.getToContext()) CXXThisExpr( |
| 7044 | *ToLocationOrErr, *ToTypeOrErr, E->isImplicit()); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7045 | } |
| 7046 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7047 | ExpectedStmt ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 7048 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7049 | if (!ToTypeOrErr) |
| 7050 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7051 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7052 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7053 | if (!ToLocationOrErr) |
| 7054 | return ToLocationOrErr.takeError(); |
| 7055 | |
| 7056 | return new (Importer.getToContext()) CXXBoolLiteralExpr( |
| 7057 | E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7058 | } |
| 7059 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7060 | ExpectedStmt ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| 7061 | auto Imp1 = importSeq( |
| 7062 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7063 | E->getTemplateKeywordLoc(), E->getMemberDecl(), E->getType()); |
| 7064 | if (!Imp1) |
| 7065 | return Imp1.takeError(); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7066 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7067 | Expr *ToBase; |
| 7068 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7069 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7070 | ValueDecl *ToMemberDecl; |
| 7071 | QualType ToType; |
| 7072 | std::tie( |
| 7073 | ToBase, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, |
| 7074 | ToType) = *Imp1; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7075 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7076 | auto Imp2 = importSeq( |
| 7077 | E->getFoundDecl().getDecl(), E->getMemberNameInfo().getName(), |
| 7078 | E->getMemberNameInfo().getLoc(), E->getLAngleLoc(), E->getRAngleLoc()); |
| 7079 | if (!Imp2) |
| 7080 | return Imp2.takeError(); |
| 7081 | NamedDecl *ToDecl; |
| 7082 | DeclarationName ToName; |
| 7083 | SourceLocation ToLoc, ToLAngleLoc, ToRAngleLoc; |
| 7084 | std::tie(ToDecl, ToName, ToLoc, ToLAngleLoc, ToRAngleLoc) = *Imp2; |
Peter Szecsi | ef97252 | 2018-05-02 11:52:54 +0000 | [diff] [blame] | 7085 | |
| 7086 | DeclAccessPair ToFoundDecl = |
| 7087 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7088 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7089 | DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7090 | |
| 7091 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7092 | // FIXME: handle template arguments |
| 7093 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7094 | } |
| 7095 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7096 | return MemberExpr::Create( |
| 7097 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, |
| 7098 | ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, ToFoundDecl, |
| 7099 | ToMemberNameInfo, nullptr, ToType, E->getValueKind(), E->getObjectKind()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7100 | } |
| 7101 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7102 | ExpectedStmt |
| 7103 | ASTNodeImporter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { |
| 7104 | auto Imp = importSeq( |
| 7105 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7106 | E->getScopeTypeInfo(), E->getColonColonLoc(), E->getTildeLoc()); |
| 7107 | if (!Imp) |
| 7108 | return Imp.takeError(); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7109 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7110 | Expr *ToBase; |
| 7111 | SourceLocation ToOperatorLoc, ToColonColonLoc, ToTildeLoc; |
| 7112 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7113 | TypeSourceInfo *ToScopeTypeInfo; |
| 7114 | std::tie( |
| 7115 | ToBase, ToOperatorLoc, ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, |
| 7116 | ToTildeLoc) = *Imp; |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7117 | |
| 7118 | PseudoDestructorTypeStorage Storage; |
| 7119 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { |
| 7120 | IdentifierInfo *ToII = Importer.Import(FromII); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7121 | ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc()); |
| 7122 | if (!ToDestroyedTypeLocOrErr) |
| 7123 | return ToDestroyedTypeLocOrErr.takeError(); |
| 7124 | Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7125 | } else { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7126 | if (auto ToTIOrErr = import(E->getDestroyedTypeInfo())) |
| 7127 | Storage = PseudoDestructorTypeStorage(*ToTIOrErr); |
| 7128 | else |
| 7129 | return ToTIOrErr.takeError(); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7130 | } |
| 7131 | |
| 7132 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7133 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, |
| 7134 | ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7135 | } |
| 7136 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7137 | ExpectedStmt ASTNodeImporter::VisitCXXDependentScopeMemberExpr( |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7138 | CXXDependentScopeMemberExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7139 | auto Imp = importSeq( |
| 7140 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7141 | E->getTemplateKeywordLoc(), E->getFirstQualifierFoundInScope()); |
| 7142 | if (!Imp) |
| 7143 | return Imp.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7144 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7145 | QualType ToType; |
| 7146 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7147 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7148 | NamedDecl *ToFirstQualifierFoundInScope; |
| 7149 | std::tie( |
| 7150 | ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7151 | ToFirstQualifierFoundInScope) = *Imp; |
| 7152 | |
| 7153 | Expr *ToBase = nullptr; |
| 7154 | if (!E->isImplicitAccess()) { |
| 7155 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7156 | ToBase = *ToBaseOrErr; |
| 7157 | else |
| 7158 | return ToBaseOrErr.takeError(); |
| 7159 | } |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7160 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7161 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7162 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7163 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7164 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7165 | ToTAInfo)) |
| 7166 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7167 | ResInfo = &ToTAInfo; |
| 7168 | } |
| 7169 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7170 | auto ToMemberNameInfoOrErr = importSeq(E->getMember(), E->getMemberLoc()); |
| 7171 | if (!ToMemberNameInfoOrErr) |
| 7172 | return ToMemberNameInfoOrErr.takeError(); |
| 7173 | DeclarationNameInfo ToMemberNameInfo( |
| 7174 | std::get<0>(*ToMemberNameInfoOrErr), std::get<1>(*ToMemberNameInfoOrErr)); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7175 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7176 | if (Error Err = ImportDeclarationNameLoc( |
| 7177 | E->getMemberNameInfo(), ToMemberNameInfo)) |
| 7178 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7179 | |
| 7180 | return CXXDependentScopeMemberExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7181 | Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc, |
| 7182 | ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope, |
| 7183 | ToMemberNameInfo, ResInfo); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7184 | } |
| 7185 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7186 | ExpectedStmt |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7187 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7188 | auto Imp = importSeq( |
| 7189 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDeclName(), |
| 7190 | E->getExprLoc(), E->getLAngleLoc(), E->getRAngleLoc()); |
| 7191 | if (!Imp) |
| 7192 | return Imp.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7193 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7194 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7195 | SourceLocation ToTemplateKeywordLoc, ToExprLoc, ToLAngleLoc, ToRAngleLoc; |
| 7196 | DeclarationName ToDeclName; |
| 7197 | std::tie( |
| 7198 | ToQualifierLoc, ToTemplateKeywordLoc, ToDeclName, ToExprLoc, |
| 7199 | ToLAngleLoc, ToRAngleLoc) = *Imp; |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7200 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7201 | DeclarationNameInfo ToNameInfo(ToDeclName, ToExprLoc); |
| 7202 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7203 | return std::move(Err); |
| 7204 | |
| 7205 | TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7206 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7207 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7208 | if (Error Err = |
| 7209 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 7210 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7211 | ResInfo = &ToTAInfo; |
| 7212 | } |
| 7213 | |
| 7214 | return DependentScopeDeclRefExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7215 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, |
| 7216 | ToNameInfo, ResInfo); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7217 | } |
| 7218 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7219 | ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr( |
| 7220 | CXXUnresolvedConstructExpr *E) { |
| 7221 | auto Imp = importSeq( |
| 7222 | E->getLParenLoc(), E->getRParenLoc(), E->getTypeSourceInfo()); |
| 7223 | if (!Imp) |
| 7224 | return Imp.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7225 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7226 | SourceLocation ToLParenLoc, ToRParenLoc; |
| 7227 | TypeSourceInfo *ToTypeSourceInfo; |
| 7228 | std::tie(ToLParenLoc, ToRParenLoc, ToTypeSourceInfo) = *Imp; |
| 7229 | |
| 7230 | SmallVector<Expr *, 8> ToArgs(E->arg_size()); |
| 7231 | if (Error Err = |
| 7232 | ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin())) |
| 7233 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7234 | |
| 7235 | return CXXUnresolvedConstructExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7236 | Importer.getToContext(), ToTypeSourceInfo, ToLParenLoc, |
| 7237 | llvm::makeArrayRef(ToArgs), ToRParenLoc); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7238 | } |
| 7239 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7240 | ExpectedStmt |
| 7241 | ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { |
| 7242 | Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass()); |
| 7243 | if (!ToNamingClassOrErr) |
| 7244 | return ToNamingClassOrErr.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7245 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7246 | auto ToQualifierLocOrErr = import(E->getQualifierLoc()); |
| 7247 | if (!ToQualifierLocOrErr) |
| 7248 | return ToQualifierLocOrErr.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7249 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7250 | auto ToNameInfoOrErr = importSeq(E->getName(), E->getNameLoc()); |
| 7251 | if (!ToNameInfoOrErr) |
| 7252 | return ToNameInfoOrErr.takeError(); |
| 7253 | DeclarationNameInfo ToNameInfo( |
| 7254 | std::get<0>(*ToNameInfoOrErr), std::get<1>(*ToNameInfoOrErr)); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7255 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7256 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7257 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7258 | |
| 7259 | UnresolvedSet<8> ToDecls; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7260 | for (auto *D : E->decls()) |
| 7261 | if (auto ToDOrErr = import(D)) |
| 7262 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7263 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7264 | return ToDOrErr.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7265 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7266 | if (E->hasExplicitTemplateArgs() && E->getTemplateKeywordLoc().isValid()) { |
| 7267 | TemplateArgumentListInfo ToTAInfo; |
| 7268 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7269 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7270 | ToTAInfo)) |
| 7271 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7272 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7273 | ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc()); |
| 7274 | if (!ToTemplateKeywordLocOrErr) |
| 7275 | return ToTemplateKeywordLocOrErr.takeError(); |
| 7276 | |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7277 | return UnresolvedLookupExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7278 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7279 | *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo, |
| 7280 | ToDecls.begin(), ToDecls.end()); |
| 7281 | } |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7282 | |
| 7283 | return UnresolvedLookupExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7284 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7285 | ToNameInfo, E->requiresADL(), E->isOverloaded(), ToDecls.begin(), |
| 7286 | ToDecls.end()); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7287 | } |
| 7288 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7289 | ExpectedStmt |
| 7290 | ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { |
| 7291 | auto Imp1 = importSeq( |
| 7292 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7293 | E->getTemplateKeywordLoc()); |
| 7294 | if (!Imp1) |
| 7295 | return Imp1.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7296 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7297 | QualType ToType; |
| 7298 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7299 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7300 | std::tie(ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc) = *Imp1; |
| 7301 | |
| 7302 | auto Imp2 = importSeq(E->getName(), E->getNameLoc()); |
| 7303 | if (!Imp2) |
| 7304 | return Imp2.takeError(); |
| 7305 | DeclarationNameInfo ToNameInfo(std::get<0>(*Imp2), std::get<1>(*Imp2)); |
| 7306 | // Import additional name location/type info. |
| 7307 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7308 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7309 | |
| 7310 | UnresolvedSet<8> ToDecls; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7311 | for (Decl *D : E->decls()) |
| 7312 | if (auto ToDOrErr = import(D)) |
| 7313 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7314 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7315 | return ToDOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7316 | |
| 7317 | TemplateArgumentListInfo ToTAInfo; |
| 7318 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7319 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7320 | if (Error Err = |
| 7321 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 7322 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7323 | ResInfo = &ToTAInfo; |
| 7324 | } |
| 7325 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7326 | Expr *ToBase = nullptr; |
| 7327 | if (!E->isImplicitAccess()) { |
| 7328 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7329 | ToBase = *ToBaseOrErr; |
| 7330 | else |
| 7331 | return ToBaseOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7332 | } |
| 7333 | |
| 7334 | return UnresolvedMemberExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7335 | Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType, |
| 7336 | E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7337 | ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end()); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7338 | } |
| 7339 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7340 | ExpectedStmt ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| 7341 | auto Imp = importSeq(E->getCallee(), E->getType(), E->getRParenLoc()); |
| 7342 | if (!Imp) |
| 7343 | return Imp.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7344 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7345 | Expr *ToCallee; |
| 7346 | QualType ToType; |
| 7347 | SourceLocation ToRParenLoc; |
| 7348 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7349 | |
| 7350 | unsigned NumArgs = E->getNumArgs(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7351 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); |
| 7352 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7353 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7354 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7355 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { |
| 7356 | return new (Importer.getToContext()) CXXOperatorCallExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7357 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType, |
| 7358 | OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures()); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7359 | } |
| 7360 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7361 | return new (Importer.getToContext()) CallExpr( |
| 7362 | Importer.getToContext(), ToCallee, ToArgs, ToType, E->getValueKind(), |
| 7363 | ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7364 | } |
| 7365 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7366 | ExpectedStmt ASTNodeImporter::VisitLambdaExpr(LambdaExpr *E) { |
| 7367 | CXXRecordDecl *FromClass = E->getLambdaClass(); |
| 7368 | auto ToClassOrErr = import(FromClass); |
| 7369 | if (!ToClassOrErr) |
| 7370 | return ToClassOrErr.takeError(); |
| 7371 | CXXRecordDecl *ToClass = *ToClassOrErr; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7372 | |
| 7373 | // NOTE: lambda classes are created with BeingDefined flag set up. |
| 7374 | // It means that ImportDefinition doesn't work for them and we should fill it |
| 7375 | // manually. |
| 7376 | if (ToClass->isBeingDefined()) { |
| 7377 | for (auto FromField : FromClass->fields()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7378 | auto ToFieldOrErr = import(FromField); |
| 7379 | if (!ToFieldOrErr) |
| 7380 | return ToFieldOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7381 | } |
| 7382 | } |
| 7383 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7384 | auto ToCallOpOrErr = import(E->getCallOperator()); |
| 7385 | if (!ToCallOpOrErr) |
| 7386 | return ToCallOpOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7387 | |
| 7388 | ToClass->completeDefinition(); |
| 7389 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7390 | SmallVector<LambdaCapture, 8> ToCaptures; |
| 7391 | ToCaptures.reserve(E->capture_size()); |
| 7392 | for (const auto &FromCapture : E->captures()) { |
| 7393 | if (auto ToCaptureOrErr = import(FromCapture)) |
| 7394 | ToCaptures.push_back(*ToCaptureOrErr); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7395 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7396 | return ToCaptureOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7397 | } |
| 7398 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7399 | SmallVector<Expr *, 8> ToCaptureInits(E->capture_size()); |
| 7400 | if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits)) |
| 7401 | return std::move(Err); |
| 7402 | |
| 7403 | auto Imp = importSeq( |
| 7404 | E->getIntroducerRange(), E->getCaptureDefaultLoc(), E->getEndLoc()); |
| 7405 | if (!Imp) |
| 7406 | return Imp.takeError(); |
| 7407 | |
| 7408 | SourceRange ToIntroducerRange; |
| 7409 | SourceLocation ToCaptureDefaultLoc, ToEndLoc; |
| 7410 | std::tie(ToIntroducerRange, ToCaptureDefaultLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7411 | |
Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 7412 | return LambdaExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7413 | Importer.getToContext(), ToClass, ToIntroducerRange, |
| 7414 | E->getCaptureDefault(), ToCaptureDefaultLoc, ToCaptures, |
| 7415 | E->hasExplicitParameters(), E->hasExplicitResultType(), ToCaptureInits, |
| 7416 | ToEndLoc, E->containsUnexpandedParameterPack()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7417 | } |
| 7418 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7419 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7420 | ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) { |
| 7421 | auto Imp = importSeq(E->getLBraceLoc(), E->getRBraceLoc(), E->getType()); |
| 7422 | if (!Imp) |
| 7423 | return Imp.takeError(); |
| 7424 | |
| 7425 | SourceLocation ToLBraceLoc, ToRBraceLoc; |
| 7426 | QualType ToType; |
| 7427 | std::tie(ToLBraceLoc, ToRBraceLoc, ToType) = *Imp; |
| 7428 | |
| 7429 | SmallVector<Expr *, 4> ToExprs(E->getNumInits()); |
| 7430 | if (Error Err = ImportContainerChecked(E->inits(), ToExprs)) |
| 7431 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7432 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7433 | ASTContext &ToCtx = Importer.getToContext(); |
| 7434 | InitListExpr *To = new (ToCtx) InitListExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7435 | ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc); |
| 7436 | To->setType(ToType); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7437 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7438 | if (E->hasArrayFiller()) { |
| 7439 | if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller())) |
| 7440 | To->setArrayFiller(*ToFillerOrErr); |
| 7441 | else |
| 7442 | return ToFillerOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7443 | } |
| 7444 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7445 | if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) { |
| 7446 | if (auto ToFDOrErr = import(FromFD)) |
| 7447 | To->setInitializedFieldInUnion(*ToFDOrErr); |
| 7448 | else |
| 7449 | return ToFDOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7450 | } |
| 7451 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7452 | if (InitListExpr *SyntForm = E->getSyntacticForm()) { |
| 7453 | if (auto ToSyntFormOrErr = import(SyntForm)) |
| 7454 | To->setSyntacticForm(*ToSyntFormOrErr); |
| 7455 | else |
| 7456 | return ToSyntFormOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7457 | } |
| 7458 | |
Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7459 | // Copy InitListExprBitfields, which are not handled in the ctor of |
| 7460 | // InitListExpr. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7461 | To->sawArrayRangeDesignator(E->hadArrayRangeDesignator()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7462 | |
| 7463 | return To; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7464 | } |
| 7465 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7466 | ExpectedStmt ASTNodeImporter::VisitCXXStdInitializerListExpr( |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7467 | CXXStdInitializerListExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7468 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7469 | if (!ToTypeOrErr) |
| 7470 | return ToTypeOrErr.takeError(); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7471 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7472 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7473 | if (!ToSubExprOrErr) |
| 7474 | return ToSubExprOrErr.takeError(); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7475 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7476 | return new (Importer.getToContext()) CXXStdInitializerListExpr( |
| 7477 | *ToTypeOrErr, *ToSubExprOrErr); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7478 | } |
| 7479 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7480 | ExpectedStmt ASTNodeImporter::VisitCXXInheritedCtorInitExpr( |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7481 | CXXInheritedCtorInitExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7482 | auto Imp = importSeq(E->getLocation(), E->getType(), E->getConstructor()); |
| 7483 | if (!Imp) |
| 7484 | return Imp.takeError(); |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7485 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7486 | SourceLocation ToLocation; |
| 7487 | QualType ToType; |
| 7488 | CXXConstructorDecl *ToConstructor; |
| 7489 | std::tie(ToLocation, ToType, ToConstructor) = *Imp; |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7490 | |
| 7491 | return new (Importer.getToContext()) CXXInheritedCtorInitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7492 | ToLocation, ToType, ToConstructor, E->constructsVBase(), |
| 7493 | E->inheritedFromVBase()); |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7494 | } |
| 7495 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7496 | ExpectedStmt ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 7497 | auto Imp = importSeq(E->getType(), E->getCommonExpr(), E->getSubExpr()); |
| 7498 | if (!Imp) |
| 7499 | return Imp.takeError(); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7500 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7501 | QualType ToType; |
| 7502 | Expr *ToCommonExpr, *ToSubExpr; |
| 7503 | std::tie(ToType, ToCommonExpr, ToSubExpr) = *Imp; |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7504 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7505 | return new (Importer.getToContext()) ArrayInitLoopExpr( |
| 7506 | ToType, ToCommonExpr, ToSubExpr); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7507 | } |
| 7508 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7509 | ExpectedStmt ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 7510 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7511 | if (!ToTypeOrErr) |
| 7512 | return ToTypeOrErr.takeError(); |
| 7513 | return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7514 | } |
| 7515 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7516 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 7517 | ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc()); |
| 7518 | if (!ToBeginLocOrErr) |
| 7519 | return ToBeginLocOrErr.takeError(); |
| 7520 | |
| 7521 | auto ToFieldOrErr = import(E->getField()); |
| 7522 | if (!ToFieldOrErr) |
| 7523 | return ToFieldOrErr.takeError(); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7524 | |
| 7525 | return CXXDefaultInitExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7526 | Importer.getToContext(), *ToBeginLocOrErr, *ToFieldOrErr); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7527 | } |
| 7528 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7529 | ExpectedStmt ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 7530 | auto Imp = importSeq( |
| 7531 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten(), |
| 7532 | E->getOperatorLoc(), E->getRParenLoc(), E->getAngleBrackets()); |
| 7533 | if (!Imp) |
| 7534 | return Imp.takeError(); |
| 7535 | |
| 7536 | QualType ToType; |
| 7537 | Expr *ToSubExpr; |
| 7538 | TypeSourceInfo *ToTypeInfoAsWritten; |
| 7539 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 7540 | SourceRange ToAngleBrackets; |
| 7541 | std::tie( |
| 7542 | ToType, ToSubExpr, ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, |
| 7543 | ToAngleBrackets) = *Imp; |
| 7544 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7545 | ExprValueKind VK = E->getValueKind(); |
| 7546 | CastKind CK = E->getCastKind(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7547 | auto ToBasePathOrErr = ImportCastPath(E); |
| 7548 | if (!ToBasePathOrErr) |
| 7549 | return ToBasePathOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7550 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7551 | if (isa<CXXStaticCastExpr>(E)) { |
| 7552 | return CXXStaticCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7553 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7554 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7555 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 7556 | return CXXDynamicCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7557 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7558 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7559 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 7560 | return CXXReinterpretCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7561 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7562 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Raphael Isemann | c705bb8 | 2018-08-20 16:20:01 +0000 | [diff] [blame] | 7563 | } else if (isa<CXXConstCastExpr>(E)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7564 | return CXXConstCastExpr::Create( |
| 7565 | Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten, |
| 7566 | ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7567 | } else { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7568 | llvm_unreachable("Unknown cast type"); |
| 7569 | return make_error<ImportError>(); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7570 | } |
| 7571 | } |
| 7572 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7573 | ExpectedStmt ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7574 | SubstNonTypeTemplateParmExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7575 | auto Imp = importSeq( |
| 7576 | E->getType(), E->getExprLoc(), E->getParameter(), E->getReplacement()); |
| 7577 | if (!Imp) |
| 7578 | return Imp.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7579 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7580 | QualType ToType; |
| 7581 | SourceLocation ToExprLoc; |
| 7582 | NonTypeTemplateParmDecl *ToParameter; |
| 7583 | Expr *ToReplacement; |
| 7584 | std::tie(ToType, ToExprLoc, ToParameter, ToReplacement) = *Imp; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7585 | |
| 7586 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7587 | ToType, E->getValueKind(), ToExprLoc, ToParameter, ToReplacement); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7588 | } |
| 7589 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7590 | ExpectedStmt ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { |
| 7591 | auto Imp = importSeq( |
| 7592 | E->getType(), E->getBeginLoc(), E->getEndLoc()); |
| 7593 | if (!Imp) |
| 7594 | return Imp.takeError(); |
| 7595 | |
| 7596 | QualType ToType; |
| 7597 | SourceLocation ToBeginLoc, ToEndLoc; |
| 7598 | std::tie(ToType, ToBeginLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7599 | |
| 7600 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7601 | if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs)) |
| 7602 | return std::move(Err); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7603 | |
| 7604 | // According to Sema::BuildTypeTrait(), if E is value-dependent, |
| 7605 | // Value is always false. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7606 | bool ToValue = (E->isValueDependent() ? false : E->getValue()); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7607 | |
| 7608 | return TypeTraitExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7609 | Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs, |
| 7610 | ToEndLoc, ToValue); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7611 | } |
| 7612 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7613 | ExpectedStmt ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { |
| 7614 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7615 | if (!ToTypeOrErr) |
| 7616 | return ToTypeOrErr.takeError(); |
| 7617 | |
| 7618 | auto ToSourceRangeOrErr = import(E->getSourceRange()); |
| 7619 | if (!ToSourceRangeOrErr) |
| 7620 | return ToSourceRangeOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7621 | |
| 7622 | if (E->isTypeOperand()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7623 | if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo())) |
| 7624 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7625 | *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr); |
| 7626 | else |
| 7627 | return ToTSIOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7628 | } |
| 7629 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7630 | ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand()); |
| 7631 | if (!ToExprOperandOrErr) |
| 7632 | return ToExprOperandOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7633 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7634 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7635 | *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7636 | } |
| 7637 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7638 | void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod, |
| 7639 | CXXMethodDecl *FromMethod) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7640 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) { |
| 7641 | if (auto ImportedOrErr = import(FromOverriddenMethod)) |
| 7642 | ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>( |
| 7643 | (*ImportedOrErr)->getCanonicalDecl())); |
| 7644 | else |
| 7645 | consumeError(ImportedOrErr.takeError()); |
| 7646 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7647 | } |
| 7648 | |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7649 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7650 | ASTContext &FromContext, FileManager &FromFileManager, |
| 7651 | bool MinimalImport) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7652 | : ToContext(ToContext), FromContext(FromContext), |
| 7653 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
| 7654 | Minimal(MinimalImport) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7655 | ImportedDecls[FromContext.getTranslationUnitDecl()] |
| 7656 | = ToContext.getTranslationUnitDecl(); |
| 7657 | } |
| 7658 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7659 | ASTImporter::~ASTImporter() = default; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7660 | |
| 7661 | QualType ASTImporter::Import(QualType FromT) { |
| 7662 | if (FromT.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7663 | return {}; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7664 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7665 | const Type *FromTy = FromT.getTypePtr(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7666 | |
| 7667 | // Check whether we've already imported this type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7668 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7669 | = ImportedTypes.find(FromTy); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7670 | if (Pos != ImportedTypes.end()) |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7671 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7672 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7673 | // Import the type |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7674 | ASTNodeImporter Importer(*this); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7675 | ExpectedType ToTOrErr = Importer.Visit(FromTy); |
| 7676 | if (!ToTOrErr) { |
| 7677 | llvm::consumeError(ToTOrErr.takeError()); |
| 7678 | return {}; |
| 7679 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7680 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7681 | // Record the imported type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7682 | ImportedTypes[FromTy] = (*ToTOrErr).getTypePtr(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7683 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7684 | return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7685 | } |
| 7686 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7687 | TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) { |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7688 | if (!FromTSI) |
| 7689 | return FromTSI; |
| 7690 | |
| 7691 | // FIXME: For now we just create a "trivial" type source info based |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 7692 | // on the type and a single location. Implement a real version of this. |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7693 | QualType T = Import(FromTSI->getType()); |
| 7694 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7695 | return nullptr; |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7696 | |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7697 | return ToContext.getTrivialTypeSourceInfo( |
| 7698 | T, Import(FromTSI->getTypeLoc().getBeginLoc())); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7699 | } |
| 7700 | |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 7701 | Attr *ASTImporter::Import(const Attr *FromAttr) { |
| 7702 | Attr *ToAttr = FromAttr->clone(ToContext); |
| 7703 | ToAttr->setRange(Import(FromAttr->getRange())); |
| 7704 | return ToAttr; |
| 7705 | } |
| 7706 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7707 | Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) { |
| 7708 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD); |
| 7709 | if (Pos != ImportedDecls.end()) { |
| 7710 | Decl *ToD = Pos->second; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7711 | // FIXME: move this call to ImportDeclParts(). |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7712 | if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(FromD, ToD)) |
| 7713 | llvm::consumeError(std::move(Err)); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7714 | return ToD; |
| 7715 | } else { |
| 7716 | return nullptr; |
| 7717 | } |
| 7718 | } |
| 7719 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7720 | Decl *ASTImporter::Import(Decl *FromD) { |
| 7721 | if (!FromD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7722 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7723 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7724 | ASTNodeImporter Importer(*this); |
| 7725 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7726 | // Check whether we've already imported this declaration. |
| 7727 | Decl *ToD = GetAlreadyImportedOrNull(FromD); |
| 7728 | if (ToD) { |
| 7729 | // If FromD has some updated flags after last import, apply it |
| 7730 | updateFlags(FromD, ToD); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7731 | return ToD; |
| 7732 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7733 | |
| 7734 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7735 | ExpectedDecl ToDOrErr = Importer.Visit(FromD); |
| 7736 | if (!ToDOrErr) { |
| 7737 | llvm::consumeError(ToDOrErr.takeError()); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7738 | return nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7739 | } |
| 7740 | ToD = *ToDOrErr; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7741 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7742 | // Notify subclasses. |
| 7743 | Imported(FromD, ToD); |
| 7744 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 7745 | updateFlags(FromD, ToD); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7746 | return ToD; |
| 7747 | } |
| 7748 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7749 | Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7750 | if (!FromDC) |
| 7751 | return FromDC; |
| 7752 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7753 | auto *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC))); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7754 | if (!ToDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7755 | return nullptr; |
| 7756 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7757 | // 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] | 7758 | // need it to have a definition. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7759 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
| 7760 | auto *FromRecord = cast<RecordDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7761 | if (ToRecord->isCompleteDefinition()) { |
| 7762 | // Do nothing. |
| 7763 | } else if (FromRecord->isCompleteDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7764 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7765 | FromRecord, ToRecord, ASTNodeImporter::IDK_Basic)) |
| 7766 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7767 | } else { |
| 7768 | CompleteDecl(ToRecord); |
| 7769 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7770 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 7771 | auto *FromEnum = cast<EnumDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7772 | if (ToEnum->isCompleteDefinition()) { |
| 7773 | // Do nothing. |
| 7774 | } else if (FromEnum->isCompleteDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7775 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7776 | FromEnum, ToEnum, ASTNodeImporter::IDK_Basic)) |
| 7777 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7778 | } else { |
| 7779 | CompleteDecl(ToEnum); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7780 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7781 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 7782 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7783 | if (ToClass->getDefinition()) { |
| 7784 | // Do nothing. |
| 7785 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7786 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7787 | FromDef, ToClass, ASTNodeImporter::IDK_Basic)) |
| 7788 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7789 | } else { |
| 7790 | CompleteDecl(ToClass); |
| 7791 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7792 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 7793 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7794 | if (ToProto->getDefinition()) { |
| 7795 | // Do nothing. |
| 7796 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7797 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7798 | FromDef, ToProto, ASTNodeImporter::IDK_Basic)) |
| 7799 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7800 | } else { |
| 7801 | CompleteDecl(ToProto); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7802 | } |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7803 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7804 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7805 | return ToDC; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7806 | } |
| 7807 | |
| 7808 | Expr *ASTImporter::Import(Expr *FromE) { |
| 7809 | if (!FromE) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7810 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7811 | |
| 7812 | return cast_or_null<Expr>(Import(cast<Stmt>(FromE))); |
| 7813 | } |
| 7814 | |
| 7815 | Stmt *ASTImporter::Import(Stmt *FromS) { |
| 7816 | if (!FromS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7817 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7818 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7819 | // Check whether we've already imported this declaration. |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7820 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 7821 | if (Pos != ImportedStmts.end()) |
| 7822 | return Pos->second; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7823 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7824 | // Import the statement. |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7825 | ASTNodeImporter Importer(*this); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7826 | ExpectedStmt ToSOrErr = Importer.Visit(FromS); |
| 7827 | if (!ToSOrErr) { |
| 7828 | llvm::consumeError(ToSOrErr.takeError()); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7829 | return nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7830 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7831 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7832 | if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) { |
Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7833 | auto *FromE = cast<Expr>(FromS); |
| 7834 | // Copy ExprBitfields, which may not be handled in Expr subclasses |
| 7835 | // constructors. |
| 7836 | ToE->setValueKind(FromE->getValueKind()); |
| 7837 | ToE->setObjectKind(FromE->getObjectKind()); |
| 7838 | ToE->setTypeDependent(FromE->isTypeDependent()); |
| 7839 | ToE->setValueDependent(FromE->isValueDependent()); |
| 7840 | ToE->setInstantiationDependent(FromE->isInstantiationDependent()); |
| 7841 | ToE->setContainsUnexpandedParameterPack( |
| 7842 | FromE->containsUnexpandedParameterPack()); |
| 7843 | } |
| 7844 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7845 | // Record the imported declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7846 | ImportedStmts[FromS] = *ToSOrErr; |
| 7847 | return *ToSOrErr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7848 | } |
| 7849 | |
| 7850 | NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) { |
| 7851 | if (!FromNNS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7852 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7853 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7854 | NestedNameSpecifier *prefix = Import(FromNNS->getPrefix()); |
| 7855 | |
| 7856 | switch (FromNNS->getKind()) { |
| 7857 | case NestedNameSpecifier::Identifier: |
| 7858 | if (IdentifierInfo *II = Import(FromNNS->getAsIdentifier())) { |
| 7859 | return NestedNameSpecifier::Create(ToContext, prefix, II); |
| 7860 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7861 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7862 | |
| 7863 | case NestedNameSpecifier::Namespace: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7864 | if (auto *NS = |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7865 | cast_or_null<NamespaceDecl>(Import(FromNNS->getAsNamespace()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7866 | return NestedNameSpecifier::Create(ToContext, prefix, NS); |
| 7867 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7868 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7869 | |
| 7870 | case NestedNameSpecifier::NamespaceAlias: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7871 | if (auto *NSAD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7872 | cast_or_null<NamespaceAliasDecl>(Import(FromNNS->getAsNamespaceAlias()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7873 | return NestedNameSpecifier::Create(ToContext, prefix, NSAD); |
| 7874 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7875 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7876 | |
| 7877 | case NestedNameSpecifier::Global: |
| 7878 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 7879 | |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7880 | case NestedNameSpecifier::Super: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7881 | if (auto *RD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7882 | cast_or_null<CXXRecordDecl>(Import(FromNNS->getAsRecordDecl()))) { |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7883 | return NestedNameSpecifier::SuperSpecifier(ToContext, RD); |
| 7884 | } |
| 7885 | return nullptr; |
| 7886 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7887 | case NestedNameSpecifier::TypeSpec: |
| 7888 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 7889 | QualType T = Import(QualType(FromNNS->getAsType(), 0u)); |
| 7890 | if (!T.isNull()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7891 | bool bTemplate = FromNNS->getKind() == |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7892 | NestedNameSpecifier::TypeSpecWithTemplate; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7893 | return NestedNameSpecifier::Create(ToContext, prefix, |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7894 | bTemplate, T.getTypePtr()); |
| 7895 | } |
| 7896 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7897 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7898 | } |
| 7899 | |
| 7900 | llvm_unreachable("Invalid nested name specifier kind"); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7901 | } |
| 7902 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 7903 | NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7904 | // Copied from NestedNameSpecifier mostly. |
| 7905 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 7906 | NestedNameSpecifierLoc NNS = FromNNS; |
| 7907 | |
| 7908 | // Push each of the nested-name-specifiers's onto a stack for |
| 7909 | // serialization in reverse order. |
| 7910 | while (NNS) { |
| 7911 | NestedNames.push_back(NNS); |
| 7912 | NNS = NNS.getPrefix(); |
| 7913 | } |
| 7914 | |
| 7915 | NestedNameSpecifierLocBuilder Builder; |
| 7916 | |
| 7917 | while (!NestedNames.empty()) { |
| 7918 | NNS = NestedNames.pop_back_val(); |
| 7919 | NestedNameSpecifier *Spec = Import(NNS.getNestedNameSpecifier()); |
| 7920 | if (!Spec) |
| 7921 | return NestedNameSpecifierLoc(); |
| 7922 | |
| 7923 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
| 7924 | switch (Kind) { |
| 7925 | case NestedNameSpecifier::Identifier: |
| 7926 | Builder.Extend(getToContext(), |
| 7927 | Spec->getAsIdentifier(), |
| 7928 | Import(NNS.getLocalBeginLoc()), |
| 7929 | Import(NNS.getLocalEndLoc())); |
| 7930 | break; |
| 7931 | |
| 7932 | case NestedNameSpecifier::Namespace: |
| 7933 | Builder.Extend(getToContext(), |
| 7934 | Spec->getAsNamespace(), |
| 7935 | Import(NNS.getLocalBeginLoc()), |
| 7936 | Import(NNS.getLocalEndLoc())); |
| 7937 | break; |
| 7938 | |
| 7939 | case NestedNameSpecifier::NamespaceAlias: |
| 7940 | Builder.Extend(getToContext(), |
| 7941 | Spec->getAsNamespaceAlias(), |
| 7942 | Import(NNS.getLocalBeginLoc()), |
| 7943 | Import(NNS.getLocalEndLoc())); |
| 7944 | break; |
| 7945 | |
| 7946 | case NestedNameSpecifier::TypeSpec: |
| 7947 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 7948 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
| 7949 | QualType(Spec->getAsType(), 0)); |
| 7950 | Builder.Extend(getToContext(), |
| 7951 | Import(NNS.getLocalBeginLoc()), |
| 7952 | TSI->getTypeLoc(), |
| 7953 | Import(NNS.getLocalEndLoc())); |
| 7954 | break; |
| 7955 | } |
| 7956 | |
| 7957 | case NestedNameSpecifier::Global: |
| 7958 | Builder.MakeGlobal(getToContext(), Import(NNS.getLocalBeginLoc())); |
| 7959 | break; |
| 7960 | |
| 7961 | case NestedNameSpecifier::Super: { |
| 7962 | SourceRange ToRange = Import(NNS.getSourceRange()); |
| 7963 | Builder.MakeSuper(getToContext(), |
| 7964 | Spec->getAsRecordDecl(), |
| 7965 | ToRange.getBegin(), |
| 7966 | ToRange.getEnd()); |
| 7967 | } |
| 7968 | } |
| 7969 | } |
| 7970 | |
| 7971 | return Builder.getWithLocInContext(getToContext()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 7972 | } |
| 7973 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7974 | TemplateName ASTImporter::Import(TemplateName From) { |
| 7975 | switch (From.getKind()) { |
| 7976 | case TemplateName::Template: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7977 | if (auto *ToTemplate = |
| 7978 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7979 | return TemplateName(ToTemplate); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7980 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7981 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7982 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7983 | case TemplateName::OverloadedTemplate: { |
| 7984 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 7985 | UnresolvedSet<2> ToTemplates; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7986 | for (auto *I : *FromStorage) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7987 | if (auto *To = cast_or_null<NamedDecl>(Import(I))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7988 | ToTemplates.addDecl(To); |
| 7989 | else |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7990 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7991 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7992 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7993 | ToTemplates.end()); |
| 7994 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7995 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7996 | case TemplateName::QualifiedTemplate: { |
| 7997 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
| 7998 | NestedNameSpecifier *Qualifier = Import(QTN->getQualifier()); |
| 7999 | if (!Qualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8000 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8001 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8002 | if (auto *ToTemplate = |
| 8003 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8004 | return ToContext.getQualifiedTemplateName(Qualifier, |
| 8005 | QTN->hasTemplateKeyword(), |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8006 | ToTemplate); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8007 | |
| 8008 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8009 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8010 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8011 | case TemplateName::DependentTemplate: { |
| 8012 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
| 8013 | NestedNameSpecifier *Qualifier = Import(DTN->getQualifier()); |
| 8014 | if (!Qualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8015 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8016 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8017 | if (DTN->isIdentifier()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8018 | return ToContext.getDependentTemplateName(Qualifier, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8019 | Import(DTN->getIdentifier())); |
| 8020 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8021 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8022 | return ToContext.getDependentTemplateName(Qualifier, DTN->getOperator()); |
| 8023 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8024 | |
| 8025 | case TemplateName::SubstTemplateTemplateParm: { |
| 8026 | SubstTemplateTemplateParmStorage *subst |
| 8027 | = From.getAsSubstTemplateTemplateParm(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8028 | auto *param = |
| 8029 | cast_or_null<TemplateTemplateParmDecl>(Import(subst->getParameter())); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8030 | if (!param) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8031 | return {}; |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8032 | |
| 8033 | TemplateName replacement = Import(subst->getReplacement()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8034 | if (replacement.isNull()) |
| 8035 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8036 | |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8037 | return ToContext.getSubstTemplateTemplateParm(param, replacement); |
| 8038 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8039 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8040 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 8041 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 8042 | = From.getAsSubstTemplateTemplateParmPack(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8043 | auto *Param = |
| 8044 | cast_or_null<TemplateTemplateParmDecl>( |
| 8045 | Import(SubstPack->getParameterPack())); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8046 | if (!Param) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8047 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8048 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8049 | ASTNodeImporter Importer(*this); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8050 | Expected<TemplateArgument> ArgPack |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8051 | = Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8052 | if (!ArgPack) { |
| 8053 | llvm::consumeError(ArgPack.takeError()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8054 | return {}; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8055 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8056 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8057 | return ToContext.getSubstTemplateTemplateParmPack(Param, *ArgPack); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8058 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8059 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8060 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8061 | llvm_unreachable("Invalid template name kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8062 | } |
| 8063 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8064 | SourceLocation ASTImporter::Import(SourceLocation FromLoc) { |
| 8065 | if (FromLoc.isInvalid()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8066 | return {}; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8067 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8068 | SourceManager &FromSM = FromContext.getSourceManager(); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8069 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8070 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
Sean Callanan | 238d897 | 2014-12-10 01:26:39 +0000 | [diff] [blame] | 8071 | FileID ToFileID = Import(Decomposed.first); |
| 8072 | if (ToFileID.isInvalid()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8073 | return {}; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8074 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 8075 | return ToSM.getComposedLoc(ToFileID, Decomposed.second); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8076 | } |
| 8077 | |
| 8078 | SourceRange ASTImporter::Import(SourceRange FromRange) { |
| 8079 | return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd())); |
| 8080 | } |
| 8081 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8082 | FileID ASTImporter::Import(FileID FromID) { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8083 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8084 | if (Pos != ImportedFileIDs.end()) |
| 8085 | return Pos->second; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8086 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8087 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 8088 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 8089 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8090 | |
| 8091 | // Map the FromID to the "to" source manager. |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8092 | FileID ToID; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8093 | if (FromSLoc.isExpansion()) { |
| 8094 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); |
| 8095 | SourceLocation ToSpLoc = Import(FromEx.getSpellingLoc()); |
| 8096 | SourceLocation ToExLocS = Import(FromEx.getExpansionLocStart()); |
| 8097 | unsigned TokenLen = FromSM.getFileIDSize(FromID); |
| 8098 | SourceLocation MLoc; |
| 8099 | if (FromEx.isMacroArgExpansion()) { |
| 8100 | MLoc = ToSM.createMacroArgExpansionLoc(ToSpLoc, ToExLocS, TokenLen); |
| 8101 | } else { |
| 8102 | SourceLocation ToExLocE = Import(FromEx.getExpansionLocEnd()); |
| 8103 | MLoc = ToSM.createExpansionLoc(ToSpLoc, ToExLocS, ToExLocE, TokenLen, |
| 8104 | FromEx.isExpansionTokenRange()); |
| 8105 | } |
| 8106 | ToID = ToSM.getFileID(MLoc); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8107 | } else { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8108 | // Include location of this file. |
| 8109 | SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); |
| 8110 | |
| 8111 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
| 8112 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
| 8113 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 8114 | // disk again |
| 8115 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 8116 | // than mmap the files several times. |
| 8117 | const FileEntry *Entry = |
| 8118 | ToFileManager.getFile(Cache->OrigEntry->getName()); |
| 8119 | if (!Entry) |
| 8120 | return {}; |
| 8121 | ToID = ToSM.createFileID(Entry, ToIncludeLoc, |
| 8122 | FromSLoc.getFile().getFileCharacteristic()); |
| 8123 | } else { |
| 8124 | // FIXME: We want to re-use the existing MemoryBuffer! |
| 8125 | const llvm::MemoryBuffer *FromBuf = |
| 8126 | Cache->getBuffer(FromContext.getDiagnostics(), FromSM); |
| 8127 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = |
| 8128 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
| 8129 | FromBuf->getBufferIdentifier()); |
| 8130 | ToID = ToSM.createFileID(std::move(ToBuf), |
| 8131 | FromSLoc.getFile().getFileCharacteristic()); |
| 8132 | } |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8133 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8134 | |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 8135 | ImportedFileIDs[FromID] = ToID; |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8136 | return ToID; |
| 8137 | } |
| 8138 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8139 | CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) { |
| 8140 | Expr *ToExpr = Import(From->getInit()); |
| 8141 | if (!ToExpr && From->getInit()) |
| 8142 | return nullptr; |
| 8143 | |
| 8144 | if (From->isBaseInitializer()) { |
| 8145 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 8146 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 8147 | return nullptr; |
| 8148 | |
| 8149 | return new (ToContext) CXXCtorInitializer( |
| 8150 | ToContext, ToTInfo, From->isBaseVirtual(), Import(From->getLParenLoc()), |
| 8151 | ToExpr, Import(From->getRParenLoc()), |
| 8152 | From->isPackExpansion() ? Import(From->getEllipsisLoc()) |
| 8153 | : SourceLocation()); |
| 8154 | } else if (From->isMemberInitializer()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8155 | auto *ToField = cast_or_null<FieldDecl>(Import(From->getMember())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8156 | if (!ToField && From->getMember()) |
| 8157 | return nullptr; |
| 8158 | |
| 8159 | return new (ToContext) CXXCtorInitializer( |
| 8160 | ToContext, ToField, Import(From->getMemberLocation()), |
| 8161 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 8162 | } else if (From->isIndirectMemberInitializer()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8163 | auto *ToIField = cast_or_null<IndirectFieldDecl>( |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8164 | Import(From->getIndirectMember())); |
| 8165 | if (!ToIField && From->getIndirectMember()) |
| 8166 | return nullptr; |
| 8167 | |
| 8168 | return new (ToContext) CXXCtorInitializer( |
| 8169 | ToContext, ToIField, Import(From->getMemberLocation()), |
| 8170 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 8171 | } else if (From->isDelegatingInitializer()) { |
| 8172 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 8173 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 8174 | return nullptr; |
| 8175 | |
| 8176 | return new (ToContext) |
| 8177 | CXXCtorInitializer(ToContext, ToTInfo, Import(From->getLParenLoc()), |
| 8178 | ToExpr, Import(From->getRParenLoc())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8179 | } else { |
| 8180 | return nullptr; |
| 8181 | } |
| 8182 | } |
| 8183 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8184 | CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { |
| 8185 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 8186 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 8187 | return Pos->second; |
| 8188 | |
| 8189 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
| 8190 | Import(BaseSpec->getSourceRange()), |
| 8191 | BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 8192 | BaseSpec->getAccessSpecifierAsWritten(), |
| 8193 | Import(BaseSpec->getTypeSourceInfo()), |
| 8194 | Import(BaseSpec->getEllipsisLoc())); |
| 8195 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 8196 | return Imported; |
| 8197 | } |
| 8198 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8199 | Error ASTImporter::ImportDefinition_New(Decl *From) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8200 | Decl *To = Import(From); |
| 8201 | if (!To) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8202 | return llvm::make_error<ImportError>(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8203 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8204 | if (auto *FromDC = cast<DeclContext>(From)) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8205 | ASTNodeImporter Importer(*this); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8206 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8207 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 8208 | if (!ToRecord->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8209 | return Importer.ImportDefinition( |
| 8210 | cast<RecordDecl>(FromDC), ToRecord, |
| 8211 | ASTNodeImporter::IDK_Everything); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8212 | } |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 8213 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8214 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8215 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8216 | if (!ToEnum->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8217 | return Importer.ImportDefinition( |
| 8218 | cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8219 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8220 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8221 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8222 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 8223 | if (!ToIFace->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8224 | return Importer.ImportDefinition( |
| 8225 | cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
| 8226 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 8227 | } |
| 8228 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8229 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8230 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 8231 | if (!ToProto->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8232 | return Importer.ImportDefinition( |
| 8233 | cast<ObjCProtocolDecl>(FromDC), ToProto, |
| 8234 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 8235 | } |
| 8236 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8237 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8238 | return Importer.ImportDeclContext(FromDC, true); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8239 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8240 | |
| 8241 | return Error::success(); |
| 8242 | } |
| 8243 | |
| 8244 | void ASTImporter::ImportDefinition(Decl *From) { |
| 8245 | Error Err = ImportDefinition_New(From); |
| 8246 | llvm::consumeError(std::move(Err)); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8247 | } |
| 8248 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8249 | DeclarationName ASTImporter::Import(DeclarationName FromName) { |
| 8250 | if (!FromName) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8251 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8252 | |
| 8253 | switch (FromName.getNameKind()) { |
| 8254 | case DeclarationName::Identifier: |
| 8255 | return Import(FromName.getAsIdentifierInfo()); |
| 8256 | |
| 8257 | case DeclarationName::ObjCZeroArgSelector: |
| 8258 | case DeclarationName::ObjCOneArgSelector: |
| 8259 | case DeclarationName::ObjCMultiArgSelector: |
| 8260 | return Import(FromName.getObjCSelector()); |
| 8261 | |
| 8262 | case DeclarationName::CXXConstructorName: { |
| 8263 | QualType T = Import(FromName.getCXXNameType()); |
| 8264 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8265 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8266 | |
| 8267 | return ToContext.DeclarationNames.getCXXConstructorName( |
| 8268 | ToContext.getCanonicalType(T)); |
| 8269 | } |
| 8270 | |
| 8271 | case DeclarationName::CXXDestructorName: { |
| 8272 | QualType T = Import(FromName.getCXXNameType()); |
| 8273 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8274 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8275 | |
| 8276 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 8277 | ToContext.getCanonicalType(T)); |
| 8278 | } |
| 8279 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8280 | case DeclarationName::CXXDeductionGuideName: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8281 | auto *Template = cast_or_null<TemplateDecl>( |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8282 | Import(FromName.getCXXDeductionGuideTemplate())); |
| 8283 | if (!Template) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8284 | return {}; |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8285 | return ToContext.DeclarationNames.getCXXDeductionGuideName(Template); |
| 8286 | } |
| 8287 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8288 | case DeclarationName::CXXConversionFunctionName: { |
| 8289 | QualType T = Import(FromName.getCXXNameType()); |
| 8290 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8291 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8292 | |
| 8293 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 8294 | ToContext.getCanonicalType(T)); |
| 8295 | } |
| 8296 | |
| 8297 | case DeclarationName::CXXOperatorName: |
| 8298 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 8299 | FromName.getCXXOverloadedOperator()); |
| 8300 | |
| 8301 | case DeclarationName::CXXLiteralOperatorName: |
| 8302 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
| 8303 | Import(FromName.getCXXLiteralIdentifier())); |
| 8304 | |
| 8305 | case DeclarationName::CXXUsingDirective: |
| 8306 | // FIXME: STATICS! |
| 8307 | return DeclarationName::getUsingDirectiveName(); |
| 8308 | } |
| 8309 | |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 8310 | llvm_unreachable("Invalid DeclarationName Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8311 | } |
| 8312 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8313 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8314 | if (!FromId) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8315 | return nullptr; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8316 | |
Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 8317 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 8318 | |
| 8319 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 8320 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 8321 | |
| 8322 | return ToId; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8323 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8324 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8325 | Selector ASTImporter::Import(Selector FromSel) { |
| 8326 | if (FromSel.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8327 | return {}; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8328 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 8329 | SmallVector<IdentifierInfo *, 4> Idents; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8330 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 8331 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 8332 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 8333 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 8334 | } |
| 8335 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8336 | DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, |
| 8337 | DeclContext *DC, |
| 8338 | unsigned IDNS, |
| 8339 | NamedDecl **Decls, |
| 8340 | unsigned NumDecls) { |
| 8341 | return Name; |
| 8342 | } |
| 8343 | |
| 8344 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8345 | if (LastDiagFromFrom) |
| 8346 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8347 | FromContext.getDiagnostics()); |
| 8348 | LastDiagFromFrom = false; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8349 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8350 | } |
| 8351 | |
| 8352 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8353 | if (!LastDiagFromFrom) |
| 8354 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8355 | ToContext.getDiagnostics()); |
| 8356 | LastDiagFromFrom = true; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8357 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8358 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8359 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8360 | void ASTImporter::CompleteDecl (Decl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8361 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8362 | if (!ID->getDefinition()) |
| 8363 | ID->startDefinition(); |
| 8364 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8365 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8366 | if (!PD->getDefinition()) |
| 8367 | PD->startDefinition(); |
| 8368 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8369 | else if (auto *TD = dyn_cast<TagDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8370 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 8371 | TD->startDefinition(); |
| 8372 | TD->setCompleteDefinition(true); |
| 8373 | } |
| 8374 | } |
| 8375 | else { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8376 | assert(0 && "CompleteDecl called on a Decl that can't be completed"); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8377 | } |
| 8378 | } |
| 8379 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8380 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { |
| 8381 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); |
| 8382 | assert((Pos == ImportedDecls.end() || Pos->second == To) && |
| 8383 | "Try to import an already imported Decl"); |
| 8384 | if (Pos != ImportedDecls.end()) |
| 8385 | return Pos->second; |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8386 | ImportedDecls[From] = To; |
| 8387 | return To; |
Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 8388 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8389 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8390 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 8391 | bool Complain) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 8392 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8393 | = ImportedTypes.find(From.getTypePtr()); |
| 8394 | if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To)) |
| 8395 | return true; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 8396 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8397 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8398 | getStructuralEquivalenceKind(*this), false, |
| 8399 | Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 8400 | return Ctx.IsEquivalent(From, To); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8401 | } |