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); |
Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 582 | ExpectedStmt VisitConstantExpr(ConstantExpr *E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 583 | ExpectedStmt VisitParenExpr(ParenExpr *E); |
| 584 | ExpectedStmt VisitParenListExpr(ParenListExpr *E); |
| 585 | ExpectedStmt VisitStmtExpr(StmtExpr *E); |
| 586 | ExpectedStmt VisitUnaryOperator(UnaryOperator *E); |
| 587 | ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); |
| 588 | ExpectedStmt VisitBinaryOperator(BinaryOperator *E); |
| 589 | ExpectedStmt VisitConditionalOperator(ConditionalOperator *E); |
| 590 | ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E); |
| 591 | ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E); |
| 592 | ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); |
| 593 | ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E); |
| 594 | ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
| 595 | ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E); |
| 596 | ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E); |
| 597 | ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 598 | ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE); |
| 599 | ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E); |
| 600 | ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E); |
| 601 | ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); |
| 602 | ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); |
| 603 | ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); |
| 604 | ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E); |
| 605 | ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); |
| 606 | ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E); |
| 607 | ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E); |
| 608 | ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E); |
| 609 | ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E); |
| 610 | ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E); |
| 611 | ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E); |
| 612 | ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); |
| 613 | ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E); |
| 614 | ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E); |
| 615 | ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); |
| 616 | ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E); |
| 617 | ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E); |
| 618 | ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E); |
| 619 | ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); |
| 620 | ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); |
| 621 | ExpectedStmt VisitMemberExpr(MemberExpr *E); |
| 622 | ExpectedStmt VisitCallExpr(CallExpr *E); |
| 623 | ExpectedStmt VisitLambdaExpr(LambdaExpr *LE); |
| 624 | ExpectedStmt VisitInitListExpr(InitListExpr *E); |
| 625 | ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E); |
| 626 | ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E); |
| 627 | ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); |
| 628 | ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); |
| 629 | ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); |
| 630 | ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E); |
| 631 | ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); |
| 632 | ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E); |
| 633 | ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 634 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 635 | template<typename IIter, typename OIter> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 636 | Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 637 | using ItemT = typename std::remove_reference<decltype(*Obegin)>::type; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 638 | for (; Ibegin != Iend; ++Ibegin, ++Obegin) { |
| 639 | Expected<ItemT> ToOrErr = import(*Ibegin); |
| 640 | if (!ToOrErr) |
| 641 | return ToOrErr.takeError(); |
| 642 | *Obegin = *ToOrErr; |
| 643 | } |
| 644 | return Error::success(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 645 | } |
| 646 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 647 | // Import every item from a container structure into an output container. |
| 648 | // If error occurs, stops at first error and returns the error. |
| 649 | // The output container should have space for all needed elements (it is not |
| 650 | // expanded, new items are put into from the beginning). |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 651 | template<typename InContainerTy, typename OutContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 652 | Error ImportContainerChecked( |
| 653 | const InContainerTy &InContainer, OutContainerTy &OutContainer) { |
| 654 | return ImportArrayChecked( |
| 655 | InContainer.begin(), InContainer.end(), OutContainer.begin()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | template<typename InContainerTy, typename OIter> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 659 | Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 660 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); |
| 661 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 662 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 663 | void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 664 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 665 | Expected<FunctionDecl *> FindFunctionTemplateSpecialization( |
| 666 | FunctionDecl *FromFD); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 667 | }; |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 668 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 669 | // FIXME: Temporary until every import returns Expected. |
| 670 | template <> |
| 671 | Expected<TemplateName> ASTNodeImporter::import(const TemplateName &From) { |
| 672 | TemplateName To = Importer.Import(From); |
| 673 | if (To.isNull() && !From.isNull()) |
| 674 | return make_error<ImportError>(); |
| 675 | return To; |
| 676 | } |
| 677 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 678 | template <typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 679 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 680 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 681 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 682 | auto ToLAngleLocOrErr = import(FromLAngleLoc); |
| 683 | if (!ToLAngleLocOrErr) |
| 684 | return ToLAngleLocOrErr.takeError(); |
| 685 | auto ToRAngleLocOrErr = import(FromRAngleLoc); |
| 686 | if (!ToRAngleLocOrErr) |
| 687 | return ToRAngleLocOrErr.takeError(); |
| 688 | |
| 689 | TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr); |
| 690 | if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo)) |
| 691 | return Err; |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 692 | Result = ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 693 | return Error::success(); |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 694 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 695 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 696 | template <> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 697 | Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 698 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { |
| 699 | return ImportTemplateArgumentListInfo( |
| 700 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); |
| 701 | } |
| 702 | |
| 703 | template <> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 704 | Error ASTNodeImporter::ImportTemplateArgumentListInfo< |
| 705 | ASTTemplateArgumentListInfo>( |
| 706 | const ASTTemplateArgumentListInfo &From, |
| 707 | TemplateArgumentListInfo &Result) { |
| 708 | return ImportTemplateArgumentListInfo( |
| 709 | From.LAngleLoc, From.RAngleLoc, From.arguments(), Result); |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 710 | } |
| 711 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 712 | Expected<ASTNodeImporter::FunctionTemplateAndArgsTy> |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 713 | ASTNodeImporter::ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 714 | FunctionDecl *FromFD) { |
| 715 | assert(FromFD->getTemplatedKind() == |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 716 | FunctionDecl::TK_FunctionTemplateSpecialization); |
| 717 | |
| 718 | FunctionTemplateAndArgsTy Result; |
| 719 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 720 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 721 | if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate())) |
| 722 | return std::move(Err); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 723 | |
| 724 | // Import template arguments. |
| 725 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 726 | if (Error Err = ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), |
| 727 | std::get<1>(Result))) |
| 728 | return std::move(Err); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 729 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 730 | return Result; |
| 731 | } |
| 732 | |
| 733 | template <> |
| 734 | Expected<TemplateParameterList *> |
| 735 | ASTNodeImporter::import(TemplateParameterList *From) { |
| 736 | SmallVector<NamedDecl *, 4> To(From->size()); |
| 737 | if (Error Err = ImportContainerChecked(*From, To)) |
| 738 | return std::move(Err); |
| 739 | |
| 740 | ExpectedExpr ToRequiresClause = import(From->getRequiresClause()); |
| 741 | if (!ToRequiresClause) |
| 742 | return ToRequiresClause.takeError(); |
| 743 | |
| 744 | auto ToTemplateLocOrErr = import(From->getTemplateLoc()); |
| 745 | if (!ToTemplateLocOrErr) |
| 746 | return ToTemplateLocOrErr.takeError(); |
| 747 | auto ToLAngleLocOrErr = import(From->getLAngleLoc()); |
| 748 | if (!ToLAngleLocOrErr) |
| 749 | return ToLAngleLocOrErr.takeError(); |
| 750 | auto ToRAngleLocOrErr = import(From->getRAngleLoc()); |
| 751 | if (!ToRAngleLocOrErr) |
| 752 | return ToRAngleLocOrErr.takeError(); |
| 753 | |
| 754 | return TemplateParameterList::Create( |
| 755 | Importer.getToContext(), |
| 756 | *ToTemplateLocOrErr, |
| 757 | *ToLAngleLocOrErr, |
| 758 | To, |
| 759 | *ToRAngleLocOrErr, |
| 760 | *ToRequiresClause); |
| 761 | } |
| 762 | |
| 763 | template <> |
| 764 | Expected<TemplateArgument> |
| 765 | ASTNodeImporter::import(const TemplateArgument &From) { |
| 766 | switch (From.getKind()) { |
| 767 | case TemplateArgument::Null: |
| 768 | return TemplateArgument(); |
| 769 | |
| 770 | case TemplateArgument::Type: { |
| 771 | ExpectedType ToTypeOrErr = import(From.getAsType()); |
| 772 | if (!ToTypeOrErr) |
| 773 | return ToTypeOrErr.takeError(); |
| 774 | return TemplateArgument(*ToTypeOrErr); |
| 775 | } |
| 776 | |
| 777 | case TemplateArgument::Integral: { |
| 778 | ExpectedType ToTypeOrErr = import(From.getIntegralType()); |
| 779 | if (!ToTypeOrErr) |
| 780 | return ToTypeOrErr.takeError(); |
| 781 | return TemplateArgument(From, *ToTypeOrErr); |
| 782 | } |
| 783 | |
| 784 | case TemplateArgument::Declaration: { |
| 785 | Expected<ValueDecl *> ToOrErr = import(From.getAsDecl()); |
| 786 | if (!ToOrErr) |
| 787 | return ToOrErr.takeError(); |
| 788 | ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl()); |
| 789 | if (!ToTypeOrErr) |
| 790 | return ToTypeOrErr.takeError(); |
| 791 | return TemplateArgument(*ToOrErr, *ToTypeOrErr); |
| 792 | } |
| 793 | |
| 794 | case TemplateArgument::NullPtr: { |
| 795 | ExpectedType ToTypeOrErr = import(From.getNullPtrType()); |
| 796 | if (!ToTypeOrErr) |
| 797 | return ToTypeOrErr.takeError(); |
| 798 | return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true); |
| 799 | } |
| 800 | |
| 801 | case TemplateArgument::Template: { |
| 802 | Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate()); |
| 803 | if (!ToTemplateOrErr) |
| 804 | return ToTemplateOrErr.takeError(); |
| 805 | |
| 806 | return TemplateArgument(*ToTemplateOrErr); |
| 807 | } |
| 808 | |
| 809 | case TemplateArgument::TemplateExpansion: { |
| 810 | Expected<TemplateName> ToTemplateOrErr = |
| 811 | import(From.getAsTemplateOrTemplatePattern()); |
| 812 | if (!ToTemplateOrErr) |
| 813 | return ToTemplateOrErr.takeError(); |
| 814 | |
| 815 | return TemplateArgument( |
| 816 | *ToTemplateOrErr, From.getNumTemplateExpansions()); |
| 817 | } |
| 818 | |
| 819 | case TemplateArgument::Expression: |
| 820 | if (ExpectedExpr ToExpr = import(From.getAsExpr())) |
| 821 | return TemplateArgument(*ToExpr); |
| 822 | else |
| 823 | return ToExpr.takeError(); |
| 824 | |
| 825 | case TemplateArgument::Pack: { |
| 826 | SmallVector<TemplateArgument, 2> ToPack; |
| 827 | ToPack.reserve(From.pack_size()); |
| 828 | if (Error Err = ImportTemplateArguments( |
| 829 | From.pack_begin(), From.pack_size(), ToPack)) |
| 830 | return std::move(Err); |
| 831 | |
| 832 | return TemplateArgument( |
| 833 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | llvm_unreachable("Invalid template argument kind"); |
| 838 | } |
| 839 | |
| 840 | template <> |
| 841 | Expected<TemplateArgumentLoc> |
| 842 | ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) { |
| 843 | Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument()); |
| 844 | if (!ArgOrErr) |
| 845 | return ArgOrErr.takeError(); |
| 846 | TemplateArgument Arg = *ArgOrErr; |
| 847 | |
| 848 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); |
| 849 | |
| 850 | TemplateArgumentLocInfo ToInfo; |
| 851 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 852 | ExpectedExpr E = import(FromInfo.getAsExpr()); |
| 853 | if (!E) |
| 854 | return E.takeError(); |
| 855 | ToInfo = TemplateArgumentLocInfo(*E); |
| 856 | } else if (Arg.getKind() == TemplateArgument::Type) { |
| 857 | if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo())) |
| 858 | ToInfo = TemplateArgumentLocInfo(*TSIOrErr); |
| 859 | else |
| 860 | return TSIOrErr.takeError(); |
| 861 | } else { |
| 862 | auto ToTemplateQualifierLocOrErr = |
| 863 | import(FromInfo.getTemplateQualifierLoc()); |
| 864 | if (!ToTemplateQualifierLocOrErr) |
| 865 | return ToTemplateQualifierLocOrErr.takeError(); |
| 866 | auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc()); |
| 867 | if (!ToTemplateNameLocOrErr) |
| 868 | return ToTemplateNameLocOrErr.takeError(); |
| 869 | auto ToTemplateEllipsisLocOrErr = |
| 870 | import(FromInfo.getTemplateEllipsisLoc()); |
| 871 | if (!ToTemplateEllipsisLocOrErr) |
| 872 | return ToTemplateEllipsisLocOrErr.takeError(); |
| 873 | |
| 874 | ToInfo = TemplateArgumentLocInfo( |
| 875 | *ToTemplateQualifierLocOrErr, |
| 876 | *ToTemplateNameLocOrErr, |
| 877 | *ToTemplateEllipsisLocOrErr); |
| 878 | } |
| 879 | |
| 880 | return TemplateArgumentLoc(Arg, ToInfo); |
| 881 | } |
| 882 | |
| 883 | template <> |
| 884 | Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) { |
| 885 | if (DG.isNull()) |
| 886 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); |
| 887 | size_t NumDecls = DG.end() - DG.begin(); |
| 888 | SmallVector<Decl *, 1> ToDecls; |
| 889 | ToDecls.reserve(NumDecls); |
| 890 | for (Decl *FromD : DG) { |
| 891 | if (auto ToDOrErr = import(FromD)) |
| 892 | ToDecls.push_back(*ToDOrErr); |
| 893 | else |
| 894 | return ToDOrErr.takeError(); |
| 895 | } |
| 896 | return DeclGroupRef::Create(Importer.getToContext(), |
| 897 | ToDecls.begin(), |
| 898 | NumDecls); |
| 899 | } |
| 900 | |
| 901 | template <> |
| 902 | Expected<ASTNodeImporter::Designator> |
| 903 | ASTNodeImporter::import(const Designator &D) { |
| 904 | if (D.isFieldDesignator()) { |
| 905 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); |
| 906 | |
| 907 | ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc()); |
| 908 | if (!ToDotLocOrErr) |
| 909 | return ToDotLocOrErr.takeError(); |
| 910 | |
| 911 | ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc()); |
| 912 | if (!ToFieldLocOrErr) |
| 913 | return ToFieldLocOrErr.takeError(); |
| 914 | |
| 915 | return Designator(ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr); |
| 916 | } |
| 917 | |
| 918 | ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc()); |
| 919 | if (!ToLBracketLocOrErr) |
| 920 | return ToLBracketLocOrErr.takeError(); |
| 921 | |
| 922 | ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc()); |
| 923 | if (!ToRBracketLocOrErr) |
| 924 | return ToRBracketLocOrErr.takeError(); |
| 925 | |
| 926 | if (D.isArrayDesignator()) |
| 927 | return Designator(D.getFirstExprIndex(), |
| 928 | *ToLBracketLocOrErr, *ToRBracketLocOrErr); |
| 929 | |
| 930 | ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc()); |
| 931 | if (!ToEllipsisLocOrErr) |
| 932 | return ToEllipsisLocOrErr.takeError(); |
| 933 | |
| 934 | assert(D.isArrayRangeDesignator()); |
| 935 | return Designator( |
| 936 | D.getFirstExprIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr, |
| 937 | *ToRBracketLocOrErr); |
| 938 | } |
| 939 | |
| 940 | template <> |
| 941 | Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) { |
| 942 | VarDecl *Var = nullptr; |
| 943 | if (From.capturesVariable()) { |
| 944 | if (auto VarOrErr = import(From.getCapturedVar())) |
| 945 | Var = *VarOrErr; |
| 946 | else |
| 947 | return VarOrErr.takeError(); |
| 948 | } |
| 949 | |
| 950 | auto LocationOrErr = import(From.getLocation()); |
| 951 | if (!LocationOrErr) |
| 952 | return LocationOrErr.takeError(); |
| 953 | |
| 954 | SourceLocation EllipsisLoc; |
| 955 | if (From.isPackExpansion()) |
| 956 | if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc())) |
| 957 | return std::move(Err); |
| 958 | |
| 959 | return LambdaCapture( |
| 960 | *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var, |
| 961 | EllipsisLoc); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 962 | } |
| 963 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 964 | } // namespace clang |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 965 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 966 | //---------------------------------------------------------------------------- |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 967 | // Import Types |
| 968 | //---------------------------------------------------------------------------- |
| 969 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 970 | using namespace clang; |
| 971 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 972 | ExpectedType ASTNodeImporter::VisitType(const Type *T) { |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 973 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) |
| 974 | << T->getTypeClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 975 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 976 | } |
| 977 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 978 | ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ |
| 979 | ExpectedType UnderlyingTypeOrErr = import(T->getValueType()); |
| 980 | if (!UnderlyingTypeOrErr) |
| 981 | return UnderlyingTypeOrErr.takeError(); |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 982 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 983 | return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr); |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 984 | } |
| 985 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 986 | ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 987 | switch (T->getKind()) { |
Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 988 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 989 | case BuiltinType::Id: \ |
| 990 | return Importer.getToContext().SingletonId; |
Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 991 | #include "clang/Basic/OpenCLImageTypes.def" |
Andrew Savonichev | 3fee351 | 2018-11-08 11:25:41 +0000 | [diff] [blame] | 992 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ |
| 993 | case BuiltinType::Id: \ |
| 994 | return Importer.getToContext().Id##Ty; |
| 995 | #include "clang/Basic/OpenCLExtensionTypes.def" |
John McCall | e314e27 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 996 | #define SHARED_SINGLETON_TYPE(Expansion) |
| 997 | #define BUILTIN_TYPE(Id, SingletonId) \ |
| 998 | case BuiltinType::Id: return Importer.getToContext().SingletonId; |
| 999 | #include "clang/AST/BuiltinTypes.def" |
| 1000 | |
| 1001 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" |
| 1002 | // context supports C++. |
| 1003 | |
| 1004 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" |
| 1005 | // context supports ObjC. |
| 1006 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1007 | case BuiltinType::Char_U: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1008 | // The context we're importing from has an unsigned 'char'. If we're |
| 1009 | // importing into a context with a signed 'char', translate to |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1010 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1011 | if (Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1012 | return Importer.getToContext().UnsignedCharTy; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1013 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1014 | return Importer.getToContext().CharTy; |
| 1015 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1016 | case BuiltinType::Char_S: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1017 | // The context we're importing from has an unsigned 'char'. If we're |
| 1018 | // importing into a context with a signed 'char', translate to |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1019 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1020 | if (!Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1021 | return Importer.getToContext().SignedCharTy; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1022 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1023 | return Importer.getToContext().CharTy; |
| 1024 | |
Chris Lattner | ad3467e | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 1025 | case BuiltinType::WChar_S: |
| 1026 | case BuiltinType::WChar_U: |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1027 | // FIXME: If not in C++, shall we translate to the C equivalent of |
| 1028 | // wchar_t? |
| 1029 | return Importer.getToContext().WCharTy; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1030 | } |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 1031 | |
| 1032 | llvm_unreachable("Invalid BuiltinType Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1033 | } |
| 1034 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1035 | ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { |
| 1036 | ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType()); |
| 1037 | if (!ToOriginalTypeOrErr) |
| 1038 | return ToOriginalTypeOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1039 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1040 | return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1043 | ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) { |
| 1044 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1045 | if (!ToElementTypeOrErr) |
| 1046 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1047 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1048 | return Importer.getToContext().getComplexType(*ToElementTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1049 | } |
| 1050 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1051 | ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) { |
| 1052 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1053 | if (!ToPointeeTypeOrErr) |
| 1054 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1055 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1056 | return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1057 | } |
| 1058 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1059 | ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1060 | // FIXME: Check for blocks support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1061 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1062 | if (!ToPointeeTypeOrErr) |
| 1063 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1064 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1065 | return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1066 | } |
| 1067 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1068 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1069 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1070 | // FIXME: Check for C++ support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1071 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); |
| 1072 | if (!ToPointeeTypeOrErr) |
| 1073 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1074 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1075 | return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1076 | } |
| 1077 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1078 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1079 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1080 | // FIXME: Check for C++0x support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1081 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); |
| 1082 | if (!ToPointeeTypeOrErr) |
| 1083 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1084 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1085 | return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1086 | } |
| 1087 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1088 | ExpectedType |
| 1089 | ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1090 | // FIXME: Check for C++ support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1091 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1092 | if (!ToPointeeTypeOrErr) |
| 1093 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1094 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1095 | ExpectedType ClassTypeOrErr = import(QualType(T->getClass(), 0)); |
| 1096 | if (!ClassTypeOrErr) |
| 1097 | return ClassTypeOrErr.takeError(); |
| 1098 | |
| 1099 | return Importer.getToContext().getMemberPointerType( |
| 1100 | *ToPointeeTypeOrErr, (*ClassTypeOrErr).getTypePtr()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1101 | } |
| 1102 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1103 | ExpectedType |
| 1104 | ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { |
| 1105 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1106 | if (!ToElementTypeOrErr) |
| 1107 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1108 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1109 | return Importer.getToContext().getConstantArrayType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1110 | T->getSize(), |
| 1111 | T->getSizeModifier(), |
| 1112 | T->getIndexTypeCVRQualifiers()); |
| 1113 | } |
| 1114 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1115 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1116 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1117 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1118 | if (!ToElementTypeOrErr) |
| 1119 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1120 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1121 | return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1122 | T->getSizeModifier(), |
| 1123 | T->getIndexTypeCVRQualifiers()); |
| 1124 | } |
| 1125 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1126 | ExpectedType |
| 1127 | ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { |
| 1128 | QualType ToElementType; |
| 1129 | Expr *ToSizeExpr; |
| 1130 | SourceRange ToBracketsRange; |
| 1131 | if (auto Imp = importSeq( |
| 1132 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) |
| 1133 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; |
| 1134 | else |
| 1135 | return Imp.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1136 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1137 | return Importer.getToContext().getVariableArrayType( |
| 1138 | ToElementType, ToSizeExpr, T->getSizeModifier(), |
| 1139 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1140 | } |
| 1141 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1142 | ExpectedType ASTNodeImporter::VisitDependentSizedArrayType( |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1143 | const DependentSizedArrayType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1144 | QualType ToElementType; |
| 1145 | Expr *ToSizeExpr; |
| 1146 | SourceRange ToBracketsRange; |
| 1147 | if (auto Imp = importSeq( |
| 1148 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) |
| 1149 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; |
| 1150 | else |
| 1151 | return Imp.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1152 | // SizeExpr may be null if size is not specified directly. |
| 1153 | // For example, 'int a[]'. |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1154 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1155 | return Importer.getToContext().getDependentSizedArrayType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1156 | ToElementType, ToSizeExpr, T->getSizeModifier(), |
| 1157 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1158 | } |
| 1159 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1160 | ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) { |
| 1161 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1162 | if (!ToElementTypeOrErr) |
| 1163 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1164 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1165 | return Importer.getToContext().getVectorType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1166 | T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 1167 | T->getVectorKind()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1168 | } |
| 1169 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1170 | ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { |
| 1171 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1172 | if (!ToElementTypeOrErr) |
| 1173 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1174 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1175 | return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1176 | T->getNumElements()); |
| 1177 | } |
| 1178 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1179 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1180 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1181 | // FIXME: What happens if we're importing a function without a prototype |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1182 | // into C++? Should we make it variadic? |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1183 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); |
| 1184 | if (!ToReturnTypeOrErr) |
| 1185 | return ToReturnTypeOrErr.takeError(); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1186 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1187 | return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr, |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1188 | T->getExtInfo()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1189 | } |
| 1190 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1191 | ExpectedType |
| 1192 | ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { |
| 1193 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); |
| 1194 | if (!ToReturnTypeOrErr) |
| 1195 | return ToReturnTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1196 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1197 | // Import argument types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1198 | SmallVector<QualType, 4> ArgTypes; |
Aaron Ballman | 40bd0aa | 2014-03-17 15:23:01 +0000 | [diff] [blame] | 1199 | for (const auto &A : T->param_types()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1200 | ExpectedType TyOrErr = import(A); |
| 1201 | if (!TyOrErr) |
| 1202 | return TyOrErr.takeError(); |
| 1203 | ArgTypes.push_back(*TyOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1204 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1205 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1206 | // Import exception types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1207 | SmallVector<QualType, 4> ExceptionTypes; |
Aaron Ballman | b088fbe | 2014-03-17 15:38:09 +0000 | [diff] [blame] | 1208 | for (const auto &E : T->exceptions()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1209 | ExpectedType TyOrErr = import(E); |
| 1210 | if (!TyOrErr) |
| 1211 | return TyOrErr.takeError(); |
| 1212 | ExceptionTypes.push_back(*TyOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1213 | } |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 1214 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1215 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); |
| 1216 | FunctionProtoType::ExtProtoInfo ToEPI; |
| 1217 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1218 | auto Imp = importSeq( |
| 1219 | FromEPI.ExceptionSpec.NoexceptExpr, |
| 1220 | FromEPI.ExceptionSpec.SourceDecl, |
| 1221 | FromEPI.ExceptionSpec.SourceTemplate); |
| 1222 | if (!Imp) |
| 1223 | return Imp.takeError(); |
| 1224 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1225 | ToEPI.ExtInfo = FromEPI.ExtInfo; |
| 1226 | ToEPI.Variadic = FromEPI.Variadic; |
| 1227 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; |
| 1228 | ToEPI.TypeQuals = FromEPI.TypeQuals; |
| 1229 | ToEPI.RefQualifier = FromEPI.RefQualifier; |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 1230 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; |
| 1231 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1232 | std::tie( |
| 1233 | ToEPI.ExceptionSpec.NoexceptExpr, |
| 1234 | ToEPI.ExceptionSpec.SourceDecl, |
| 1235 | ToEPI.ExceptionSpec.SourceTemplate) = *Imp; |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1236 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1237 | return Importer.getToContext().getFunctionType( |
| 1238 | *ToReturnTypeOrErr, ArgTypes, ToEPI); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1239 | } |
| 1240 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1241 | ExpectedType ASTNodeImporter::VisitUnresolvedUsingType( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1242 | const UnresolvedUsingType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1243 | UnresolvedUsingTypenameDecl *ToD; |
| 1244 | Decl *ToPrevD; |
| 1245 | if (auto Imp = importSeq(T->getDecl(), T->getDecl()->getPreviousDecl())) |
| 1246 | std::tie(ToD, ToPrevD) = *Imp; |
| 1247 | else |
| 1248 | return Imp.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1249 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1250 | return Importer.getToContext().getTypeDeclType( |
| 1251 | ToD, cast_or_null<TypeDecl>(ToPrevD)); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1252 | } |
| 1253 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1254 | ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) { |
| 1255 | ExpectedType ToInnerTypeOrErr = import(T->getInnerType()); |
| 1256 | if (!ToInnerTypeOrErr) |
| 1257 | return ToInnerTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1258 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1259 | return Importer.getToContext().getParenType(*ToInnerTypeOrErr); |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 1260 | } |
| 1261 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1262 | ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { |
| 1263 | Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1264 | if (!ToDeclOrErr) |
| 1265 | return ToDeclOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1266 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1267 | return Importer.getToContext().getTypeDeclType(*ToDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1268 | } |
| 1269 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1270 | ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { |
| 1271 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); |
| 1272 | if (!ToExprOrErr) |
| 1273 | return ToExprOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1274 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1275 | return Importer.getToContext().getTypeOfExprType(*ToExprOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1276 | } |
| 1277 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1278 | ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { |
| 1279 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1280 | if (!ToUnderlyingTypeOrErr) |
| 1281 | return ToUnderlyingTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1282 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1283 | return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1284 | } |
| 1285 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1286 | ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1287 | // FIXME: Make sure that the "to" context supports C++0x! |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1288 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); |
| 1289 | if (!ToExprOrErr) |
| 1290 | return ToExprOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1291 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1292 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1293 | if (!ToUnderlyingTypeOrErr) |
| 1294 | return ToUnderlyingTypeOrErr.takeError(); |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 1295 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1296 | return Importer.getToContext().getDecltypeType( |
| 1297 | *ToExprOrErr, *ToUnderlyingTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1298 | } |
| 1299 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1300 | ExpectedType |
| 1301 | ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 1302 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); |
| 1303 | if (!ToBaseTypeOrErr) |
| 1304 | return ToBaseTypeOrErr.takeError(); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1305 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1306 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1307 | if (!ToUnderlyingTypeOrErr) |
| 1308 | return ToUnderlyingTypeOrErr.takeError(); |
| 1309 | |
| 1310 | return Importer.getToContext().getUnaryTransformType( |
| 1311 | *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind()); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1312 | } |
| 1313 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1314 | ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 1315 | // FIXME: Make sure that the "to" context supports C++11! |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1316 | ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType()); |
| 1317 | if (!ToDeducedTypeOrErr) |
| 1318 | return ToDeducedTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1319 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1320 | return Importer.getToContext().getAutoType(*ToDeducedTypeOrErr, |
| 1321 | T->getKeyword(), |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 1322 | /*IsDependent*/false); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1323 | } |
| 1324 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1325 | ExpectedType ASTNodeImporter::VisitInjectedClassNameType( |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1326 | const InjectedClassNameType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1327 | Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1328 | if (!ToDeclOrErr) |
| 1329 | return ToDeclOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1330 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1331 | ExpectedType ToInjTypeOrErr = import(T->getInjectedSpecializationType()); |
| 1332 | if (!ToInjTypeOrErr) |
| 1333 | return ToInjTypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1334 | |
| 1335 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading |
| 1336 | // See comments in InjectedClassNameType definition for details |
| 1337 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); |
| 1338 | enum { |
| 1339 | TypeAlignmentInBits = 4, |
| 1340 | TypeAlignment = 1 << TypeAlignmentInBits |
| 1341 | }; |
| 1342 | |
| 1343 | return QualType(new (Importer.getToContext(), TypeAlignment) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1344 | InjectedClassNameType(*ToDeclOrErr, *ToInjTypeOrErr), 0); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1345 | } |
| 1346 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1347 | ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) { |
| 1348 | Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1349 | if (!ToDeclOrErr) |
| 1350 | return ToDeclOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1351 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1352 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1353 | } |
| 1354 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1355 | ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) { |
| 1356 | Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1357 | if (!ToDeclOrErr) |
| 1358 | return ToDeclOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1359 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1360 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1361 | } |
| 1362 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1363 | ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { |
| 1364 | ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType()); |
| 1365 | if (!ToModifiedTypeOrErr) |
| 1366 | return ToModifiedTypeOrErr.takeError(); |
| 1367 | ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType()); |
| 1368 | if (!ToEquivalentTypeOrErr) |
| 1369 | return ToEquivalentTypeOrErr.takeError(); |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1370 | |
| 1371 | return Importer.getToContext().getAttributedType(T->getAttrKind(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1372 | *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr); |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1373 | } |
| 1374 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1375 | ExpectedType ASTNodeImporter::VisitTemplateTypeParmType( |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1376 | const TemplateTypeParmType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1377 | Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1378 | if (!ToDeclOrErr) |
| 1379 | return ToDeclOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1380 | |
| 1381 | return Importer.getToContext().getTemplateTypeParmType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1382 | T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1385 | ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType( |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1386 | const SubstTemplateTypeParmType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1387 | ExpectedType ReplacedOrErr = import(QualType(T->getReplacedParameter(), 0)); |
| 1388 | if (!ReplacedOrErr) |
| 1389 | return ReplacedOrErr.takeError(); |
| 1390 | const TemplateTypeParmType *Replaced = |
| 1391 | cast<TemplateTypeParmType>((*ReplacedOrErr).getTypePtr()); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1392 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1393 | ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType()); |
| 1394 | if (!ToReplacementTypeOrErr) |
| 1395 | return ToReplacementTypeOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1396 | |
| 1397 | return Importer.getToContext().getSubstTemplateTypeParmType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1398 | Replaced, (*ToReplacementTypeOrErr).getCanonicalType()); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1399 | } |
| 1400 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1401 | ExpectedType ASTNodeImporter::VisitTemplateSpecializationType( |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1402 | const TemplateSpecializationType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1403 | auto ToTemplateOrErr = import(T->getTemplateName()); |
| 1404 | if (!ToTemplateOrErr) |
| 1405 | return ToTemplateOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1406 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1407 | SmallVector<TemplateArgument, 2> ToTemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1408 | if (Error Err = ImportTemplateArguments( |
| 1409 | T->getArgs(), T->getNumArgs(), ToTemplateArgs)) |
| 1410 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1411 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1412 | QualType ToCanonType; |
| 1413 | if (!QualType(T, 0).isCanonical()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1414 | QualType FromCanonType |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1415 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1416 | if (ExpectedType TyOrErr = import(FromCanonType)) |
| 1417 | ToCanonType = *TyOrErr; |
| 1418 | else |
| 1419 | return TyOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1420 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1421 | return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr, |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 1422 | ToTemplateArgs, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1423 | ToCanonType); |
| 1424 | } |
| 1425 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1426 | ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1427 | // Note: the qualifier in an ElaboratedType is optional. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1428 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1429 | if (!ToQualifierOrErr) |
| 1430 | return ToQualifierOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1431 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1432 | ExpectedType ToNamedTypeOrErr = import(T->getNamedType()); |
| 1433 | if (!ToNamedTypeOrErr) |
| 1434 | return ToNamedTypeOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1435 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1436 | Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl()); |
| 1437 | if (!ToOwnedTagDeclOrErr) |
| 1438 | return ToOwnedTagDeclOrErr.takeError(); |
Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 1439 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1440 | return Importer.getToContext().getElaboratedType(T->getKeyword(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1441 | *ToQualifierOrErr, |
| 1442 | *ToNamedTypeOrErr, |
| 1443 | *ToOwnedTagDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1444 | } |
| 1445 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1446 | ExpectedType |
| 1447 | ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { |
| 1448 | ExpectedType ToPatternOrErr = import(T->getPattern()); |
| 1449 | if (!ToPatternOrErr) |
| 1450 | return ToPatternOrErr.takeError(); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1451 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1452 | return Importer.getToContext().getPackExpansionType(*ToPatternOrErr, |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1453 | T->getNumExpansions()); |
| 1454 | } |
| 1455 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1456 | ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType( |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1457 | const DependentTemplateSpecializationType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1458 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1459 | if (!ToQualifierOrErr) |
| 1460 | return ToQualifierOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1461 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1462 | IdentifierInfo *ToName = Importer.Import(T->getIdentifier()); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1463 | |
| 1464 | SmallVector<TemplateArgument, 2> ToPack; |
| 1465 | ToPack.reserve(T->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1466 | if (Error Err = ImportTemplateArguments( |
| 1467 | T->getArgs(), T->getNumArgs(), ToPack)) |
| 1468 | return std::move(Err); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1469 | |
| 1470 | return Importer.getToContext().getDependentTemplateSpecializationType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1471 | T->getKeyword(), *ToQualifierOrErr, ToName, ToPack); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1472 | } |
| 1473 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1474 | ExpectedType |
| 1475 | ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) { |
| 1476 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1477 | if (!ToQualifierOrErr) |
| 1478 | return ToQualifierOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1479 | |
| 1480 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1481 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1482 | QualType Canon; |
| 1483 | if (T != T->getCanonicalTypeInternal().getTypePtr()) { |
| 1484 | if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal())) |
| 1485 | Canon = (*TyOrErr).getCanonicalType(); |
| 1486 | else |
| 1487 | return TyOrErr.takeError(); |
| 1488 | } |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1489 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1490 | return Importer.getToContext().getDependentNameType(T->getKeyword(), |
| 1491 | *ToQualifierOrErr, |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1492 | Name, Canon); |
| 1493 | } |
| 1494 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1495 | ExpectedType |
| 1496 | ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
| 1497 | Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1498 | if (!ToDeclOrErr) |
| 1499 | return ToDeclOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1500 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1501 | return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1502 | } |
| 1503 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1504 | ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { |
| 1505 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); |
| 1506 | if (!ToBaseTypeOrErr) |
| 1507 | return ToBaseTypeOrErr.takeError(); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1508 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1509 | SmallVector<QualType, 4> TypeArgs; |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 1510 | for (auto TypeArg : T->getTypeArgsAsWritten()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1511 | if (ExpectedType TyOrErr = import(TypeArg)) |
| 1512 | TypeArgs.push_back(*TyOrErr); |
| 1513 | else |
| 1514 | return TyOrErr.takeError(); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1515 | } |
| 1516 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1517 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 1518 | for (auto *P : T->quals()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1519 | if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P)) |
| 1520 | Protocols.push_back(*ProtocolOrErr); |
| 1521 | else |
| 1522 | return ProtocolOrErr.takeError(); |
| 1523 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1524 | } |
| 1525 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1526 | return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs, |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 1527 | Protocols, |
| 1528 | T->isKindOfTypeAsWritten()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1529 | } |
| 1530 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1531 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1532 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1533 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1534 | if (!ToPointeeTypeOrErr) |
| 1535 | return ToPointeeTypeOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1536 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1537 | return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1538 | } |
| 1539 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 1540 | //---------------------------------------------------------------------------- |
| 1541 | // Import Declarations |
| 1542 | //---------------------------------------------------------------------------- |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1543 | Error ASTNodeImporter::ImportDeclParts( |
| 1544 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, |
| 1545 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) { |
Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1546 | // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop. |
| 1547 | // example: int struct_in_proto(struct data_t{int a;int b;} *d); |
| 1548 | DeclContext *OrigDC = D->getDeclContext(); |
| 1549 | FunctionDecl *FunDecl; |
| 1550 | if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) && |
| 1551 | FunDecl->hasBody()) { |
Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1552 | auto getLeafPointeeType = [](const Type *T) { |
| 1553 | while (T->isPointerType() || T->isArrayType()) { |
| 1554 | T = T->getPointeeOrArrayElementType(); |
| 1555 | } |
| 1556 | return T; |
| 1557 | }; |
| 1558 | for (const ParmVarDecl *P : FunDecl->parameters()) { |
| 1559 | const Type *LeafT = |
| 1560 | getLeafPointeeType(P->getType().getCanonicalType().getTypePtr()); |
| 1561 | auto *RT = dyn_cast<RecordType>(LeafT); |
| 1562 | if (RT && RT->getDecl() == D) { |
| 1563 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 1564 | << D->getDeclKindName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1565 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1566 | } |
Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1567 | } |
| 1568 | } |
| 1569 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1570 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1571 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 1572 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1573 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1574 | // Import the name of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1575 | if (Error Err = importInto(Name, D->getDeclName())) |
| 1576 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1577 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1578 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1579 | if (Error Err = importInto(Loc, D->getLocation())) |
| 1580 | return Err; |
| 1581 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1582 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1583 | |
| 1584 | return Error::success(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1587 | Error ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1588 | if (!FromD) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1589 | return Error::success(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1590 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1591 | if (!ToD) |
| 1592 | if (Error Err = importInto(ToD, FromD)) |
| 1593 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1594 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1595 | if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) { |
| 1596 | if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) { |
| 1597 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && |
| 1598 | !ToRecord->getDefinition()) { |
| 1599 | if (Error Err = ImportDefinition(FromRecord, ToRecord)) |
| 1600 | return Err; |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1601 | } |
| 1602 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1603 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1604 | } |
| 1605 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1606 | if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) { |
| 1607 | if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1608 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1609 | if (Error Err = ImportDefinition(FromEnum, ToEnum)) |
| 1610 | return Err; |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1611 | } |
| 1612 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1613 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1614 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1615 | |
| 1616 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1617 | } |
| 1618 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1619 | Error |
| 1620 | ASTNodeImporter::ImportDeclarationNameLoc( |
| 1621 | const DeclarationNameInfo &From, DeclarationNameInfo& To) { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1622 | // NOTE: To.Name and To.Loc are already imported. |
| 1623 | // We only have to import To.LocInfo. |
| 1624 | switch (To.getName().getNameKind()) { |
| 1625 | case DeclarationName::Identifier: |
| 1626 | case DeclarationName::ObjCZeroArgSelector: |
| 1627 | case DeclarationName::ObjCOneArgSelector: |
| 1628 | case DeclarationName::ObjCMultiArgSelector: |
| 1629 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1630 | case DeclarationName::CXXDeductionGuideName: |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1631 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1632 | |
| 1633 | case DeclarationName::CXXOperatorName: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1634 | if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange())) |
| 1635 | To.setCXXOperatorNameRange(*ToRangeOrErr); |
| 1636 | else |
| 1637 | return ToRangeOrErr.takeError(); |
| 1638 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1639 | } |
| 1640 | case DeclarationName::CXXLiteralOperatorName: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1641 | if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc())) |
| 1642 | To.setCXXLiteralOperatorNameLoc(*LocOrErr); |
| 1643 | else |
| 1644 | return LocOrErr.takeError(); |
| 1645 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1646 | } |
| 1647 | case DeclarationName::CXXConstructorName: |
| 1648 | case DeclarationName::CXXDestructorName: |
| 1649 | case DeclarationName::CXXConversionFunctionName: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1650 | if (auto ToTInfoOrErr = import(From.getNamedTypeInfo())) |
| 1651 | To.setNamedTypeInfo(*ToTInfoOrErr); |
| 1652 | else |
| 1653 | return ToTInfoOrErr.takeError(); |
| 1654 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1655 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1656 | } |
Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 1657 | llvm_unreachable("Unknown name kind."); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1658 | } |
| 1659 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1660 | Error |
| 1661 | ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1662 | if (Importer.isMinimalImport() && !ForceImport) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1663 | auto ToDCOrErr = Importer.ImportContext(FromDC); |
| 1664 | return ToDCOrErr.takeError(); |
| 1665 | } |
Davide Italiano | 93a64ef | 2018-10-30 20:46:29 +0000 | [diff] [blame] | 1666 | llvm::SmallVector<Decl *, 8> ImportedDecls; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1667 | for (auto *From : FromDC->decls()) { |
| 1668 | ExpectedDecl ImportedOrErr = import(From); |
Davide Italiano | 93a64ef | 2018-10-30 20:46:29 +0000 | [diff] [blame] | 1669 | if (!ImportedOrErr) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1670 | // Ignore the error, continue with next Decl. |
| 1671 | // FIXME: Handle this case somehow better. |
Davide Italiano | 93a64ef | 2018-10-30 20:46:29 +0000 | [diff] [blame] | 1672 | consumeError(ImportedOrErr.takeError()); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1673 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1674 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1675 | return Error::success(); |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 1676 | } |
| 1677 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1678 | Error ASTNodeImporter::ImportDeclContext( |
| 1679 | Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) { |
| 1680 | auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext()); |
| 1681 | if (!ToDCOrErr) |
| 1682 | return ToDCOrErr.takeError(); |
| 1683 | ToDC = *ToDCOrErr; |
| 1684 | |
| 1685 | if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) { |
| 1686 | auto ToLexicalDCOrErr = Importer.ImportContext( |
| 1687 | FromD->getLexicalDeclContext()); |
| 1688 | if (!ToLexicalDCOrErr) |
| 1689 | return ToLexicalDCOrErr.takeError(); |
| 1690 | ToLexicalDC = *ToLexicalDCOrErr; |
| 1691 | } else |
| 1692 | ToLexicalDC = ToDC; |
| 1693 | |
| 1694 | return Error::success(); |
| 1695 | } |
| 1696 | |
| 1697 | Error ASTNodeImporter::ImportImplicitMethods( |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1698 | const CXXRecordDecl *From, CXXRecordDecl *To) { |
| 1699 | assert(From->isCompleteDefinition() && To->getDefinition() == To && |
| 1700 | "Import implicit methods to or from non-definition"); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1701 | |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1702 | for (CXXMethodDecl *FromM : From->methods()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1703 | if (FromM->isImplicit()) { |
| 1704 | Expected<CXXMethodDecl *> ToMOrErr = import(FromM); |
| 1705 | if (!ToMOrErr) |
| 1706 | return ToMOrErr.takeError(); |
| 1707 | } |
| 1708 | |
| 1709 | return Error::success(); |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1710 | } |
| 1711 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1712 | static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, |
| 1713 | ASTImporter &Importer) { |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1714 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1715 | Decl *ToTypedef = Importer.Import(FromTypedef); |
| 1716 | if (!ToTypedef) |
| 1717 | return make_error<ImportError>(); |
| 1718 | To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(ToTypedef)); |
| 1719 | // FIXME: This should be the final code. |
| 1720 | //if (Expected<Decl *> ToTypedefOrErr = Importer.Import(FromTypedef)) |
| 1721 | // To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr)); |
| 1722 | //else |
| 1723 | // return ToTypedefOrErr.takeError(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1724 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1725 | return Error::success(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1726 | } |
| 1727 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1728 | Error ASTNodeImporter::ImportDefinition( |
| 1729 | RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1730 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1731 | if (Kind == IDK_Everything) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1732 | return ImportDeclContext(From, /*ForceImport=*/true); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1733 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1734 | return Error::success(); |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1735 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1736 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1737 | To->startDefinition(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1738 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1739 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 1740 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1741 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1742 | // Add base classes. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1743 | if (auto *ToCXX = dyn_cast<CXXRecordDecl>(To)) { |
| 1744 | auto *FromCXX = cast<CXXRecordDecl>(From); |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1745 | |
| 1746 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); |
| 1747 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); |
| 1748 | ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1749 | ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1750 | ToData.Aggregate = FromData.Aggregate; |
| 1751 | ToData.PlainOldData = FromData.PlainOldData; |
| 1752 | ToData.Empty = FromData.Empty; |
| 1753 | ToData.Polymorphic = FromData.Polymorphic; |
| 1754 | ToData.Abstract = FromData.Abstract; |
| 1755 | ToData.IsStandardLayout = FromData.IsStandardLayout; |
Richard Smith | b6070db | 2018-04-05 18:55:37 +0000 | [diff] [blame] | 1756 | ToData.IsCXX11StandardLayout = FromData.IsCXX11StandardLayout; |
| 1757 | ToData.HasBasesWithFields = FromData.HasBasesWithFields; |
| 1758 | ToData.HasBasesWithNonStaticDataMembers = |
| 1759 | FromData.HasBasesWithNonStaticDataMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1760 | ToData.HasPrivateFields = FromData.HasPrivateFields; |
| 1761 | ToData.HasProtectedFields = FromData.HasProtectedFields; |
| 1762 | ToData.HasPublicFields = FromData.HasPublicFields; |
| 1763 | ToData.HasMutableFields = FromData.HasMutableFields; |
Richard Smith | ab44d5b | 2013-12-10 08:25:00 +0000 | [diff] [blame] | 1764 | ToData.HasVariantMembers = FromData.HasVariantMembers; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1765 | ToData.HasOnlyCMembers = FromData.HasOnlyCMembers; |
Richard Smith | e2648ba | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 1766 | ToData.HasInClassInitializer = FromData.HasInClassInitializer; |
Richard Smith | 593f993 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 1767 | ToData.HasUninitializedReferenceMember |
| 1768 | = FromData.HasUninitializedReferenceMember; |
Nico Weber | 6a6376b | 2016-02-19 01:52:46 +0000 | [diff] [blame] | 1769 | ToData.HasUninitializedFields = FromData.HasUninitializedFields; |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 1770 | ToData.HasInheritedConstructor = FromData.HasInheritedConstructor; |
| 1771 | ToData.HasInheritedAssignment = FromData.HasInheritedAssignment; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1772 | ToData.NeedOverloadResolutionForCopyConstructor |
| 1773 | = FromData.NeedOverloadResolutionForCopyConstructor; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1774 | ToData.NeedOverloadResolutionForMoveConstructor |
| 1775 | = FromData.NeedOverloadResolutionForMoveConstructor; |
| 1776 | ToData.NeedOverloadResolutionForMoveAssignment |
| 1777 | = FromData.NeedOverloadResolutionForMoveAssignment; |
| 1778 | ToData.NeedOverloadResolutionForDestructor |
| 1779 | = FromData.NeedOverloadResolutionForDestructor; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1780 | ToData.DefaultedCopyConstructorIsDeleted |
| 1781 | = FromData.DefaultedCopyConstructorIsDeleted; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1782 | ToData.DefaultedMoveConstructorIsDeleted |
| 1783 | = FromData.DefaultedMoveConstructorIsDeleted; |
| 1784 | ToData.DefaultedMoveAssignmentIsDeleted |
| 1785 | = FromData.DefaultedMoveAssignmentIsDeleted; |
| 1786 | ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1787 | ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers; |
| 1788 | ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1789 | ToData.HasConstexprNonCopyMoveConstructor |
| 1790 | = FromData.HasConstexprNonCopyMoveConstructor; |
Nico Weber | 72c57f4 | 2016-02-24 20:58:14 +0000 | [diff] [blame] | 1791 | ToData.HasDefaultedDefaultConstructor |
| 1792 | = FromData.HasDefaultedDefaultConstructor; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1793 | ToData.DefaultedDefaultConstructorIsConstexpr |
| 1794 | = FromData.DefaultedDefaultConstructorIsConstexpr; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1795 | ToData.HasConstexprDefaultConstructor |
| 1796 | = FromData.HasConstexprDefaultConstructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1797 | ToData.HasNonLiteralTypeFieldsOrBases |
| 1798 | = FromData.HasNonLiteralTypeFieldsOrBases; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1799 | // ComputedVisibleConversions not imported. |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1800 | ToData.UserProvidedDefaultConstructor |
| 1801 | = FromData.UserProvidedDefaultConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1802 | ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers; |
Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 1803 | ToData.ImplicitCopyConstructorCanHaveConstParamForVBase |
| 1804 | = FromData.ImplicitCopyConstructorCanHaveConstParamForVBase; |
| 1805 | ToData.ImplicitCopyConstructorCanHaveConstParamForNonVBase |
| 1806 | = FromData.ImplicitCopyConstructorCanHaveConstParamForNonVBase; |
Richard Smith | 1c33fe8 | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 1807 | ToData.ImplicitCopyAssignmentHasConstParam |
| 1808 | = FromData.ImplicitCopyAssignmentHasConstParam; |
| 1809 | ToData.HasDeclaredCopyConstructorWithConstParam |
| 1810 | = FromData.HasDeclaredCopyConstructorWithConstParam; |
| 1811 | ToData.HasDeclaredCopyAssignmentWithConstParam |
| 1812 | = FromData.HasDeclaredCopyAssignmentWithConstParam; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1813 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1814 | SmallVector<CXXBaseSpecifier *, 4> Bases; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1815 | for (const auto &Base1 : FromCXX->bases()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1816 | ExpectedType TyOrErr = import(Base1.getType()); |
| 1817 | if (!TyOrErr) |
| 1818 | return TyOrErr.takeError(); |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1819 | |
| 1820 | SourceLocation EllipsisLoc; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1821 | if (Base1.isPackExpansion()) { |
| 1822 | if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc())) |
| 1823 | EllipsisLoc = *LocOrErr; |
| 1824 | else |
| 1825 | return LocOrErr.takeError(); |
| 1826 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1827 | |
| 1828 | // Ensure that we have a definition for the base. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1829 | if (Error Err = |
| 1830 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl())) |
| 1831 | return Err; |
| 1832 | |
| 1833 | auto RangeOrErr = import(Base1.getSourceRange()); |
| 1834 | if (!RangeOrErr) |
| 1835 | return RangeOrErr.takeError(); |
| 1836 | |
| 1837 | auto TSIOrErr = import(Base1.getTypeSourceInfo()); |
| 1838 | if (!TSIOrErr) |
| 1839 | return TSIOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1840 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1841 | Bases.push_back( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1842 | new (Importer.getToContext()) CXXBaseSpecifier( |
| 1843 | *RangeOrErr, |
| 1844 | Base1.isVirtual(), |
| 1845 | Base1.isBaseOfClass(), |
| 1846 | Base1.getAccessSpecifierAsWritten(), |
| 1847 | *TSIOrErr, |
| 1848 | EllipsisLoc)); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1849 | } |
| 1850 | if (!Bases.empty()) |
Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1851 | ToCXX->setBases(Bases.data(), Bases.size()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1852 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1853 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1854 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1855 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 1856 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1857 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1858 | To->completeDefinition(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1859 | return Error::success(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1860 | } |
| 1861 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1862 | Error ASTNodeImporter::ImportInitializer(VarDecl *From, VarDecl *To) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1863 | if (To->getAnyInitializer()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1864 | return Error::success(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1865 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1866 | Expr *FromInit = From->getInit(); |
| 1867 | if (!FromInit) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1868 | return Error::success(); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1869 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1870 | ExpectedExpr ToInitOrErr = import(FromInit); |
| 1871 | if (!ToInitOrErr) |
| 1872 | return ToInitOrErr.takeError(); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1873 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1874 | To->setInit(*ToInitOrErr); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1875 | if (From->isInitKnownICE()) { |
| 1876 | EvaluatedStmt *Eval = To->ensureEvaluatedStmt(); |
| 1877 | Eval->CheckedICE = true; |
| 1878 | Eval->IsICE = From->isInitICE(); |
| 1879 | } |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1880 | |
| 1881 | // FIXME: Other bits to merge? |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1882 | return Error::success(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1883 | } |
| 1884 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1885 | Error ASTNodeImporter::ImportDefinition( |
| 1886 | EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1887 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1888 | if (Kind == IDK_Everything) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1889 | return ImportDeclContext(From, /*ForceImport=*/true); |
| 1890 | return Error::success(); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1891 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1892 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1893 | To->startDefinition(); |
| 1894 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1895 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 1896 | return Err; |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1897 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1898 | ExpectedType ToTypeOrErr = |
| 1899 | import(Importer.getFromContext().getTypeDeclType(From)); |
| 1900 | if (!ToTypeOrErr) |
| 1901 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1902 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1903 | ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType()); |
| 1904 | if (!ToPromotionTypeOrErr) |
| 1905 | return ToPromotionTypeOrErr.takeError(); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1906 | |
| 1907 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1908 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 1909 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1910 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1911 | // FIXME: we might need to merge the number of positive or negative bits |
| 1912 | // if the enumerator lists don't match. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1913 | To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr, |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1914 | From->getNumPositiveBits(), |
| 1915 | From->getNumNegativeBits()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1916 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1917 | } |
| 1918 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1919 | // FIXME: Remove this, use `import` instead. |
| 1920 | Expected<TemplateParameterList *> ASTNodeImporter::ImportTemplateParameterList( |
| 1921 | TemplateParameterList *Params) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1922 | SmallVector<NamedDecl *, 4> ToParams(Params->size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1923 | if (Error Err = ImportContainerChecked(*Params, ToParams)) |
| 1924 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1925 | |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1926 | Expr *ToRequiresClause; |
| 1927 | if (Expr *const R = Params->getRequiresClause()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1928 | if (Error Err = importInto(ToRequiresClause, R)) |
| 1929 | return std::move(Err); |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1930 | } else { |
| 1931 | ToRequiresClause = nullptr; |
| 1932 | } |
| 1933 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1934 | auto ToTemplateLocOrErr = import(Params->getTemplateLoc()); |
| 1935 | if (!ToTemplateLocOrErr) |
| 1936 | return ToTemplateLocOrErr.takeError(); |
| 1937 | auto ToLAngleLocOrErr = import(Params->getLAngleLoc()); |
| 1938 | if (!ToLAngleLocOrErr) |
| 1939 | return ToLAngleLocOrErr.takeError(); |
| 1940 | auto ToRAngleLocOrErr = import(Params->getRAngleLoc()); |
| 1941 | if (!ToRAngleLocOrErr) |
| 1942 | return ToRAngleLocOrErr.takeError(); |
| 1943 | |
| 1944 | return TemplateParameterList::Create( |
| 1945 | Importer.getToContext(), |
| 1946 | *ToTemplateLocOrErr, |
| 1947 | *ToLAngleLocOrErr, |
| 1948 | ToParams, |
| 1949 | *ToRAngleLocOrErr, |
| 1950 | ToRequiresClause); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1951 | } |
| 1952 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1953 | Error ASTNodeImporter::ImportTemplateArguments( |
| 1954 | const TemplateArgument *FromArgs, unsigned NumFromArgs, |
| 1955 | SmallVectorImpl<TemplateArgument> &ToArgs) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1956 | for (unsigned I = 0; I != NumFromArgs; ++I) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1957 | if (auto ToOrErr = import(FromArgs[I])) |
| 1958 | ToArgs.push_back(*ToOrErr); |
| 1959 | else |
| 1960 | return ToOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1961 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1962 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1963 | return Error::success(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1964 | } |
| 1965 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1966 | // FIXME: Do not forget to remove this and use only 'import'. |
| 1967 | Expected<TemplateArgument> |
| 1968 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { |
| 1969 | return import(From); |
| 1970 | } |
| 1971 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1972 | template <typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1973 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1974 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { |
| 1975 | for (const auto &FromLoc : Container) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1976 | if (auto ToLocOrErr = import(FromLoc)) |
| 1977 | ToTAInfo.addArgument(*ToLocOrErr); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1978 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1979 | return ToLocOrErr.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1980 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1981 | return Error::success(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1982 | } |
| 1983 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1984 | static StructuralEquivalenceKind |
| 1985 | getStructuralEquivalenceKind(const ASTImporter &Importer) { |
| 1986 | return Importer.isMinimalImport() ? StructuralEquivalenceKind::Minimal |
| 1987 | : StructuralEquivalenceKind::Default; |
| 1988 | } |
| 1989 | |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1990 | bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) { |
| 1991 | StructuralEquivalenceContext Ctx( |
| 1992 | Importer.getFromContext(), Importer.getToContext(), |
| 1993 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1994 | false, Complain); |
| 1995 | return Ctx.IsEquivalent(From, To); |
| 1996 | } |
| 1997 | |
| 1998 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1999 | RecordDecl *ToRecord, bool Complain) { |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2000 | // Eliminate a potential failure point where we attempt to re-import |
| 2001 | // something we're trying to import while completing ToRecord. |
| 2002 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); |
| 2003 | if (ToOrigin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2004 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2005 | if (ToOriginRecord) |
| 2006 | ToRecord = ToOriginRecord; |
| 2007 | } |
| 2008 | |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 2009 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2010 | ToRecord->getASTContext(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2011 | Importer.getNonEquivalentDecls(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2012 | getStructuralEquivalenceKind(Importer), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2013 | false, Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2014 | return Ctx.IsEquivalent(FromRecord, ToRecord); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2015 | } |
| 2016 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2017 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 2018 | bool Complain) { |
| 2019 | StructuralEquivalenceContext Ctx( |
| 2020 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2021 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2022 | false, Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2023 | return Ctx.IsEquivalent(FromVar, ToVar); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2024 | } |
| 2025 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2026 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2027 | StructuralEquivalenceContext Ctx( |
| 2028 | Importer.getFromContext(), Importer.getToContext(), |
| 2029 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2030 | return Ctx.IsEquivalent(FromEnum, ToEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2031 | } |
| 2032 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2033 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, |
| 2034 | FunctionTemplateDecl *To) { |
| 2035 | StructuralEquivalenceContext Ctx( |
| 2036 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2037 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2038 | false, false); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2039 | return Ctx.IsEquivalent(From, To); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2040 | } |
| 2041 | |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2042 | bool ASTNodeImporter::IsStructuralMatch(FunctionDecl *From, FunctionDecl *To) { |
| 2043 | StructuralEquivalenceContext Ctx( |
| 2044 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2045 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2046 | false, false); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2047 | return Ctx.IsEquivalent(From, To); |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2048 | } |
| 2049 | |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2050 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2051 | EnumConstantDecl *ToEC) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2052 | const llvm::APSInt &FromVal = FromEC->getInitVal(); |
| 2053 | const llvm::APSInt &ToVal = ToEC->getInitVal(); |
| 2054 | |
| 2055 | return FromVal.isSigned() == ToVal.isSigned() && |
| 2056 | FromVal.getBitWidth() == ToVal.getBitWidth() && |
| 2057 | FromVal == ToVal; |
| 2058 | } |
| 2059 | |
| 2060 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2061 | ClassTemplateDecl *To) { |
| 2062 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2063 | Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2064 | Importer.getNonEquivalentDecls(), |
| 2065 | getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2066 | return Ctx.IsEquivalent(From, To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2067 | } |
| 2068 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2069 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, |
| 2070 | VarTemplateDecl *To) { |
| 2071 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2072 | Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2073 | Importer.getNonEquivalentDecls(), |
| 2074 | getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2075 | return Ctx.IsEquivalent(From, To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2076 | } |
| 2077 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2078 | ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 2079 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2080 | << D->getDeclKindName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2081 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2082 | } |
| 2083 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2084 | ExpectedDecl ASTNodeImporter::VisitImportDecl(ImportDecl *D) { |
| 2085 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 2086 | << D->getDeclKindName(); |
| 2087 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| 2088 | } |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2089 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2090 | ExpectedDecl ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { |
| 2091 | // Import the context of this declaration. |
| 2092 | DeclContext *DC, *LexicalDC; |
| 2093 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 2094 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2095 | |
| 2096 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2097 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2098 | if (!LocOrErr) |
| 2099 | return LocOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2100 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2101 | EmptyDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2102 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2103 | return ToD; |
| 2104 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2105 | ToD->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2106 | LexicalDC->addDeclInternal(ToD); |
| 2107 | return ToD; |
| 2108 | } |
| 2109 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2110 | ExpectedDecl ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2111 | TranslationUnitDecl *ToD = |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2112 | Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2113 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2114 | Importer.MapImported(D, ToD); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2115 | |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2116 | return ToD; |
| 2117 | } |
| 2118 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2119 | ExpectedDecl ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
| 2120 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2121 | if (!LocOrErr) |
| 2122 | return LocOrErr.takeError(); |
| 2123 | auto ColonLocOrErr = import(D->getColonLoc()); |
| 2124 | if (!ColonLocOrErr) |
| 2125 | return ColonLocOrErr.takeError(); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2126 | |
| 2127 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2128 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2129 | if (!DCOrErr) |
| 2130 | return DCOrErr.takeError(); |
| 2131 | DeclContext *DC = *DCOrErr; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2132 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2133 | AccessSpecDecl *ToD; |
| 2134 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2135 | DC, *LocOrErr, *ColonLocOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2136 | return ToD; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2137 | |
| 2138 | // Lexical DeclContext and Semantic DeclContext |
| 2139 | // is always the same for the accessSpec. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2140 | ToD->setLexicalDeclContext(DC); |
| 2141 | DC->addDeclInternal(ToD); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2142 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2143 | return ToD; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2144 | } |
| 2145 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2146 | ExpectedDecl ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 2147 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2148 | if (!DCOrErr) |
| 2149 | return DCOrErr.takeError(); |
| 2150 | DeclContext *DC = *DCOrErr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2151 | DeclContext *LexicalDC = DC; |
| 2152 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2153 | SourceLocation ToLocation, ToRParenLoc; |
| 2154 | Expr *ToAssertExpr; |
| 2155 | StringLiteral *ToMessage; |
| 2156 | if (auto Imp = importSeq( |
| 2157 | D->getLocation(), D->getAssertExpr(), D->getMessage(), D->getRParenLoc())) |
| 2158 | std::tie(ToLocation, ToAssertExpr, ToMessage, ToRParenLoc) = *Imp; |
| 2159 | else |
| 2160 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2161 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2162 | StaticAssertDecl *ToD; |
| 2163 | if (GetImportedOrCreateDecl( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2164 | ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage, |
| 2165 | ToRParenLoc, D->isFailed())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2166 | return ToD; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2167 | |
| 2168 | ToD->setLexicalDeclContext(LexicalDC); |
| 2169 | LexicalDC->addDeclInternal(ToD); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2170 | return ToD; |
| 2171 | } |
| 2172 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2173 | ExpectedDecl ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2174 | // Import the major distinguishing characteristics of this namespace. |
| 2175 | DeclContext *DC, *LexicalDC; |
| 2176 | DeclarationName Name; |
| 2177 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2178 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2179 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2180 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2181 | if (ToD) |
| 2182 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2183 | |
| 2184 | NamespaceDecl *MergeWithNamespace = nullptr; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2185 | if (!Name) { |
| 2186 | // This is an anonymous namespace. Adopt an existing anonymous |
| 2187 | // namespace if we can. |
| 2188 | // FIXME: Not testable. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2189 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2190 | MergeWithNamespace = TU->getAnonymousNamespace(); |
| 2191 | else |
| 2192 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); |
| 2193 | } else { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2194 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2195 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2196 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2197 | for (auto *FoundDecl : FoundDecls) { |
| 2198 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2199 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2200 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2201 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2202 | MergeWithNamespace = FoundNS; |
| 2203 | ConflictingDecls.clear(); |
| 2204 | break; |
| 2205 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2206 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2207 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2208 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2209 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2210 | if (!ConflictingDecls.empty()) { |
John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 2211 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2212 | ConflictingDecls.data(), |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2213 | ConflictingDecls.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2214 | if (!Name) |
| 2215 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2216 | } |
| 2217 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2218 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2219 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2220 | if (!BeginLocOrErr) |
| 2221 | return BeginLocOrErr.takeError(); |
| 2222 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2223 | // Create the "to" namespace, if needed. |
| 2224 | NamespaceDecl *ToNamespace = MergeWithNamespace; |
| 2225 | if (!ToNamespace) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2226 | if (GetImportedOrCreateDecl( |
| 2227 | ToNamespace, D, Importer.getToContext(), DC, D->isInline(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2228 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2229 | /*PrevDecl=*/nullptr)) |
| 2230 | return ToNamespace; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2231 | ToNamespace->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2232 | LexicalDC->addDeclInternal(ToNamespace); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2233 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2234 | // If this is an anonymous namespace, register it as the anonymous |
| 2235 | // namespace within its context. |
| 2236 | if (!Name) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2237 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2238 | TU->setAnonymousNamespace(ToNamespace); |
| 2239 | else |
| 2240 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); |
| 2241 | } |
| 2242 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2243 | Importer.MapImported(D, ToNamespace); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2244 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2245 | if (Error Err = ImportDeclContext(D)) |
| 2246 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2247 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2248 | return ToNamespace; |
| 2249 | } |
| 2250 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2251 | ExpectedDecl ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2252 | // Import the major distinguishing characteristics of this namespace. |
| 2253 | DeclContext *DC, *LexicalDC; |
| 2254 | DeclarationName Name; |
| 2255 | SourceLocation Loc; |
| 2256 | NamedDecl *LookupD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2257 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) |
| 2258 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2259 | if (LookupD) |
| 2260 | return LookupD; |
| 2261 | |
| 2262 | // NOTE: No conflict resolution is done for namespace aliases now. |
| 2263 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2264 | SourceLocation ToNamespaceLoc, ToAliasLoc, ToTargetNameLoc; |
| 2265 | NestedNameSpecifierLoc ToQualifierLoc; |
| 2266 | NamespaceDecl *ToNamespace; |
| 2267 | if (auto Imp = importSeq( |
| 2268 | D->getNamespaceLoc(), D->getAliasLoc(), D->getQualifierLoc(), |
| 2269 | D->getTargetNameLoc(), D->getNamespace())) |
| 2270 | std::tie( |
| 2271 | ToNamespaceLoc, ToAliasLoc, ToQualifierLoc, ToTargetNameLoc, |
| 2272 | ToNamespace) = *Imp; |
| 2273 | else |
| 2274 | return Imp.takeError(); |
| 2275 | IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier()); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2276 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2277 | NamespaceAliasDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2278 | if (GetImportedOrCreateDecl( |
| 2279 | ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc, |
| 2280 | ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2281 | return ToD; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2282 | |
| 2283 | ToD->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2284 | LexicalDC->addDeclInternal(ToD); |
| 2285 | |
| 2286 | return ToD; |
| 2287 | } |
| 2288 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2289 | ExpectedDecl |
| 2290 | ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2291 | // Import the major distinguishing characteristics of this typedef. |
| 2292 | DeclContext *DC, *LexicalDC; |
| 2293 | DeclarationName Name; |
| 2294 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2295 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2296 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2297 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2298 | if (ToD) |
| 2299 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2300 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2301 | // If this typedef is not in block scope, determine whether we've |
| 2302 | // seen a typedef with the same name (that we can merge with) or any |
| 2303 | // other entity by that name (which name lookup could conflict with). |
| 2304 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2305 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2306 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2307 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2308 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2309 | for (auto *FoundDecl : FoundDecls) { |
| 2310 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2311 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2312 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2313 | if (Importer.IsStructurallyEquivalent( |
| 2314 | D->getUnderlyingType(), FoundTypedef->getUnderlyingType())) |
| 2315 | return Importer.MapImported(D, FoundTypedef); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2316 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2317 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2318 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2319 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2320 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2321 | if (!ConflictingDecls.empty()) { |
| 2322 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2323 | ConflictingDecls.data(), |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2324 | ConflictingDecls.size()); |
| 2325 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2326 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2327 | } |
| 2328 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2329 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2330 | QualType ToUnderlyingType; |
| 2331 | TypeSourceInfo *ToTypeSourceInfo; |
| 2332 | SourceLocation ToBeginLoc; |
| 2333 | if (auto Imp = importSeq( |
| 2334 | D->getUnderlyingType(), D->getTypeSourceInfo(), D->getBeginLoc())) |
| 2335 | std::tie(ToUnderlyingType, ToTypeSourceInfo, ToBeginLoc) = *Imp; |
| 2336 | else |
| 2337 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2338 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2339 | // Create the new typedef node. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2340 | // FIXME: ToUnderlyingType is not used. |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2341 | TypedefNameDecl *ToTypedef; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2342 | if (IsAlias) { |
| 2343 | if (GetImportedOrCreateDecl<TypeAliasDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2344 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2345 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2346 | return ToTypedef; |
| 2347 | } else if (GetImportedOrCreateDecl<TypedefDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2348 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2349 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2350 | return ToTypedef; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2351 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2352 | ToTypedef->setAccess(D->getAccess()); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2353 | ToTypedef->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2354 | |
| 2355 | // Templated declarations should not appear in DeclContext. |
| 2356 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; |
| 2357 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) |
| 2358 | LexicalDC->addDeclInternal(ToTypedef); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2359 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2360 | return ToTypedef; |
| 2361 | } |
| 2362 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2363 | ExpectedDecl ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2364 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); |
| 2365 | } |
| 2366 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2367 | ExpectedDecl ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2368 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); |
| 2369 | } |
| 2370 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2371 | ExpectedDecl |
| 2372 | ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2373 | // Import the major distinguishing characteristics of this typedef. |
| 2374 | DeclContext *DC, *LexicalDC; |
| 2375 | DeclarationName Name; |
| 2376 | SourceLocation Loc; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2377 | NamedDecl *FoundD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2378 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) |
| 2379 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2380 | if (FoundD) |
| 2381 | return FoundD; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2382 | |
| 2383 | // If this typedef is not in block scope, determine whether we've |
| 2384 | // seen a typedef with the same name (that we can merge with) or any |
| 2385 | // other entity by that name (which name lookup could conflict with). |
| 2386 | if (!DC->isFunctionOrMethod()) { |
| 2387 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 2388 | unsigned IDNS = Decl::IDNS_Ordinary; |
| 2389 | SmallVector<NamedDecl *, 2> FoundDecls; |
| 2390 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2391 | for (auto *FoundDecl : FoundDecls) { |
| 2392 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2393 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2394 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2395 | return Importer.MapImported(D, FoundAlias); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2396 | ConflictingDecls.push_back(FoundDecl); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2397 | } |
| 2398 | |
| 2399 | if (!ConflictingDecls.empty()) { |
| 2400 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2401 | ConflictingDecls.data(), |
| 2402 | ConflictingDecls.size()); |
| 2403 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2404 | return make_error<ImportError>(ImportError::NameConflict); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2405 | } |
| 2406 | } |
| 2407 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2408 | TemplateParameterList *ToTemplateParameters; |
| 2409 | TypeAliasDecl *ToTemplatedDecl; |
| 2410 | if (auto Imp = importSeq(D->getTemplateParameters(), D->getTemplatedDecl())) |
| 2411 | std::tie(ToTemplateParameters, ToTemplatedDecl) = *Imp; |
| 2412 | else |
| 2413 | return Imp.takeError(); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2414 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2415 | TypeAliasTemplateDecl *ToAlias; |
| 2416 | if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2417 | Name, ToTemplateParameters, ToTemplatedDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2418 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2419 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2420 | ToTemplatedDecl->setDescribedAliasTemplate(ToAlias); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2421 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2422 | ToAlias->setAccess(D->getAccess()); |
| 2423 | ToAlias->setLexicalDeclContext(LexicalDC); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2424 | LexicalDC->addDeclInternal(ToAlias); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2425 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2426 | } |
| 2427 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2428 | ExpectedDecl ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2429 | // Import the major distinguishing characteristics of this label. |
| 2430 | DeclContext *DC, *LexicalDC; |
| 2431 | DeclarationName Name; |
| 2432 | SourceLocation Loc; |
| 2433 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2434 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2435 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2436 | if (ToD) |
| 2437 | return ToD; |
| 2438 | |
| 2439 | assert(LexicalDC->isFunctionOrMethod()); |
| 2440 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2441 | LabelDecl *ToLabel; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2442 | if (D->isGnuLocal()) { |
| 2443 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2444 | if (!BeginLocOrErr) |
| 2445 | return BeginLocOrErr.takeError(); |
| 2446 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2447 | Name.getAsIdentifierInfo(), *BeginLocOrErr)) |
| 2448 | return ToLabel; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2449 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2450 | } else { |
| 2451 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2452 | Name.getAsIdentifierInfo())) |
| 2453 | return ToLabel; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2454 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2455 | } |
| 2456 | |
| 2457 | Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt()); |
| 2458 | if (!ToStmtOrErr) |
| 2459 | return ToStmtOrErr.takeError(); |
| 2460 | |
| 2461 | ToLabel->setStmt(*ToStmtOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2462 | ToLabel->setLexicalDeclContext(LexicalDC); |
| 2463 | LexicalDC->addDeclInternal(ToLabel); |
| 2464 | return ToLabel; |
| 2465 | } |
| 2466 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2467 | ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2468 | // Import the major distinguishing characteristics of this enum. |
| 2469 | DeclContext *DC, *LexicalDC; |
| 2470 | DeclarationName Name; |
| 2471 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2472 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2473 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2474 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2475 | if (ToD) |
| 2476 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2477 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2478 | // Figure out what enum name we're looking for. |
| 2479 | unsigned IDNS = Decl::IDNS_Tag; |
| 2480 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2481 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2482 | if (Error Err = importInto( |
| 2483 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2484 | return std::move(Err); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2485 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2486 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2487 | IDNS |= Decl::IDNS_Ordinary; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2488 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2489 | // We may already have an enum of the same name; try to find and match it. |
| 2490 | if (!DC->isFunctionOrMethod() && SearchName) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2491 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2492 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 2493 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2494 | for (auto *FoundDecl : FoundDecls) { |
| 2495 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2496 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2497 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2498 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2499 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2500 | FoundDecl = Tag->getDecl(); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2501 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2502 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2503 | if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) { |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2504 | if (IsStructuralMatch(D, FoundEnum)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2505 | return Importer.MapImported(D, FoundEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2506 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2507 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2508 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2509 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2510 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2511 | if (!ConflictingDecls.empty()) { |
| 2512 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2513 | ConflictingDecls.data(), |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2514 | ConflictingDecls.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2515 | if (!Name) |
| 2516 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2517 | } |
| 2518 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2519 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2520 | SourceLocation ToBeginLoc; |
| 2521 | NestedNameSpecifierLoc ToQualifierLoc; |
| 2522 | QualType ToIntegerType; |
| 2523 | if (auto Imp = importSeq( |
| 2524 | D->getBeginLoc(), D->getQualifierLoc(), D->getIntegerType())) |
| 2525 | std::tie(ToBeginLoc, ToQualifierLoc, ToIntegerType) = *Imp; |
| 2526 | else |
| 2527 | return Imp.takeError(); |
| 2528 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2529 | // Create the enum declaration. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2530 | EnumDecl *D2; |
| 2531 | if (GetImportedOrCreateDecl( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2532 | D2, D, Importer.getToContext(), DC, ToBeginLoc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2533 | Loc, Name.getAsIdentifierInfo(), nullptr, D->isScoped(), |
| 2534 | D->isScopedUsingClassTag(), D->isFixed())) |
| 2535 | return D2; |
| 2536 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2537 | D2->setQualifierInfo(ToQualifierLoc); |
| 2538 | D2->setIntegerType(ToIntegerType); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2539 | D2->setAccess(D->getAccess()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2540 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2541 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2542 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2543 | // Import the definition |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2544 | if (D->isCompleteDefinition()) |
| 2545 | if (Error Err = ImportDefinition(D, D2)) |
| 2546 | return std::move(Err); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2547 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2548 | return D2; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2549 | } |
| 2550 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2551 | ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2552 | bool IsFriendTemplate = false; |
| 2553 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2554 | IsFriendTemplate = |
| 2555 | DCXX->getDescribedClassTemplate() && |
| 2556 | DCXX->getDescribedClassTemplate()->getFriendObjectKind() != |
| 2557 | Decl::FOK_None; |
| 2558 | } |
| 2559 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2560 | // If this record has a definition in the translation unit we're coming from, |
| 2561 | // but this particular declaration is not that definition, import the |
| 2562 | // definition and map to that. |
Douglas Gregor | 0a5a221 | 2010-02-11 01:04:33 +0000 | [diff] [blame] | 2563 | TagDecl *Definition = D->getDefinition(); |
Gabor Marton | a3af567 | 2018-05-23 14:24:02 +0000 | [diff] [blame] | 2564 | if (Definition && Definition != D && |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2565 | // Friend template declaration must be imported on its own. |
| 2566 | !IsFriendTemplate && |
Gabor Marton | a3af567 | 2018-05-23 14:24:02 +0000 | [diff] [blame] | 2567 | // In contrast to a normal CXXRecordDecl, the implicit |
| 2568 | // CXXRecordDecl of ClassTemplateSpecializationDecl is its redeclaration. |
| 2569 | // The definition of the implicit CXXRecordDecl in this case is the |
| 2570 | // ClassTemplateSpecializationDecl itself. Thus, we start with an extra |
| 2571 | // condition in order to be able to import the implict Decl. |
| 2572 | !D->isImplicit()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2573 | ExpectedDecl ImportedDefOrErr = import(Definition); |
| 2574 | if (!ImportedDefOrErr) |
| 2575 | return ImportedDefOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2576 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2577 | return Importer.MapImported(D, *ImportedDefOrErr); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2578 | } |
Gabor Marton | a3af567 | 2018-05-23 14:24:02 +0000 | [diff] [blame] | 2579 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2580 | // Import the major distinguishing characteristics of this record. |
| 2581 | DeclContext *DC, *LexicalDC; |
| 2582 | DeclarationName Name; |
| 2583 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2584 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2585 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2586 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2587 | if (ToD) |
| 2588 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2589 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2590 | // Figure out what structure name we're looking for. |
| 2591 | unsigned IDNS = Decl::IDNS_Tag; |
| 2592 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2593 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2594 | if (Error Err = importInto( |
| 2595 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2596 | return std::move(Err); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2597 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2598 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2599 | IDNS |= Decl::IDNS_Ordinary; |
| 2600 | |
| 2601 | // 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] | 2602 | RecordDecl *AdoptDecl = nullptr; |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2603 | RecordDecl *PrevDecl = nullptr; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2604 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2605 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2606 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 2607 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2608 | |
| 2609 | if (!FoundDecls.empty()) { |
| 2610 | // We're going to have to compare D against potentially conflicting Decls, so complete it. |
| 2611 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) |
| 2612 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 2613 | } |
| 2614 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2615 | for (auto *FoundDecl : FoundDecls) { |
| 2616 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2617 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2618 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2619 | Decl *Found = FoundDecl; |
| 2620 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 2621 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2622 | Found = Tag->getDecl(); |
| 2623 | } |
Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2624 | |
| 2625 | if (D->getDescribedTemplate()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2626 | if (auto *Template = dyn_cast<ClassTemplateDecl>(Found)) { |
Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2627 | Found = Template->getTemplatedDecl(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2628 | } else { |
| 2629 | ConflictingDecls.push_back(FoundDecl); |
Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2630 | continue; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2631 | } |
Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2632 | } |
| 2633 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2634 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { |
Aleksei Sidorin | 499de6c | 2018-04-05 15:31:49 +0000 | [diff] [blame] | 2635 | if (!SearchName) { |
Gabor Marton | 0bebf95 | 2018-07-05 09:51:13 +0000 | [diff] [blame] | 2636 | if (!IsStructuralMatch(D, FoundRecord, false)) |
| 2637 | continue; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2638 | } else { |
| 2639 | if (!IsStructuralMatch(D, FoundRecord)) { |
| 2640 | ConflictingDecls.push_back(FoundDecl); |
| 2641 | continue; |
| 2642 | } |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2643 | } |
| 2644 | |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2645 | PrevDecl = FoundRecord; |
| 2646 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2647 | if (RecordDecl *FoundDef = FoundRecord->getDefinition()) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2648 | if ((SearchName && !D->isCompleteDefinition() && !IsFriendTemplate) |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2649 | || (D->isCompleteDefinition() && |
| 2650 | D->isAnonymousStructOrUnion() |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2651 | == FoundDef->isAnonymousStructOrUnion())) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2652 | // The record types structurally match, or the "from" translation |
| 2653 | // unit only had a forward declaration anyway; call it the same |
| 2654 | // function. |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2655 | // FIXME: Structural equivalence check should check for same |
| 2656 | // user-defined methods. |
| 2657 | Importer.MapImported(D, FoundDef); |
| 2658 | if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2659 | auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef); |
| 2660 | assert(FoundCXX && "Record type mismatch"); |
| 2661 | |
| 2662 | if (D->isCompleteDefinition() && !Importer.isMinimalImport()) |
| 2663 | // FoundDef may not have every implicit method that D has |
| 2664 | // because implicit methods are created only if they are used. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2665 | if (Error Err = ImportImplicitMethods(DCXX, FoundCXX)) |
| 2666 | return std::move(Err); |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2667 | } |
| 2668 | return FoundDef; |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2669 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2670 | if (IsFriendTemplate) |
| 2671 | continue; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2672 | } else if (!D->isCompleteDefinition()) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2673 | // We have a forward declaration of this type, so adopt that forward |
| 2674 | // declaration rather than building a new one. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2675 | |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 2676 | // If one or both can be completed from external storage then try one |
| 2677 | // last time to complete and compare them before doing this. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2678 | |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 2679 | if (FoundRecord->hasExternalLexicalStorage() && |
| 2680 | !FoundRecord->isCompleteDefinition()) |
| 2681 | FoundRecord->getASTContext().getExternalSource()->CompleteType(FoundRecord); |
| 2682 | if (D->hasExternalLexicalStorage()) |
| 2683 | D->getASTContext().getExternalSource()->CompleteType(D); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2684 | |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 2685 | if (FoundRecord->isCompleteDefinition() && |
| 2686 | D->isCompleteDefinition() && |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2687 | !IsStructuralMatch(D, FoundRecord)) { |
| 2688 | ConflictingDecls.push_back(FoundDecl); |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 2689 | continue; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2690 | } |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2691 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2692 | AdoptDecl = FoundRecord; |
| 2693 | continue; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2694 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2695 | |
| 2696 | continue; |
| 2697 | } else if (isa<ValueDecl>(Found)) |
| 2698 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2699 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2700 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2701 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2702 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2703 | if (!ConflictingDecls.empty() && SearchName) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2704 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2705 | ConflictingDecls.data(), |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2706 | ConflictingDecls.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2707 | if (!Name) |
| 2708 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2709 | } |
| 2710 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2711 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2712 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2713 | if (!BeginLocOrErr) |
| 2714 | return BeginLocOrErr.takeError(); |
| 2715 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2716 | // Create the record declaration. |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2717 | RecordDecl *D2 = AdoptDecl; |
| 2718 | if (!D2) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2719 | CXXRecordDecl *D2CXX = nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2720 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2721 | if (DCXX->isLambda()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2722 | auto TInfoOrErr = import(DCXX->getLambdaTypeInfo()); |
| 2723 | if (!TInfoOrErr) |
| 2724 | return TInfoOrErr.takeError(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2725 | if (GetImportedOrCreateSpecialDecl( |
| 2726 | D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2727 | DC, *TInfoOrErr, Loc, DCXX->isDependentLambda(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2728 | DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault())) |
| 2729 | return D2CXX; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2730 | ExpectedDecl CDeclOrErr = import(DCXX->getLambdaContextDecl()); |
| 2731 | if (!CDeclOrErr) |
| 2732 | return CDeclOrErr.takeError(); |
| 2733 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), *CDeclOrErr); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2734 | } else if (DCXX->isInjectedClassName()) { |
| 2735 | // We have to be careful to do a similar dance to the one in |
| 2736 | // Sema::ActOnStartCXXMemberDeclarations |
| 2737 | CXXRecordDecl *const PrevDecl = nullptr; |
| 2738 | const bool DelayTypeCreation = true; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2739 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2740 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2741 | Name.getAsIdentifierInfo(), PrevDecl, |
| 2742 | DelayTypeCreation)) |
| 2743 | return D2CXX; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2744 | Importer.getToContext().getTypeDeclType( |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2745 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2746 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2747 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2748 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2749 | Name.getAsIdentifierInfo(), |
| 2750 | cast_or_null<CXXRecordDecl>(PrevDecl))) |
| 2751 | return D2CXX; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2752 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2753 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2754 | D2 = D2CXX; |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2755 | D2->setAccess(D->getAccess()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2756 | D2->setLexicalDeclContext(LexicalDC); |
Gabor Marton | de8bf26 | 2018-05-17 09:46:07 +0000 | [diff] [blame] | 2757 | if (!DCXX->getDescribedClassTemplate() || DCXX->isImplicit()) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2758 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2759 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2760 | if (ClassTemplateDecl *FromDescribed = |
| 2761 | DCXX->getDescribedClassTemplate()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2762 | ClassTemplateDecl *ToDescribed; |
| 2763 | if (Error Err = importInto(ToDescribed, FromDescribed)) |
| 2764 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2765 | D2CXX->setDescribedClassTemplate(ToDescribed); |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2766 | if (!DCXX->isInjectedClassName() && !IsFriendTemplate) { |
Gabor Marton | 5915777e | 2018-06-26 13:44:24 +0000 | [diff] [blame] | 2767 | // In a record describing a template the type should be an |
| 2768 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the |
| 2769 | // previously set type to the correct value here (ToDescribed is not |
| 2770 | // available at record create). |
| 2771 | // FIXME: The previous type is cleared but not removed from |
| 2772 | // ASTContext's internal storage. |
| 2773 | CXXRecordDecl *Injected = nullptr; |
| 2774 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { |
| 2775 | auto *Record = dyn_cast<CXXRecordDecl>(Found); |
| 2776 | if (Record && Record->isInjectedClassName()) { |
| 2777 | Injected = Record; |
| 2778 | break; |
| 2779 | } |
| 2780 | } |
| 2781 | D2CXX->setTypeForDecl(nullptr); |
| 2782 | Importer.getToContext().getInjectedClassNameType(D2CXX, |
| 2783 | ToDescribed->getInjectedClassNameSpecialization()); |
| 2784 | if (Injected) { |
| 2785 | Injected->setTypeForDecl(nullptr); |
| 2786 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); |
| 2787 | } |
| 2788 | } |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2789 | } else if (MemberSpecializationInfo *MemberInfo = |
| 2790 | DCXX->getMemberSpecializationInfo()) { |
| 2791 | TemplateSpecializationKind SK = |
| 2792 | MemberInfo->getTemplateSpecializationKind(); |
| 2793 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2794 | |
| 2795 | if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst)) |
| 2796 | D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK); |
| 2797 | else |
| 2798 | return ToInstOrErr.takeError(); |
| 2799 | |
| 2800 | if (ExpectedSLoc POIOrErr = |
| 2801 | import(MemberInfo->getPointOfInstantiation())) |
| 2802 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( |
| 2803 | *POIOrErr); |
| 2804 | else |
| 2805 | return POIOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2806 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2807 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2808 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2809 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2810 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2811 | Name.getAsIdentifierInfo(), PrevDecl)) |
| 2812 | return D2; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2813 | D2->setLexicalDeclContext(LexicalDC); |
| 2814 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2815 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2816 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2817 | if (auto QualifierLocOrErr = import(D->getQualifierLoc())) |
| 2818 | D2->setQualifierInfo(*QualifierLocOrErr); |
| 2819 | else |
| 2820 | return QualifierLocOrErr.takeError(); |
| 2821 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2822 | if (D->isAnonymousStructOrUnion()) |
| 2823 | D2->setAnonymousStructOrUnion(true); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2824 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2825 | |
| 2826 | Importer.MapImported(D, D2); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2827 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2828 | if (D->isCompleteDefinition()) |
| 2829 | if (Error Err = ImportDefinition(D, D2, IDK_Default)) |
| 2830 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2831 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2832 | return D2; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2833 | } |
| 2834 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2835 | ExpectedDecl ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2836 | // Import the major distinguishing characteristics of this enumerator. |
| 2837 | DeclContext *DC, *LexicalDC; |
| 2838 | DeclarationName Name; |
| 2839 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2840 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2841 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2842 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2843 | if (ToD) |
| 2844 | return ToD; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2845 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2846 | // Determine whether there are any other declarations with the same name and |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2847 | // in the same context. |
| 2848 | if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2849 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2850 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2851 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2852 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2853 | for (auto *FoundDecl : FoundDecls) { |
| 2854 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2855 | continue; |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2856 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2857 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2858 | if (IsStructuralMatch(D, FoundEnumConstant)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2859 | return Importer.MapImported(D, FoundEnumConstant); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2860 | } |
| 2861 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2862 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2863 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2864 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2865 | if (!ConflictingDecls.empty()) { |
| 2866 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2867 | ConflictingDecls.data(), |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2868 | ConflictingDecls.size()); |
| 2869 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2870 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2871 | } |
| 2872 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2873 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2874 | ExpectedType TypeOrErr = import(D->getType()); |
| 2875 | if (!TypeOrErr) |
| 2876 | return TypeOrErr.takeError(); |
| 2877 | |
| 2878 | ExpectedExpr InitOrErr = import(D->getInitExpr()); |
| 2879 | if (!InitOrErr) |
| 2880 | return InitOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2881 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2882 | EnumConstantDecl *ToEnumerator; |
| 2883 | if (GetImportedOrCreateDecl( |
| 2884 | ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2885 | Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2886 | return ToEnumerator; |
| 2887 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2888 | ToEnumerator->setAccess(D->getAccess()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2889 | ToEnumerator->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2890 | LexicalDC->addDeclInternal(ToEnumerator); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2891 | return ToEnumerator; |
| 2892 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2893 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2894 | Error ASTNodeImporter::ImportTemplateInformation( |
| 2895 | FunctionDecl *FromFD, FunctionDecl *ToFD) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2896 | switch (FromFD->getTemplatedKind()) { |
| 2897 | case FunctionDecl::TK_NonTemplate: |
| 2898 | case FunctionDecl::TK_FunctionTemplate: |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2899 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2900 | |
| 2901 | case FunctionDecl::TK_MemberSpecialization: { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2902 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2903 | |
| 2904 | if (Expected<FunctionDecl *> InstFDOrErr = |
| 2905 | import(FromFD->getInstantiatedFromMemberFunction())) |
| 2906 | ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK); |
| 2907 | else |
| 2908 | return InstFDOrErr.takeError(); |
| 2909 | |
| 2910 | if (ExpectedSLoc POIOrErr = import( |
| 2911 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation())) |
| 2912 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr); |
| 2913 | else |
| 2914 | return POIOrErr.takeError(); |
| 2915 | |
| 2916 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2917 | } |
| 2918 | |
| 2919 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2920 | auto FunctionAndArgsOrErr = |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2921 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2922 | if (!FunctionAndArgsOrErr) |
| 2923 | return FunctionAndArgsOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2924 | |
| 2925 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2926 | Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr)); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2927 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2928 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2929 | TemplateArgumentListInfo ToTAInfo; |
| 2930 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2931 | if (FromTAArgsAsWritten) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2932 | if (Error Err = ImportTemplateArgumentListInfo( |
| 2933 | *FromTAArgsAsWritten, ToTAInfo)) |
| 2934 | return Err; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2935 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2936 | ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation()); |
| 2937 | if (!POIOrErr) |
| 2938 | return POIOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2939 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2940 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2941 | ToFD->setFunctionTemplateSpecialization( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2942 | std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr, |
| 2943 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr); |
| 2944 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2945 | } |
| 2946 | |
| 2947 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 2948 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); |
| 2949 | UnresolvedSet<8> TemplDecls; |
| 2950 | unsigned NumTemplates = FromInfo->getNumTemplates(); |
| 2951 | for (unsigned I = 0; I < NumTemplates; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2952 | if (Expected<FunctionTemplateDecl *> ToFTDOrErr = |
| 2953 | import(FromInfo->getTemplate(I))) |
| 2954 | TemplDecls.addDecl(*ToFTDOrErr); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2955 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2956 | return ToFTDOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2957 | } |
| 2958 | |
| 2959 | // Import TemplateArgumentListInfo. |
| 2960 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2961 | if (Error Err = ImportTemplateArgumentListInfo( |
| 2962 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), |
| 2963 | llvm::makeArrayRef( |
| 2964 | FromInfo->getTemplateArgs(), FromInfo->getNumTemplateArgs()), |
| 2965 | ToTAInfo)) |
| 2966 | return Err; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2967 | |
| 2968 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), |
| 2969 | TemplDecls, ToTAInfo); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2970 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2971 | } |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2972 | } |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2973 | llvm_unreachable("All cases should be covered!"); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2974 | } |
| 2975 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2976 | Expected<FunctionDecl *> |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2977 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2978 | auto FunctionAndArgsOrErr = |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2979 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2980 | if (!FunctionAndArgsOrErr) |
| 2981 | return FunctionAndArgsOrErr.takeError(); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2982 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2983 | FunctionTemplateDecl *Template; |
| 2984 | TemplateArgsTy ToTemplArgs; |
| 2985 | std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2986 | void *InsertPos = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2987 | auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2988 | return FoundSpec; |
| 2989 | } |
| 2990 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2991 | ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2992 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2993 | SmallVector<Decl *, 2> Redecls = getCanonicalForwardRedeclChain(D); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2994 | auto RedeclIt = Redecls.begin(); |
| 2995 | // Import the first part of the decl chain. I.e. import all previous |
| 2996 | // declarations starting from the canonical decl. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2997 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 2998 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 2999 | if (!ToRedeclOrErr) |
| 3000 | return ToRedeclOrErr.takeError(); |
| 3001 | } |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3002 | assert(*RedeclIt == D); |
| 3003 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3004 | // Import the major distinguishing characteristics of this function. |
| 3005 | DeclContext *DC, *LexicalDC; |
| 3006 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3007 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3008 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3009 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3010 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3011 | if (ToD) |
| 3012 | return ToD; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3013 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3014 | const FunctionDecl *FoundByLookup = nullptr; |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3015 | FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 3016 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3017 | // If this is a function template specialization, then try to find the same |
| 3018 | // existing specialization in the "to" context. The localUncachedLookup |
| 3019 | // below will not find any specialization, but would find the primary |
| 3020 | // template; thus, we have to skip normal lookup in case of specializations. |
| 3021 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? |
| 3022 | if (D->getTemplatedKind() == |
| 3023 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3024 | auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D); |
| 3025 | if (!FoundFunctionOrErr) |
| 3026 | return FoundFunctionOrErr.takeError(); |
| 3027 | if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) { |
| 3028 | if (D->doesThisDeclarationHaveABody() && FoundFunction->hasBody()) |
| 3029 | return Importer.MapImported(D, FoundFunction); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3030 | FoundByLookup = FoundFunction; |
| 3031 | } |
| 3032 | } |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3033 | // Try to find a function in our own ("to") context with the same name, same |
| 3034 | // type, and in the same context as the function we're importing. |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3035 | else if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3036 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3037 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3038 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3039 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3040 | for (auto *FoundDecl : FoundDecls) { |
| 3041 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3042 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3043 | |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3044 | // If template was found, look at the templated function. |
| 3045 | if (FromFT) { |
| 3046 | if (auto *Template = dyn_cast<FunctionTemplateDecl>(FoundDecl)) |
| 3047 | FoundDecl = Template->getTemplatedDecl(); |
| 3048 | else |
| 3049 | continue; |
| 3050 | } |
| 3051 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3052 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { |
Rafael Espindola | 3ae0005 | 2013-05-13 00:12:11 +0000 | [diff] [blame] | 3053 | if (FoundFunction->hasExternalFormalLinkage() && |
| 3054 | D->hasExternalFormalLinkage()) { |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 3055 | if (IsStructuralMatch(D, FoundFunction)) { |
| 3056 | const FunctionDecl *Definition = nullptr; |
| 3057 | if (D->doesThisDeclarationHaveABody() && |
| 3058 | FoundFunction->hasBody(Definition)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3059 | return Importer.MapImported( |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 3060 | D, const_cast<FunctionDecl *>(Definition)); |
| 3061 | } |
| 3062 | FoundByLookup = FoundFunction; |
| 3063 | break; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3064 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3065 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3066 | // FIXME: Check for overloading more carefully, e.g., by boosting |
| 3067 | // Sema::IsOverload out to the AST library. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3068 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3069 | // Function overloading is okay in C++. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3070 | if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3071 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3072 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3073 | // Complain about inconsistent function types. |
| 3074 | Importer.ToDiag(Loc, diag::err_odr_function_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3075 | << Name << D->getType() << FoundFunction->getType(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3076 | Importer.ToDiag(FoundFunction->getLocation(), |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3077 | diag::note_odr_value_here) |
| 3078 | << FoundFunction->getType(); |
| 3079 | } |
| 3080 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3081 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3082 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3083 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3084 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3085 | if (!ConflictingDecls.empty()) { |
| 3086 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3087 | ConflictingDecls.data(), |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3088 | ConflictingDecls.size()); |
| 3089 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3090 | return make_error<ImportError>(ImportError::NameConflict); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3091 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3092 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3093 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3094 | DeclarationNameInfo NameInfo(Name, Loc); |
| 3095 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3096 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 3097 | return std::move(Err); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3098 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3099 | QualType FromTy = D->getType(); |
| 3100 | bool usedDifferentExceptionSpec = false; |
| 3101 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3102 | if (const auto *FromFPT = D->getType()->getAs<FunctionProtoType>()) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3103 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); |
| 3104 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the |
| 3105 | // FunctionDecl that we are importing the FunctionProtoType for. |
| 3106 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| 3107 | // with a simplified function type and update it afterwards. |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 3108 | if (FromEPI.ExceptionSpec.SourceDecl || |
| 3109 | FromEPI.ExceptionSpec.SourceTemplate || |
| 3110 | FromEPI.ExceptionSpec.NoexceptExpr) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3111 | FunctionProtoType::ExtProtoInfo DefaultEPI; |
| 3112 | FromTy = Importer.getFromContext().getFunctionType( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3113 | FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI); |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3114 | usedDifferentExceptionSpec = true; |
| 3115 | } |
| 3116 | } |
| 3117 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3118 | QualType T; |
| 3119 | TypeSourceInfo *TInfo; |
| 3120 | SourceLocation ToInnerLocStart, ToEndLoc; |
| 3121 | NestedNameSpecifierLoc ToQualifierLoc; |
| 3122 | if (auto Imp = importSeq( |
| 3123 | FromTy, D->getTypeSourceInfo(), D->getInnerLocStart(), |
| 3124 | D->getQualifierLoc(), D->getEndLoc())) |
| 3125 | std::tie(T, TInfo, ToInnerLocStart, ToQualifierLoc, ToEndLoc) = *Imp; |
| 3126 | else |
| 3127 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3128 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3129 | // Import the function parameters. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3130 | SmallVector<ParmVarDecl *, 8> Parameters; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3131 | for (auto P : D->parameters()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3132 | if (Expected<ParmVarDecl *> ToPOrErr = import(P)) |
| 3133 | Parameters.push_back(*ToPOrErr); |
| 3134 | else |
| 3135 | return ToPOrErr.takeError(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3136 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3137 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3138 | // Create the imported function. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3139 | FunctionDecl *ToFunction = nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3140 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3141 | if (GetImportedOrCreateDecl<CXXConstructorDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3142 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3143 | ToInnerLocStart, NameInfo, T, TInfo, |
| 3144 | FromConstructor->isExplicit(), |
| 3145 | D->isInlineSpecified(), D->isImplicit(), D->isConstexpr())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3146 | return ToFunction; |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 3147 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3148 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers); |
| 3149 | // Import first, then allocate memory and copy if there was no error. |
| 3150 | if (Error Err = ImportContainerChecked( |
| 3151 | FromConstructor->inits(), CtorInitializers)) |
| 3152 | return std::move(Err); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3153 | auto **Memory = |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 3154 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 3155 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3156 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 3157 | ToCtor->setCtorInitializers(Memory); |
| 3158 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 3159 | } |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3160 | } else if (isa<CXXDestructorDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3161 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3162 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3163 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| 3164 | D->isImplicit())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3165 | return ToFunction; |
| 3166 | } else if (CXXConversionDecl *FromConversion = |
| 3167 | dyn_cast<CXXConversionDecl>(D)) { |
| 3168 | if (GetImportedOrCreateDecl<CXXConversionDecl>( |
| 3169 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3170 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3171 | FromConversion->isExplicit(), D->isConstexpr(), SourceLocation())) |
| 3172 | return ToFunction; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3173 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3174 | if (GetImportedOrCreateDecl<CXXMethodDecl>( |
| 3175 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3176 | ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3177 | Method->isInlineSpecified(), D->isConstexpr(), SourceLocation())) |
| 3178 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3179 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3180 | if (GetImportedOrCreateDecl(ToFunction, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3181 | ToInnerLocStart, NameInfo, T, TInfo, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3182 | D->getStorageClass(), D->isInlineSpecified(), |
| 3183 | D->hasWrittenPrototype(), D->isConstexpr())) |
| 3184 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3185 | } |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3186 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3187 | ToFunction->setQualifierInfo(ToQualifierLoc); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3188 | ToFunction->setAccess(D->getAccess()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3189 | ToFunction->setLexicalDeclContext(LexicalDC); |
John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 3190 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 3191 | ToFunction->setTrivial(D->isTrivial()); |
| 3192 | ToFunction->setPure(D->isPure()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3193 | ToFunction->setRangeEnd(ToEndLoc); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3194 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3195 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3196 | for (auto *Param : Parameters) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3197 | Param->setOwningFunction(ToFunction); |
| 3198 | ToFunction->addDeclInternal(Param); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3199 | } |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 3200 | ToFunction->setParams(Parameters); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3201 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3202 | if (FoundByLookup) { |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 3203 | auto *Recent = const_cast<FunctionDecl *>( |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3204 | FoundByLookup->getMostRecentDecl()); |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 3205 | ToFunction->setPreviousDecl(Recent); |
| 3206 | } |
| 3207 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3208 | // We need to complete creation of FunctionProtoTypeLoc manually with setting |
| 3209 | // params it refers to. |
| 3210 | if (TInfo) { |
| 3211 | if (auto ProtoLoc = |
| 3212 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { |
| 3213 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) |
| 3214 | ProtoLoc.setParam(I, Parameters[I]); |
| 3215 | } |
| 3216 | } |
| 3217 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3218 | if (usedDifferentExceptionSpec) { |
| 3219 | // Update FunctionProtoType::ExtProtoInfo. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3220 | if (ExpectedType TyOrErr = import(D->getType())) |
| 3221 | ToFunction->setType(*TyOrErr); |
| 3222 | else |
| 3223 | return TyOrErr.takeError(); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 3224 | } |
| 3225 | |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3226 | // Import the describing template function, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3227 | if (FromFT) { |
| 3228 | auto ToFTOrErr = import(FromFT); |
| 3229 | if (!ToFTOrErr) |
| 3230 | return ToFTOrErr.takeError(); |
| 3231 | } |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3232 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3233 | if (D->doesThisDeclarationHaveABody()) { |
| 3234 | if (Stmt *FromBody = D->getBody()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3235 | if (ExpectedStmt ToBodyOrErr = import(FromBody)) |
| 3236 | ToFunction->setBody(*ToBodyOrErr); |
| 3237 | else |
| 3238 | return ToBodyOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3239 | } |
| 3240 | } |
| 3241 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3242 | // FIXME: Other bits to merge? |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3243 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3244 | // If it is a template, import all related things. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3245 | if (Error Err = ImportTemplateInformation(D, ToFunction)) |
| 3246 | return std::move(Err); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3247 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3248 | bool IsFriend = D->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend); |
| 3249 | |
| 3250 | // TODO Can we generalize this approach to other AST nodes as well? |
| 3251 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 3252 | DC->addDeclInternal(ToFunction); |
| 3253 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3254 | LexicalDC->addDeclInternal(ToFunction); |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3255 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3256 | // Friend declaration's lexical context is the befriending class, but the |
| 3257 | // semantic context is the enclosing scope of the befriending class. |
| 3258 | // We want the friend functions to be found in the semantic context by lookup. |
| 3259 | // FIXME should we handle this generically in VisitFriendDecl? |
| 3260 | // In Other cases when LexicalDC != DC we don't want it to be added, |
| 3261 | // e.g out-of-class definitions like void B::f() {} . |
| 3262 | if (LexicalDC != DC && IsFriend) { |
| 3263 | DC->makeDeclVisibleInContext(ToFunction); |
| 3264 | } |
| 3265 | |
Gabor Marton | 7a0841e | 2018-10-29 10:18:28 +0000 | [diff] [blame] | 3266 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) |
| 3267 | ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod); |
| 3268 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3269 | // Import the rest of the chain. I.e. import all subsequent declarations. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3270 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3271 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 3272 | if (!ToRedeclOrErr) |
| 3273 | return ToRedeclOrErr.takeError(); |
| 3274 | } |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3275 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3276 | return ToFunction; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3277 | } |
| 3278 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3279 | ExpectedDecl ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3280 | return VisitFunctionDecl(D); |
| 3281 | } |
| 3282 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3283 | ExpectedDecl ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3284 | return VisitCXXMethodDecl(D); |
| 3285 | } |
| 3286 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3287 | ExpectedDecl ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3288 | return VisitCXXMethodDecl(D); |
| 3289 | } |
| 3290 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3291 | ExpectedDecl ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3292 | return VisitCXXMethodDecl(D); |
| 3293 | } |
| 3294 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3295 | ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3296 | // Import the major distinguishing characteristics of a variable. |
| 3297 | DeclContext *DC, *LexicalDC; |
| 3298 | DeclarationName Name; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3299 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3300 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3301 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3302 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3303 | if (ToD) |
| 3304 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3305 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3306 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3307 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3308 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3309 | for (auto *FoundDecl : FoundDecls) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3310 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3311 | // For anonymous fields, match up by index. |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3312 | if (!Name && |
| 3313 | ASTImporter::getFieldIndex(D) != |
| 3314 | ASTImporter::getFieldIndex(FoundField)) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3315 | continue; |
| 3316 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3317 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3318 | FoundField->getType())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3319 | Importer.MapImported(D, FoundField); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3320 | // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the |
| 3321 | // initializer of a FieldDecl might not had been instantiated in the |
| 3322 | // "To" context. However, the "From" context might instantiated that, |
| 3323 | // thus we have to merge that. |
| 3324 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
| 3325 | // We don't have yet the initializer set. |
| 3326 | if (FoundField->hasInClassInitializer() && |
| 3327 | !FoundField->getInClassInitializer()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3328 | if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) |
| 3329 | FoundField->setInClassInitializer(*ToInitializerOrErr); |
| 3330 | else { |
| 3331 | // We can't return error here, |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3332 | // since we already mapped D as imported. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3333 | // FIXME: warning message? |
| 3334 | consumeError(ToInitializerOrErr.takeError()); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3335 | return FoundField; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3336 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3337 | } |
| 3338 | } |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3339 | return FoundField; |
| 3340 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3341 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3342 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3343 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 3344 | << Name << D->getType() << FoundField->getType(); |
| 3345 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3346 | << FoundField->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3347 | |
| 3348 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3349 | } |
| 3350 | } |
| 3351 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3352 | QualType ToType; |
| 3353 | TypeSourceInfo *ToTInfo; |
| 3354 | Expr *ToBitWidth; |
| 3355 | SourceLocation ToInnerLocStart; |
| 3356 | Expr *ToInitializer; |
| 3357 | if (auto Imp = importSeq( |
| 3358 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), |
| 3359 | D->getInnerLocStart(), D->getInClassInitializer())) |
| 3360 | std::tie( |
| 3361 | ToType, ToTInfo, ToBitWidth, ToInnerLocStart, ToInitializer) = *Imp; |
| 3362 | else |
| 3363 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3364 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3365 | FieldDecl *ToField; |
| 3366 | if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3367 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3368 | ToType, ToTInfo, ToBitWidth, D->isMutable(), |
| 3369 | D->getInClassInitStyle())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3370 | return ToField; |
| 3371 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3372 | ToField->setAccess(D->getAccess()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3373 | ToField->setLexicalDeclContext(LexicalDC); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3374 | if (ToInitializer) |
| 3375 | ToField->setInClassInitializer(ToInitializer); |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3376 | ToField->setImplicit(D->isImplicit()); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3377 | LexicalDC->addDeclInternal(ToField); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3378 | return ToField; |
| 3379 | } |
| 3380 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3381 | ExpectedDecl ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3382 | // Import the major distinguishing characteristics of a variable. |
| 3383 | DeclContext *DC, *LexicalDC; |
| 3384 | DeclarationName Name; |
| 3385 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3386 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3387 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3388 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3389 | if (ToD) |
| 3390 | return ToD; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3391 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3392 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3393 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3394 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3395 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3396 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3397 | // For anonymous indirect fields, match up by index. |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3398 | if (!Name && |
| 3399 | ASTImporter::getFieldIndex(D) != |
| 3400 | ASTImporter::getFieldIndex(FoundField)) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3401 | continue; |
| 3402 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3403 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3404 | FoundField->getType(), |
David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 3405 | !Name.isEmpty())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3406 | Importer.MapImported(D, FoundField); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3407 | return FoundField; |
| 3408 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3409 | |
| 3410 | // If there are more anonymous fields to check, continue. |
| 3411 | if (!Name && I < N-1) |
| 3412 | continue; |
| 3413 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3414 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3415 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 3416 | << Name << D->getType() << FoundField->getType(); |
| 3417 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3418 | << FoundField->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3419 | |
| 3420 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3421 | } |
| 3422 | } |
| 3423 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3424 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3425 | auto TypeOrErr = import(D->getType()); |
| 3426 | if (!TypeOrErr) |
| 3427 | return TypeOrErr.takeError(); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3428 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3429 | auto **NamedChain = |
| 3430 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3431 | |
| 3432 | unsigned i = 0; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3433 | for (auto *PI : D->chain()) |
| 3434 | if (Expected<NamedDecl *> ToD = import(PI)) |
| 3435 | NamedChain[i++] = *ToD; |
| 3436 | else |
| 3437 | return ToD.takeError(); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3438 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3439 | llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()}; |
| 3440 | IndirectFieldDecl *ToIndirectField; |
| 3441 | if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3442 | Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3443 | // FIXME here we leak `NamedChain` which is allocated before |
| 3444 | return ToIndirectField; |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 3445 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3446 | for (const auto *Attr : D->attrs()) |
| 3447 | ToIndirectField->addAttr(Importer.Import(Attr)); |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 3448 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3449 | ToIndirectField->setAccess(D->getAccess()); |
| 3450 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3451 | LexicalDC->addDeclInternal(ToIndirectField); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3452 | return ToIndirectField; |
| 3453 | } |
| 3454 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3455 | ExpectedDecl ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3456 | // Import the major distinguishing characteristics of a declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3457 | DeclContext *DC, *LexicalDC; |
| 3458 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 3459 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3460 | |
| 3461 | // Determine whether we've already imported this decl. |
| 3462 | // FriendDecl is not a NamedDecl so we cannot use localUncachedLookup. |
| 3463 | auto *RD = cast<CXXRecordDecl>(DC); |
| 3464 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3465 | |
| 3466 | while (ImportedFriend) { |
| 3467 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 3468 | if (IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(), |
| 3469 | /*Complain=*/false)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3470 | return Importer.MapImported(D, ImportedFriend); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3471 | |
| 3472 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| 3473 | if (Importer.IsStructurallyEquivalent( |
| 3474 | D->getFriendType()->getType(), |
| 3475 | ImportedFriend->getFriendType()->getType(), true)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3476 | return Importer.MapImported(D, ImportedFriend); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3477 | } |
| 3478 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 3479 | } |
| 3480 | |
| 3481 | // Not found. Create it. |
| 3482 | FriendDecl::FriendUnion ToFU; |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3483 | if (NamedDecl *FriendD = D->getFriendDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3484 | NamedDecl *ToFriendD; |
| 3485 | if (Error Err = importInto(ToFriendD, FriendD)) |
| 3486 | return std::move(Err); |
| 3487 | |
| 3488 | if (FriendD->getFriendObjectKind() != Decl::FOK_None && |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3489 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) |
| 3490 | ToFriendD->setObjectOfFriendDecl(false); |
| 3491 | |
| 3492 | ToFU = ToFriendD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3493 | } else { // The friend is a type, not a decl. |
| 3494 | if (auto TSIOrErr = import(D->getFriendType())) |
| 3495 | ToFU = *TSIOrErr; |
| 3496 | else |
| 3497 | return TSIOrErr.takeError(); |
| 3498 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3499 | |
| 3500 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3501 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3502 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3503 | if (auto ListOrErr = ImportTemplateParameterList(FromTPLists[I])) |
| 3504 | ToTPLists[I] = *ListOrErr; |
| 3505 | else |
| 3506 | return ListOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3507 | } |
| 3508 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3509 | auto LocationOrErr = import(D->getLocation()); |
| 3510 | if (!LocationOrErr) |
| 3511 | return LocationOrErr.takeError(); |
| 3512 | auto FriendLocOrErr = import(D->getFriendLoc()); |
| 3513 | if (!FriendLocOrErr) |
| 3514 | return FriendLocOrErr.takeError(); |
| 3515 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3516 | FriendDecl *FrD; |
| 3517 | if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3518 | *LocationOrErr, ToFU, |
| 3519 | *FriendLocOrErr, ToTPLists)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3520 | return FrD; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3521 | |
| 3522 | FrD->setAccess(D->getAccess()); |
| 3523 | FrD->setLexicalDeclContext(LexicalDC); |
| 3524 | LexicalDC->addDeclInternal(FrD); |
| 3525 | return FrD; |
| 3526 | } |
| 3527 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3528 | ExpectedDecl ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3529 | // Import the major distinguishing characteristics of an ivar. |
| 3530 | DeclContext *DC, *LexicalDC; |
| 3531 | DeclarationName Name; |
| 3532 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3533 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3534 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3535 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3536 | if (ToD) |
| 3537 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3538 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3539 | // Determine whether we've already imported this ivar |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3540 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3541 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3542 | for (auto *FoundDecl : FoundDecls) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3543 | if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3544 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3545 | FoundIvar->getType())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3546 | Importer.MapImported(D, FoundIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3547 | return FoundIvar; |
| 3548 | } |
| 3549 | |
| 3550 | Importer.ToDiag(Loc, diag::err_odr_ivar_type_inconsistent) |
| 3551 | << Name << D->getType() << FoundIvar->getType(); |
| 3552 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) |
| 3553 | << FoundIvar->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3554 | |
| 3555 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3556 | } |
| 3557 | } |
| 3558 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3559 | QualType ToType; |
| 3560 | TypeSourceInfo *ToTypeSourceInfo; |
| 3561 | Expr *ToBitWidth; |
| 3562 | SourceLocation ToInnerLocStart; |
| 3563 | if (auto Imp = importSeq( |
| 3564 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), D->getInnerLocStart())) |
| 3565 | std::tie(ToType, ToTypeSourceInfo, ToBitWidth, ToInnerLocStart) = *Imp; |
| 3566 | else |
| 3567 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3568 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3569 | ObjCIvarDecl *ToIvar; |
| 3570 | if (GetImportedOrCreateDecl( |
| 3571 | ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3572 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3573 | ToType, ToTypeSourceInfo, |
| 3574 | D->getAccessControl(),ToBitWidth, D->getSynthesize())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3575 | return ToIvar; |
| 3576 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3577 | ToIvar->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3578 | LexicalDC->addDeclInternal(ToIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3579 | return ToIvar; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3580 | } |
| 3581 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3582 | ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) { |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3583 | |
| 3584 | SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D); |
| 3585 | auto RedeclIt = Redecls.begin(); |
| 3586 | // Import the first part of the decl chain. I.e. import all previous |
| 3587 | // declarations starting from the canonical decl. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3588 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 3589 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3590 | if (!RedeclOrErr) |
| 3591 | return RedeclOrErr.takeError(); |
| 3592 | } |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3593 | assert(*RedeclIt == D); |
| 3594 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3595 | // Import the major distinguishing characteristics of a variable. |
| 3596 | DeclContext *DC, *LexicalDC; |
| 3597 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3598 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3599 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3600 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3601 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3602 | if (ToD) |
| 3603 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3604 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3605 | // Try to find a variable in our own ("to") context with the same name and |
| 3606 | // in the same context as the variable we're importing. |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3607 | VarDecl *FoundByLookup = nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3608 | if (D->isFileVarDecl()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3609 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3610 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3611 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3612 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3613 | for (auto *FoundDecl : FoundDecls) { |
| 3614 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3615 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3616 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3617 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3618 | // 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] | 3619 | if (FoundVar->hasExternalFormalLinkage() && |
| 3620 | D->hasExternalFormalLinkage()) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3621 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3622 | FoundVar->getType())) { |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3623 | |
| 3624 | // The VarDecl in the "From" context has a definition, but in the |
| 3625 | // "To" context we already have a definition. |
| 3626 | VarDecl *FoundDef = FoundVar->getDefinition(); |
| 3627 | if (D->isThisDeclarationADefinition() && FoundDef) |
| 3628 | // FIXME Check for ODR error if the two definitions have |
| 3629 | // different initializers? |
| 3630 | return Importer.MapImported(D, FoundDef); |
| 3631 | |
| 3632 | // The VarDecl in the "From" context has an initializer, but in the |
| 3633 | // "To" context we already have an initializer. |
| 3634 | const VarDecl *FoundDInit = nullptr; |
| 3635 | if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit)) |
| 3636 | // FIXME Diagnose ODR error if the two initializers are different? |
| 3637 | return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit)); |
| 3638 | |
| 3639 | FoundByLookup = FoundVar; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3640 | break; |
| 3641 | } |
| 3642 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3643 | const ArrayType *FoundArray |
| 3644 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 3645 | const ArrayType *TArray |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3646 | = Importer.getToContext().getAsArrayType(D->getType()); |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3647 | if (FoundArray && TArray) { |
| 3648 | if (isa<IncompleteArrayType>(FoundArray) && |
| 3649 | isa<ConstantArrayType>(TArray)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3650 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3651 | if (auto TyOrErr = import(D->getType())) |
| 3652 | FoundVar->setType(*TyOrErr); |
| 3653 | else |
| 3654 | return TyOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3655 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3656 | FoundByLookup = FoundVar; |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3657 | break; |
| 3658 | } else if (isa<IncompleteArrayType>(TArray) && |
| 3659 | isa<ConstantArrayType>(FoundArray)) { |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3660 | FoundByLookup = FoundVar; |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3661 | break; |
Douglas Gregor | 2fbe558 | 2010-02-10 17:16:49 +0000 | [diff] [blame] | 3662 | } |
| 3663 | } |
| 3664 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3665 | Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3666 | << Name << D->getType() << FoundVar->getType(); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3667 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 3668 | << FoundVar->getType(); |
| 3669 | } |
| 3670 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3671 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3672 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3673 | } |
| 3674 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3675 | if (!ConflictingDecls.empty()) { |
| 3676 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3677 | ConflictingDecls.data(), |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3678 | ConflictingDecls.size()); |
| 3679 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3680 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3681 | } |
| 3682 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3683 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3684 | QualType ToType; |
| 3685 | TypeSourceInfo *ToTypeSourceInfo; |
| 3686 | SourceLocation ToInnerLocStart; |
| 3687 | NestedNameSpecifierLoc ToQualifierLoc; |
| 3688 | if (auto Imp = importSeq( |
| 3689 | D->getType(), D->getTypeSourceInfo(), D->getInnerLocStart(), |
| 3690 | D->getQualifierLoc())) |
| 3691 | std::tie(ToType, ToTypeSourceInfo, ToInnerLocStart, ToQualifierLoc) = *Imp; |
| 3692 | else |
| 3693 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3694 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3695 | // Create the imported variable. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3696 | VarDecl *ToVar; |
| 3697 | if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3698 | ToInnerLocStart, Loc, |
| 3699 | Name.getAsIdentifierInfo(), |
| 3700 | ToType, ToTypeSourceInfo, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3701 | D->getStorageClass())) |
| 3702 | return ToVar; |
| 3703 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3704 | ToVar->setQualifierInfo(ToQualifierLoc); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3705 | ToVar->setAccess(D->getAccess()); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3706 | ToVar->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3707 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3708 | if (FoundByLookup) { |
| 3709 | auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl()); |
| 3710 | ToVar->setPreviousDecl(Recent); |
| 3711 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3712 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3713 | if (Error Err = ImportInitializer(D, ToVar)) |
| 3714 | return std::move(Err); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3715 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3716 | if (D->isConstexpr()) |
| 3717 | ToVar->setConstexpr(true); |
| 3718 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3719 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 3720 | DC->addDeclInternal(ToVar); |
| 3721 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
| 3722 | LexicalDC->addDeclInternal(ToVar); |
| 3723 | |
| 3724 | // Import the rest of the chain. I.e. import all subsequent declarations. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3725 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3726 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3727 | if (!RedeclOrErr) |
| 3728 | return RedeclOrErr.takeError(); |
| 3729 | } |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3730 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3731 | return ToVar; |
| 3732 | } |
| 3733 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3734 | ExpectedDecl ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3735 | // Parameters are created in the translation unit's context, then moved |
| 3736 | // into the function declaration's context afterward. |
| 3737 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3738 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3739 | DeclarationName ToDeclName; |
| 3740 | SourceLocation ToLocation; |
| 3741 | QualType ToType; |
| 3742 | if (auto Imp = importSeq(D->getDeclName(), D->getLocation(), D->getType())) |
| 3743 | std::tie(ToDeclName, ToLocation, ToType) = *Imp; |
| 3744 | else |
| 3745 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3746 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3747 | // Create the imported parameter. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3748 | ImplicitParamDecl *ToParm = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3749 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
| 3750 | ToLocation, ToDeclName.getAsIdentifierInfo(), |
| 3751 | ToType, D->getParameterKind())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3752 | return ToParm; |
| 3753 | return ToParm; |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3754 | } |
| 3755 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3756 | ExpectedDecl ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3757 | // Parameters are created in the translation unit's context, then moved |
| 3758 | // into the function declaration's context afterward. |
| 3759 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3760 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3761 | DeclarationName ToDeclName; |
| 3762 | SourceLocation ToLocation, ToInnerLocStart; |
| 3763 | QualType ToType; |
| 3764 | TypeSourceInfo *ToTypeSourceInfo; |
| 3765 | if (auto Imp = importSeq( |
| 3766 | D->getDeclName(), D->getLocation(), D->getType(), D->getInnerLocStart(), |
| 3767 | D->getTypeSourceInfo())) |
| 3768 | std::tie( |
| 3769 | ToDeclName, ToLocation, ToType, ToInnerLocStart, |
| 3770 | ToTypeSourceInfo) = *Imp; |
| 3771 | else |
| 3772 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3773 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3774 | ParmVarDecl *ToParm; |
| 3775 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3776 | ToInnerLocStart, ToLocation, |
| 3777 | ToDeclName.getAsIdentifierInfo(), ToType, |
| 3778 | ToTypeSourceInfo, D->getStorageClass(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3779 | /*DefaultArg*/ nullptr)) |
| 3780 | return ToParm; |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3781 | |
| 3782 | // Set the default argument. |
John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 3783 | ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg()); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3784 | ToParm->setKNRPromoted(D->isKNRPromoted()); |
| 3785 | |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3786 | if (D->hasUninstantiatedDefaultArg()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3787 | if (auto ToDefArgOrErr = import(D->getUninstantiatedDefaultArg())) |
| 3788 | ToParm->setUninstantiatedDefaultArg(*ToDefArgOrErr); |
| 3789 | else |
| 3790 | return ToDefArgOrErr.takeError(); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3791 | } else if (D->hasUnparsedDefaultArg()) { |
| 3792 | ToParm->setUnparsedDefaultArg(); |
| 3793 | } else if (D->hasDefaultArg()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3794 | if (auto ToDefArgOrErr = import(D->getDefaultArg())) |
| 3795 | ToParm->setDefaultArg(*ToDefArgOrErr); |
| 3796 | else |
| 3797 | return ToDefArgOrErr.takeError(); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3798 | } |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3799 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3800 | if (D->isObjCMethodParameter()) { |
| 3801 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); |
| 3802 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); |
| 3803 | } else { |
| 3804 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), |
| 3805 | D->getFunctionScopeIndex()); |
| 3806 | } |
| 3807 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3808 | return ToParm; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3809 | } |
| 3810 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3811 | ExpectedDecl ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3812 | // Import the major distinguishing characteristics of a method. |
| 3813 | DeclContext *DC, *LexicalDC; |
| 3814 | DeclarationName Name; |
| 3815 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3816 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3817 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3818 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3819 | if (ToD) |
| 3820 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3821 | |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3822 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3823 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3824 | for (auto *FoundDecl : FoundDecls) { |
| 3825 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3826 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 3827 | continue; |
| 3828 | |
| 3829 | // Check return types. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3830 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 3831 | FoundMethod->getReturnType())) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3832 | Importer.ToDiag(Loc, diag::err_odr_objc_method_result_type_inconsistent) |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3833 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 3834 | << FoundMethod->getReturnType(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3835 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3836 | diag::note_odr_objc_method_here) |
| 3837 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3838 | |
| 3839 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3840 | } |
| 3841 | |
| 3842 | // Check the number of parameters. |
| 3843 | if (D->param_size() != FoundMethod->param_size()) { |
| 3844 | Importer.ToDiag(Loc, diag::err_odr_objc_method_num_params_inconsistent) |
| 3845 | << D->isInstanceMethod() << Name |
| 3846 | << D->param_size() << FoundMethod->param_size(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3847 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3848 | diag::note_odr_objc_method_here) |
| 3849 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3850 | |
| 3851 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3852 | } |
| 3853 | |
| 3854 | // Check parameter types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3855 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3856 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 3857 | P != PEnd; ++P, ++FoundP) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3858 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3859 | (*FoundP)->getType())) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3860 | Importer.FromDiag((*P)->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3861 | diag::err_odr_objc_method_param_type_inconsistent) |
| 3862 | << D->isInstanceMethod() << Name |
| 3863 | << (*P)->getType() << (*FoundP)->getType(); |
| 3864 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 3865 | << (*FoundP)->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3866 | |
| 3867 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3868 | } |
| 3869 | } |
| 3870 | |
| 3871 | // Check variadic/non-variadic. |
| 3872 | // Check the number of parameters. |
| 3873 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
| 3874 | Importer.ToDiag(Loc, diag::err_odr_objc_method_variadic_inconsistent) |
| 3875 | << D->isInstanceMethod() << Name; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3876 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3877 | diag::note_odr_objc_method_here) |
| 3878 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3879 | |
| 3880 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3881 | } |
| 3882 | |
| 3883 | // FIXME: Any other bits we need to merge? |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3884 | return Importer.MapImported(D, FoundMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3885 | } |
| 3886 | } |
| 3887 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3888 | SourceLocation ToEndLoc; |
| 3889 | QualType ToReturnType; |
| 3890 | TypeSourceInfo *ToReturnTypeSourceInfo; |
| 3891 | if (auto Imp = importSeq( |
| 3892 | D->getEndLoc(), D->getReturnType(), D->getReturnTypeSourceInfo())) |
| 3893 | std::tie(ToEndLoc, ToReturnType, ToReturnTypeSourceInfo) = *Imp; |
| 3894 | else |
| 3895 | return Imp.takeError(); |
Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 3896 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3897 | ObjCMethodDecl *ToMethod; |
| 3898 | if (GetImportedOrCreateDecl( |
| 3899 | ToMethod, D, Importer.getToContext(), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3900 | ToEndLoc, Name.getObjCSelector(), ToReturnType, |
| 3901 | ToReturnTypeSourceInfo, DC, D->isInstanceMethod(), D->isVariadic(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3902 | D->isPropertyAccessor(), D->isImplicit(), D->isDefined(), |
| 3903 | D->getImplementationControl(), D->hasRelatedResultType())) |
| 3904 | return ToMethod; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3905 | |
| 3906 | // FIXME: When we decide to merge method definitions, we'll need to |
| 3907 | // deal with implicit parameters. |
| 3908 | |
| 3909 | // Import the parameters |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3910 | SmallVector<ParmVarDecl *, 5> ToParams; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3911 | for (auto *FromP : D->parameters()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3912 | if (Expected<ParmVarDecl *> ToPOrErr = import(FromP)) |
| 3913 | ToParams.push_back(*ToPOrErr); |
| 3914 | else |
| 3915 | return ToPOrErr.takeError(); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3916 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3917 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3918 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3919 | for (auto *ToParam : ToParams) { |
| 3920 | ToParam->setOwningFunction(ToMethod); |
| 3921 | ToMethod->addDeclInternal(ToParam); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3922 | } |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3923 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3924 | SmallVector<SourceLocation, 12> FromSelLocs; |
| 3925 | D->getSelectorLocs(FromSelLocs); |
| 3926 | SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size()); |
| 3927 | if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs)) |
| 3928 | return std::move(Err); |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3929 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3930 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3931 | |
| 3932 | ToMethod->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3933 | LexicalDC->addDeclInternal(ToMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3934 | return ToMethod; |
| 3935 | } |
| 3936 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3937 | ExpectedDecl ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3938 | // Import the major distinguishing characteristics of a category. |
| 3939 | DeclContext *DC, *LexicalDC; |
| 3940 | DeclarationName Name; |
| 3941 | SourceLocation Loc; |
| 3942 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3943 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3944 | return std::move(Err); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3945 | if (ToD) |
| 3946 | return ToD; |
| 3947 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3948 | SourceLocation ToVarianceLoc, ToLocation, ToColonLoc; |
| 3949 | TypeSourceInfo *ToTypeSourceInfo; |
| 3950 | if (auto Imp = importSeq( |
| 3951 | D->getVarianceLoc(), D->getLocation(), D->getColonLoc(), |
| 3952 | D->getTypeSourceInfo())) |
| 3953 | std::tie(ToVarianceLoc, ToLocation, ToColonLoc, ToTypeSourceInfo) = *Imp; |
| 3954 | else |
| 3955 | return Imp.takeError(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3956 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3957 | ObjCTypeParamDecl *Result; |
| 3958 | if (GetImportedOrCreateDecl( |
| 3959 | Result, D, Importer.getToContext(), DC, D->getVariance(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3960 | ToVarianceLoc, D->getIndex(), |
| 3961 | ToLocation, Name.getAsIdentifierInfo(), |
| 3962 | ToColonLoc, ToTypeSourceInfo)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3963 | return Result; |
| 3964 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3965 | Result->setLexicalDeclContext(LexicalDC); |
| 3966 | return Result; |
| 3967 | } |
| 3968 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3969 | ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3970 | // Import the major distinguishing characteristics of a category. |
| 3971 | DeclContext *DC, *LexicalDC; |
| 3972 | DeclarationName Name; |
| 3973 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3974 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3975 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3976 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3977 | if (ToD) |
| 3978 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3979 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3980 | ObjCInterfaceDecl *ToInterface; |
| 3981 | if (Error Err = importInto(ToInterface, D->getClassInterface())) |
| 3982 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3983 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3984 | // Determine if we've already encountered this category. |
| 3985 | ObjCCategoryDecl *MergeWithCategory |
| 3986 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 3987 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 3988 | if (!ToCategory) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3989 | SourceLocation ToAtStartLoc, ToCategoryNameLoc; |
| 3990 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; |
| 3991 | if (auto Imp = importSeq( |
| 3992 | D->getAtStartLoc(), D->getCategoryNameLoc(), |
| 3993 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) |
| 3994 | std::tie( |
| 3995 | ToAtStartLoc, ToCategoryNameLoc, |
| 3996 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; |
| 3997 | else |
| 3998 | return Imp.takeError(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3999 | |
| 4000 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4001 | ToAtStartLoc, Loc, |
| 4002 | ToCategoryNameLoc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4003 | Name.getAsIdentifierInfo(), ToInterface, |
| 4004 | /*TypeParamList=*/nullptr, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4005 | ToIvarLBraceLoc, |
| 4006 | ToIvarRBraceLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4007 | return ToCategory; |
| 4008 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4009 | ToCategory->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4010 | LexicalDC->addDeclInternal(ToCategory); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4011 | // Import the type parameter list after MapImported, to avoid |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4012 | // loops when bringing in their DeclContext. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4013 | if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList())) |
| 4014 | ToCategory->setTypeParamList(*PListOrErr); |
| 4015 | else |
| 4016 | return PListOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4017 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4018 | // Import protocols |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4019 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4020 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4021 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 4022 | = D->protocol_loc_begin(); |
| 4023 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 4024 | FromProtoEnd = D->protocol_end(); |
| 4025 | FromProto != FromProtoEnd; |
| 4026 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4027 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4028 | Protocols.push_back(*ToProtoOrErr); |
| 4029 | else |
| 4030 | return ToProtoOrErr.takeError(); |
| 4031 | |
| 4032 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4033 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4034 | else |
| 4035 | return ToProtoLocOrErr.takeError(); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4036 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4037 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4038 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4039 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 4040 | ProtocolLocs.data(), Importer.getToContext()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4041 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4042 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4043 | Importer.MapImported(D, ToCategory); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4044 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4045 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4046 | // Import all of the members of this category. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4047 | if (Error Err = ImportDeclContext(D)) |
| 4048 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4049 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4050 | // If we have an implementation, import it as well. |
| 4051 | if (D->getImplementation()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4052 | if (Expected<ObjCCategoryImplDecl *> ToImplOrErr = |
| 4053 | import(D->getImplementation())) |
| 4054 | ToCategory->setImplementation(*ToImplOrErr); |
| 4055 | else |
| 4056 | return ToImplOrErr.takeError(); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4057 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4058 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4059 | return ToCategory; |
| 4060 | } |
| 4061 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4062 | Error ASTNodeImporter::ImportDefinition( |
| 4063 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4064 | if (To->getDefinition()) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4065 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4066 | if (Error Err = ImportDeclContext(From)) |
| 4067 | return Err; |
| 4068 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4069 | } |
| 4070 | |
| 4071 | // Start the protocol definition |
| 4072 | To->startDefinition(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4073 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4074 | // Import protocols |
| 4075 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4076 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4077 | ObjCProtocolDecl::protocol_loc_iterator FromProtoLoc = |
| 4078 | From->protocol_loc_begin(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4079 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4080 | FromProtoEnd = From->protocol_end(); |
| 4081 | FromProto != FromProtoEnd; |
| 4082 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4083 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4084 | Protocols.push_back(*ToProtoOrErr); |
| 4085 | else |
| 4086 | return ToProtoOrErr.takeError(); |
| 4087 | |
| 4088 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4089 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4090 | else |
| 4091 | return ToProtoLocOrErr.takeError(); |
| 4092 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4093 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4094 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4095 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4096 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4097 | ProtocolLocs.data(), Importer.getToContext()); |
| 4098 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4099 | if (shouldForceImportDeclContext(Kind)) { |
| 4100 | // Import all of the members of this protocol. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4101 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4102 | return Err; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4103 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4104 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4105 | } |
| 4106 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4107 | ExpectedDecl ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4108 | // 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] | 4109 | // from, but this particular declaration is not that definition, import the |
| 4110 | // definition and map to that. |
| 4111 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 4112 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4113 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4114 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4115 | else |
| 4116 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4117 | } |
| 4118 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4119 | // Import the major distinguishing characteristics of a protocol. |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4120 | DeclContext *DC, *LexicalDC; |
| 4121 | DeclarationName Name; |
| 4122 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4123 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4124 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4125 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4126 | if (ToD) |
| 4127 | return ToD; |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4128 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4129 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4130 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4131 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4132 | for (auto *FoundDecl : FoundDecls) { |
| 4133 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4134 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4135 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4136 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4137 | break; |
| 4138 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4139 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4140 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4141 | if (!ToProto) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4142 | auto ToAtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4143 | if (!ToAtBeginLocOrErr) |
| 4144 | return ToAtBeginLocOrErr.takeError(); |
| 4145 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4146 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, |
| 4147 | Name.getAsIdentifierInfo(), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4148 | *ToAtBeginLocOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4149 | /*PrevDecl=*/nullptr)) |
| 4150 | return ToProto; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4151 | ToProto->setLexicalDeclContext(LexicalDC); |
| 4152 | LexicalDC->addDeclInternal(ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4153 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4154 | |
| 4155 | Importer.MapImported(D, ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4156 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4157 | if (D->isThisDeclarationADefinition()) |
| 4158 | if (Error Err = ImportDefinition(D, ToProto)) |
| 4159 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4160 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4161 | return ToProto; |
| 4162 | } |
| 4163 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4164 | ExpectedDecl ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 4165 | DeclContext *DC, *LexicalDC; |
| 4166 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4167 | return std::move(Err); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4168 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4169 | ExpectedSLoc ExternLocOrErr = import(D->getExternLoc()); |
| 4170 | if (!ExternLocOrErr) |
| 4171 | return ExternLocOrErr.takeError(); |
| 4172 | |
| 4173 | ExpectedSLoc LangLocOrErr = import(D->getLocation()); |
| 4174 | if (!LangLocOrErr) |
| 4175 | return LangLocOrErr.takeError(); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4176 | |
| 4177 | bool HasBraces = D->hasBraces(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4178 | |
| 4179 | LinkageSpecDecl *ToLinkageSpec; |
| 4180 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4181 | *ExternLocOrErr, *LangLocOrErr, |
| 4182 | D->getLanguage(), HasBraces)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4183 | return ToLinkageSpec; |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4184 | |
| 4185 | if (HasBraces) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4186 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); |
| 4187 | if (!RBraceLocOrErr) |
| 4188 | return RBraceLocOrErr.takeError(); |
| 4189 | ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4190 | } |
| 4191 | |
| 4192 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 4193 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 4194 | |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4195 | return ToLinkageSpec; |
| 4196 | } |
| 4197 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4198 | ExpectedDecl ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4199 | DeclContext *DC, *LexicalDC; |
| 4200 | DeclarationName Name; |
| 4201 | SourceLocation Loc; |
| 4202 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4203 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4204 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4205 | if (ToD) |
| 4206 | return ToD; |
| 4207 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4208 | SourceLocation ToLoc, ToUsingLoc; |
| 4209 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4210 | if (auto Imp = importSeq( |
| 4211 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc())) |
| 4212 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc) = *Imp; |
| 4213 | else |
| 4214 | return Imp.takeError(); |
| 4215 | |
| 4216 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4217 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4218 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4219 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4220 | UsingDecl *ToUsing; |
| 4221 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4222 | ToUsingLoc, ToQualifierLoc, NameInfo, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4223 | D->hasTypename())) |
| 4224 | return ToUsing; |
| 4225 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4226 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4227 | LexicalDC->addDeclInternal(ToUsing); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4228 | |
| 4229 | if (NamedDecl *FromPattern = |
| 4230 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4231 | if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern)) |
| 4232 | Importer.getToContext().setInstantiatedFromUsingDecl( |
| 4233 | ToUsing, *ToPatternOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4234 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4235 | return ToPatternOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4236 | } |
| 4237 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4238 | for (UsingShadowDecl *FromShadow : D->shadows()) { |
| 4239 | if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow)) |
| 4240 | ToUsing->addShadowDecl(*ToShadowOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4241 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4242 | // FIXME: We return error here but the definition is already created |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4243 | // and available with lookups. How to fix this?.. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4244 | return ToShadowOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4245 | } |
| 4246 | return ToUsing; |
| 4247 | } |
| 4248 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4249 | ExpectedDecl ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4250 | DeclContext *DC, *LexicalDC; |
| 4251 | DeclarationName Name; |
| 4252 | SourceLocation Loc; |
| 4253 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4254 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4255 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4256 | if (ToD) |
| 4257 | return ToD; |
| 4258 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4259 | Expected<UsingDecl *> ToUsingOrErr = import(D->getUsingDecl()); |
| 4260 | if (!ToUsingOrErr) |
| 4261 | return ToUsingOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4262 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4263 | Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl()); |
| 4264 | if (!ToTargetOrErr) |
| 4265 | return ToTargetOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4266 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4267 | UsingShadowDecl *ToShadow; |
| 4268 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4269 | *ToUsingOrErr, *ToTargetOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4270 | return ToShadow; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4271 | |
| 4272 | ToShadow->setLexicalDeclContext(LexicalDC); |
| 4273 | ToShadow->setAccess(D->getAccess()); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4274 | |
| 4275 | if (UsingShadowDecl *FromPattern = |
| 4276 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4277 | if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern)) |
| 4278 | Importer.getToContext().setInstantiatedFromUsingShadowDecl( |
| 4279 | ToShadow, *ToPatternOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4280 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4281 | // FIXME: We return error here but the definition is already created |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4282 | // and available with lookups. How to fix this?.. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4283 | return ToPatternOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4284 | } |
| 4285 | |
| 4286 | LexicalDC->addDeclInternal(ToShadow); |
| 4287 | |
| 4288 | return ToShadow; |
| 4289 | } |
| 4290 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4291 | ExpectedDecl ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4292 | DeclContext *DC, *LexicalDC; |
| 4293 | DeclarationName Name; |
| 4294 | SourceLocation Loc; |
| 4295 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4296 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4297 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4298 | if (ToD) |
| 4299 | return ToD; |
| 4300 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4301 | auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor()); |
| 4302 | if (!ToComAncestorOrErr) |
| 4303 | return ToComAncestorOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4304 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4305 | NamespaceDecl *ToNominatedNamespace; |
| 4306 | SourceLocation ToUsingLoc, ToNamespaceKeyLocation, ToIdentLocation; |
| 4307 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4308 | if (auto Imp = importSeq( |
| 4309 | D->getNominatedNamespace(), D->getUsingLoc(), |
| 4310 | D->getNamespaceKeyLocation(), D->getQualifierLoc(), |
| 4311 | D->getIdentLocation())) |
| 4312 | std::tie( |
| 4313 | ToNominatedNamespace, ToUsingLoc, ToNamespaceKeyLocation, |
| 4314 | ToQualifierLoc, ToIdentLocation) = *Imp; |
| 4315 | else |
| 4316 | return Imp.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4317 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4318 | UsingDirectiveDecl *ToUsingDir; |
| 4319 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4320 | ToUsingLoc, |
| 4321 | ToNamespaceKeyLocation, |
| 4322 | ToQualifierLoc, |
| 4323 | ToIdentLocation, |
| 4324 | ToNominatedNamespace, *ToComAncestorOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4325 | return ToUsingDir; |
| 4326 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4327 | ToUsingDir->setLexicalDeclContext(LexicalDC); |
| 4328 | LexicalDC->addDeclInternal(ToUsingDir); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4329 | |
| 4330 | return ToUsingDir; |
| 4331 | } |
| 4332 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4333 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4334 | UnresolvedUsingValueDecl *D) { |
| 4335 | DeclContext *DC, *LexicalDC; |
| 4336 | DeclarationName Name; |
| 4337 | SourceLocation Loc; |
| 4338 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4339 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4340 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4341 | if (ToD) |
| 4342 | return ToD; |
| 4343 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4344 | SourceLocation ToLoc, ToUsingLoc, ToEllipsisLoc; |
| 4345 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4346 | if (auto Imp = importSeq( |
| 4347 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc(), |
| 4348 | D->getEllipsisLoc())) |
| 4349 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; |
| 4350 | else |
| 4351 | return Imp.takeError(); |
| 4352 | |
| 4353 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4354 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4355 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4356 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4357 | UnresolvedUsingValueDecl *ToUsingValue; |
| 4358 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4359 | ToUsingLoc, ToQualifierLoc, NameInfo, |
| 4360 | ToEllipsisLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4361 | return ToUsingValue; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4362 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4363 | ToUsingValue->setAccess(D->getAccess()); |
| 4364 | ToUsingValue->setLexicalDeclContext(LexicalDC); |
| 4365 | LexicalDC->addDeclInternal(ToUsingValue); |
| 4366 | |
| 4367 | return ToUsingValue; |
| 4368 | } |
| 4369 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4370 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4371 | UnresolvedUsingTypenameDecl *D) { |
| 4372 | DeclContext *DC, *LexicalDC; |
| 4373 | DeclarationName Name; |
| 4374 | SourceLocation Loc; |
| 4375 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4376 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4377 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4378 | if (ToD) |
| 4379 | return ToD; |
| 4380 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4381 | SourceLocation ToUsingLoc, ToTypenameLoc, ToEllipsisLoc; |
| 4382 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4383 | if (auto Imp = importSeq( |
| 4384 | D->getUsingLoc(), D->getTypenameLoc(), D->getQualifierLoc(), |
| 4385 | D->getEllipsisLoc())) |
| 4386 | std::tie(ToUsingLoc, ToTypenameLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; |
| 4387 | else |
| 4388 | return Imp.takeError(); |
| 4389 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4390 | UnresolvedUsingTypenameDecl *ToUsing; |
| 4391 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4392 | ToUsingLoc, ToTypenameLoc, |
| 4393 | ToQualifierLoc, Loc, Name, ToEllipsisLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4394 | return ToUsing; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4395 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4396 | ToUsing->setAccess(D->getAccess()); |
| 4397 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4398 | LexicalDC->addDeclInternal(ToUsing); |
| 4399 | |
| 4400 | return ToUsing; |
| 4401 | } |
| 4402 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4403 | |
| 4404 | Error ASTNodeImporter::ImportDefinition( |
| 4405 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4406 | if (To->getDefinition()) { |
| 4407 | // Check consistency of superclass. |
| 4408 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 4409 | if (FromSuper) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4410 | if (auto FromSuperOrErr = import(FromSuper)) |
| 4411 | FromSuper = *FromSuperOrErr; |
| 4412 | else |
| 4413 | return FromSuperOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4414 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4415 | |
| 4416 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4417 | if ((bool)FromSuper != (bool)ToSuper || |
| 4418 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4419 | Importer.ToDiag(To->getLocation(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4420 | diag::err_odr_objc_superclass_inconsistent) |
| 4421 | << To->getDeclName(); |
| 4422 | if (ToSuper) |
| 4423 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 4424 | << To->getSuperClass()->getDeclName(); |
| 4425 | else |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4426 | Importer.ToDiag(To->getLocation(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4427 | diag::note_odr_objc_missing_superclass); |
| 4428 | if (From->getSuperClass()) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4429 | Importer.FromDiag(From->getSuperClassLoc(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4430 | diag::note_odr_objc_superclass) |
| 4431 | << From->getSuperClass()->getDeclName(); |
| 4432 | else |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4433 | Importer.FromDiag(From->getLocation(), |
| 4434 | diag::note_odr_objc_missing_superclass); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4435 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4436 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4437 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4438 | if (Error Err = ImportDeclContext(From)) |
| 4439 | return Err; |
| 4440 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4441 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4442 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4443 | // Start the definition. |
| 4444 | To->startDefinition(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4445 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4446 | // If this class has a superclass, import it. |
| 4447 | if (From->getSuperClass()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4448 | if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo())) |
| 4449 | To->setSuperClass(*SuperTInfoOrErr); |
| 4450 | else |
| 4451 | return SuperTInfoOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4452 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4453 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4454 | // Import protocols |
| 4455 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4456 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4457 | ObjCInterfaceDecl::protocol_loc_iterator FromProtoLoc = |
| 4458 | From->protocol_loc_begin(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4459 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4460 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4461 | FromProtoEnd = From->protocol_end(); |
| 4462 | FromProto != FromProtoEnd; |
| 4463 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4464 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4465 | Protocols.push_back(*ToProtoOrErr); |
| 4466 | else |
| 4467 | return ToProtoOrErr.takeError(); |
| 4468 | |
| 4469 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4470 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4471 | else |
| 4472 | return ToProtoLocOrErr.takeError(); |
| 4473 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4474 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4475 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4476 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4477 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4478 | ProtocolLocs.data(), Importer.getToContext()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4479 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4480 | // Import categories. When the categories themselves are imported, they'll |
| 4481 | // hook themselves into this interface. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4482 | for (auto *Cat : From->known_categories()) { |
| 4483 | auto ToCatOrErr = import(Cat); |
| 4484 | if (!ToCatOrErr) |
| 4485 | return ToCatOrErr.takeError(); |
| 4486 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4487 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4488 | // If we have an @implementation, import it as well. |
| 4489 | if (From->getImplementation()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4490 | if (Expected<ObjCImplementationDecl *> ToImplOrErr = |
| 4491 | import(From->getImplementation())) |
| 4492 | To->setImplementation(*ToImplOrErr); |
| 4493 | else |
| 4494 | return ToImplOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4495 | } |
| 4496 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4497 | if (shouldForceImportDeclContext(Kind)) { |
| 4498 | // Import all of the members of this class. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4499 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4500 | return Err; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4501 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4502 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4503 | } |
| 4504 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4505 | Expected<ObjCTypeParamList *> |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4506 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 4507 | if (!list) |
| 4508 | return nullptr; |
| 4509 | |
| 4510 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4511 | for (auto *fromTypeParam : *list) { |
| 4512 | if (auto toTypeParamOrErr = import(fromTypeParam)) |
| 4513 | toTypeParams.push_back(*toTypeParamOrErr); |
| 4514 | else |
| 4515 | return toTypeParamOrErr.takeError(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4516 | } |
| 4517 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4518 | auto LAngleLocOrErr = import(list->getLAngleLoc()); |
| 4519 | if (!LAngleLocOrErr) |
| 4520 | return LAngleLocOrErr.takeError(); |
| 4521 | |
| 4522 | auto RAngleLocOrErr = import(list->getRAngleLoc()); |
| 4523 | if (!RAngleLocOrErr) |
| 4524 | return RAngleLocOrErr.takeError(); |
| 4525 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4526 | return ObjCTypeParamList::create(Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4527 | *LAngleLocOrErr, |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4528 | toTypeParams, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4529 | *RAngleLocOrErr); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4530 | } |
| 4531 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4532 | ExpectedDecl ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4533 | // If this class has a definition in the translation unit we're coming from, |
| 4534 | // but this particular declaration is not that definition, import the |
| 4535 | // definition and map to that. |
| 4536 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 4537 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4538 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4539 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4540 | else |
| 4541 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4542 | } |
| 4543 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4544 | // Import the major distinguishing characteristics of an @interface. |
| 4545 | DeclContext *DC, *LexicalDC; |
| 4546 | DeclarationName Name; |
| 4547 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4548 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4549 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4550 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4551 | if (ToD) |
| 4552 | return ToD; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4553 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4554 | // Look for an existing interface with the same name. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4555 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4556 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4557 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4558 | for (auto *FoundDecl : FoundDecls) { |
| 4559 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4560 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4561 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4562 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4563 | break; |
| 4564 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4565 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4566 | // Create an interface declaration, if one does not already exist. |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4567 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4568 | if (!ToIface) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4569 | ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4570 | if (!AtBeginLocOrErr) |
| 4571 | return AtBeginLocOrErr.takeError(); |
| 4572 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4573 | if (GetImportedOrCreateDecl( |
| 4574 | ToIface, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4575 | *AtBeginLocOrErr, Name.getAsIdentifierInfo(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4576 | /*TypeParamList=*/nullptr, |
| 4577 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) |
| 4578 | return ToIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4579 | ToIface->setLexicalDeclContext(LexicalDC); |
| 4580 | LexicalDC->addDeclInternal(ToIface); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4581 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4582 | Importer.MapImported(D, ToIface); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4583 | // Import the type parameter list after MapImported, to avoid |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4584 | // loops when bringing in their DeclContext. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4585 | if (auto ToPListOrErr = |
| 4586 | ImportObjCTypeParamList(D->getTypeParamListAsWritten())) |
| 4587 | ToIface->setTypeParamList(*ToPListOrErr); |
| 4588 | else |
| 4589 | return ToPListOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4590 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4591 | if (D->isThisDeclarationADefinition()) |
| 4592 | if (Error Err = ImportDefinition(D, ToIface)) |
| 4593 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4594 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4595 | return ToIface; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4596 | } |
| 4597 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4598 | ExpectedDecl |
| 4599 | ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 4600 | ObjCCategoryDecl *Category; |
| 4601 | if (Error Err = importInto(Category, D->getCategoryDecl())) |
| 4602 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4603 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4604 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 4605 | if (!ToImpl) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4606 | DeclContext *DC, *LexicalDC; |
| 4607 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4608 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4609 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4610 | SourceLocation ToLocation, ToAtStartLoc, ToCategoryNameLoc; |
| 4611 | if (auto Imp = importSeq( |
| 4612 | D->getLocation(), D->getAtStartLoc(), D->getCategoryNameLoc())) |
| 4613 | std::tie(ToLocation, ToAtStartLoc, ToCategoryNameLoc) = *Imp; |
| 4614 | else |
| 4615 | return Imp.takeError(); |
| 4616 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4617 | if (GetImportedOrCreateDecl( |
| 4618 | ToImpl, D, Importer.getToContext(), DC, |
| 4619 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4620 | ToLocation, ToAtStartLoc, ToCategoryNameLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4621 | return ToImpl; |
| 4622 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4623 | ToImpl->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4624 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4625 | Category->setImplementation(ToImpl); |
| 4626 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4627 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4628 | Importer.MapImported(D, ToImpl); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4629 | if (Error Err = ImportDeclContext(D)) |
| 4630 | return std::move(Err); |
| 4631 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4632 | return ToImpl; |
| 4633 | } |
| 4634 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4635 | ExpectedDecl |
| 4636 | ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4637 | // Find the corresponding interface. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4638 | ObjCInterfaceDecl *Iface; |
| 4639 | if (Error Err = importInto(Iface, D->getClassInterface())) |
| 4640 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4641 | |
| 4642 | // Import the superclass, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4643 | ObjCInterfaceDecl *Super; |
| 4644 | if (Error Err = importInto(Super, D->getSuperClass())) |
| 4645 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4646 | |
| 4647 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 4648 | if (!Impl) { |
| 4649 | // We haven't imported an implementation yet. Create a new @implementation |
| 4650 | // now. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4651 | DeclContext *DC, *LexicalDC; |
| 4652 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4653 | return std::move(Err); |
| 4654 | |
| 4655 | SourceLocation ToLocation, ToAtStartLoc, ToSuperClassLoc; |
| 4656 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; |
| 4657 | if (auto Imp = importSeq( |
| 4658 | D->getLocation(), D->getAtStartLoc(), D->getSuperClassLoc(), |
| 4659 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) |
| 4660 | std::tie( |
| 4661 | ToLocation, ToAtStartLoc, ToSuperClassLoc, |
| 4662 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; |
| 4663 | else |
| 4664 | return Imp.takeError(); |
| 4665 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4666 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4667 | DC, Iface, Super, |
| 4668 | ToLocation, |
| 4669 | ToAtStartLoc, |
| 4670 | ToSuperClassLoc, |
| 4671 | ToIvarLBraceLoc, |
| 4672 | ToIvarRBraceLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4673 | return Impl; |
| 4674 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4675 | Impl->setLexicalDeclContext(LexicalDC); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4676 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4677 | // Associate the implementation with the class it implements. |
| 4678 | Iface->setImplementation(Impl); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4679 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4680 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4681 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4682 | |
| 4683 | // Verify that the existing @implementation has the same superclass. |
| 4684 | if ((Super && !Impl->getSuperClass()) || |
| 4685 | (!Super && Impl->getSuperClass()) || |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4686 | (Super && Impl->getSuperClass() && |
| 4687 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 4688 | Impl->getSuperClass()))) { |
| 4689 | Importer.ToDiag(Impl->getLocation(), |
| 4690 | diag::err_odr_objc_superclass_inconsistent) |
| 4691 | << Iface->getDeclName(); |
| 4692 | // FIXME: It would be nice to have the location of the superclass |
| 4693 | // below. |
| 4694 | if (Impl->getSuperClass()) |
| 4695 | Importer.ToDiag(Impl->getLocation(), |
| 4696 | diag::note_odr_objc_superclass) |
| 4697 | << Impl->getSuperClass()->getDeclName(); |
| 4698 | else |
| 4699 | Importer.ToDiag(Impl->getLocation(), |
| 4700 | diag::note_odr_objc_missing_superclass); |
| 4701 | if (D->getSuperClass()) |
| 4702 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4703 | diag::note_odr_objc_superclass) |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4704 | << D->getSuperClass()->getDeclName(); |
| 4705 | else |
| 4706 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4707 | diag::note_odr_objc_missing_superclass); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4708 | |
| 4709 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4710 | } |
| 4711 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4712 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4713 | // Import all of the members of this @implementation. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4714 | if (Error Err = ImportDeclContext(D)) |
| 4715 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4716 | |
| 4717 | return Impl; |
| 4718 | } |
| 4719 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4720 | ExpectedDecl ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4721 | // Import the major distinguishing characteristics of an @property. |
| 4722 | DeclContext *DC, *LexicalDC; |
| 4723 | DeclarationName Name; |
| 4724 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4725 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4726 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4727 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4728 | if (ToD) |
| 4729 | return ToD; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4730 | |
| 4731 | // Check whether we have already imported this property. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4732 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4733 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4734 | for (auto *FoundDecl : FoundDecls) { |
| 4735 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4736 | // Check property types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4737 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4738 | FoundProp->getType())) { |
| 4739 | Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent) |
| 4740 | << Name << D->getType() << FoundProp->getType(); |
| 4741 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 4742 | << FoundProp->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4743 | |
| 4744 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4745 | } |
| 4746 | |
| 4747 | // FIXME: Check property attributes, getters, setters, etc.? |
| 4748 | |
| 4749 | // Consider these properties to be equivalent. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4750 | Importer.MapImported(D, FoundProp); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4751 | return FoundProp; |
| 4752 | } |
| 4753 | } |
| 4754 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4755 | QualType ToType; |
| 4756 | TypeSourceInfo *ToTypeSourceInfo; |
| 4757 | SourceLocation ToAtLoc, ToLParenLoc; |
| 4758 | if (auto Imp = importSeq( |
| 4759 | D->getType(), D->getTypeSourceInfo(), D->getAtLoc(), D->getLParenLoc())) |
| 4760 | std::tie(ToType, ToTypeSourceInfo, ToAtLoc, ToLParenLoc) = *Imp; |
| 4761 | else |
| 4762 | return Imp.takeError(); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4763 | |
| 4764 | // Create the new property. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4765 | ObjCPropertyDecl *ToProperty; |
| 4766 | if (GetImportedOrCreateDecl( |
| 4767 | ToProperty, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4768 | Name.getAsIdentifierInfo(), ToAtLoc, |
| 4769 | ToLParenLoc, ToType, |
| 4770 | ToTypeSourceInfo, D->getPropertyImplementation())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4771 | return ToProperty; |
| 4772 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4773 | Selector ToGetterName, ToSetterName; |
| 4774 | SourceLocation ToGetterNameLoc, ToSetterNameLoc; |
| 4775 | ObjCMethodDecl *ToGetterMethodDecl, *ToSetterMethodDecl; |
| 4776 | ObjCIvarDecl *ToPropertyIvarDecl; |
| 4777 | if (auto Imp = importSeq( |
| 4778 | D->getGetterName(), D->getSetterName(), |
| 4779 | D->getGetterNameLoc(), D->getSetterNameLoc(), |
| 4780 | D->getGetterMethodDecl(), D->getSetterMethodDecl(), |
| 4781 | D->getPropertyIvarDecl())) |
| 4782 | std::tie( |
| 4783 | ToGetterName, ToSetterName, |
| 4784 | ToGetterNameLoc, ToSetterNameLoc, |
| 4785 | ToGetterMethodDecl, ToSetterMethodDecl, |
| 4786 | ToPropertyIvarDecl) = *Imp; |
| 4787 | else |
| 4788 | return Imp.takeError(); |
| 4789 | |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4790 | ToProperty->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4791 | LexicalDC->addDeclInternal(ToProperty); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4792 | |
| 4793 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 4794 | ToProperty->setPropertyAttributesAsWritten( |
| 4795 | D->getPropertyAttributesAsWritten()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4796 | ToProperty->setGetterName(ToGetterName, ToGetterNameLoc); |
| 4797 | ToProperty->setSetterName(ToSetterName, ToSetterNameLoc); |
| 4798 | ToProperty->setGetterMethodDecl(ToGetterMethodDecl); |
| 4799 | ToProperty->setSetterMethodDecl(ToSetterMethodDecl); |
| 4800 | ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4801 | return ToProperty; |
| 4802 | } |
| 4803 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4804 | ExpectedDecl |
| 4805 | ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 4806 | ObjCPropertyDecl *Property; |
| 4807 | if (Error Err = importInto(Property, D->getPropertyDecl())) |
| 4808 | return std::move(Err); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4809 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4810 | DeclContext *DC, *LexicalDC; |
| 4811 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4812 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4813 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4814 | auto *InImpl = cast<ObjCImplDecl>(LexicalDC); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4815 | |
| 4816 | // Import the ivar (for an @synthesize). |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4817 | ObjCIvarDecl *Ivar = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4818 | if (Error Err = importInto(Ivar, D->getPropertyIvarDecl())) |
| 4819 | return std::move(Err); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4820 | |
| 4821 | ObjCPropertyImplDecl *ToImpl |
Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 4822 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 4823 | Property->getQueryKind()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4824 | if (!ToImpl) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4825 | SourceLocation ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc; |
| 4826 | if (auto Imp = importSeq( |
| 4827 | D->getBeginLoc(), D->getLocation(), D->getPropertyIvarDeclLoc())) |
| 4828 | std::tie(ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc) = *Imp; |
| 4829 | else |
| 4830 | return Imp.takeError(); |
| 4831 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4832 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4833 | ToBeginLoc, |
| 4834 | ToLocation, Property, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4835 | D->getPropertyImplementation(), Ivar, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4836 | ToPropertyIvarDeclLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4837 | return ToImpl; |
| 4838 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4839 | ToImpl->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4840 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4841 | } else { |
| 4842 | // Check that we have the same kind of property implementation (@synthesize |
| 4843 | // vs. @dynamic). |
| 4844 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4845 | Importer.ToDiag(ToImpl->getLocation(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4846 | diag::err_odr_objc_property_impl_kind_inconsistent) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4847 | << Property->getDeclName() |
| 4848 | << (ToImpl->getPropertyImplementation() |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4849 | == ObjCPropertyImplDecl::Dynamic); |
| 4850 | Importer.FromDiag(D->getLocation(), |
| 4851 | diag::note_odr_objc_property_impl_kind) |
| 4852 | << D->getPropertyDecl()->getDeclName() |
| 4853 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4854 | |
| 4855 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4856 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4857 | |
| 4858 | // For @synthesize, check that we have the same |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4859 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 4860 | Ivar != ToImpl->getPropertyIvarDecl()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4861 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4862 | diag::err_odr_objc_synthesize_ivar_inconsistent) |
| 4863 | << Property->getDeclName() |
| 4864 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 4865 | << Ivar->getDeclName(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4866 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4867 | diag::note_odr_objc_synthesize_ivar_here) |
| 4868 | << D->getPropertyIvarDecl()->getDeclName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4869 | |
| 4870 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4871 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4872 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4873 | // Merge the existing implementation with the new implementation. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4874 | Importer.MapImported(D, ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4875 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4876 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4877 | return ToImpl; |
| 4878 | } |
| 4879 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4880 | ExpectedDecl |
| 4881 | ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4882 | // For template arguments, we adopt the translation unit as our declaration |
| 4883 | // context. This context will be fixed when the actual template declaration |
| 4884 | // is created. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4885 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4886 | // FIXME: Import default argument. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4887 | |
| 4888 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 4889 | if (!BeginLocOrErr) |
| 4890 | return BeginLocOrErr.takeError(); |
| 4891 | |
| 4892 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 4893 | if (!LocationOrErr) |
| 4894 | return LocationOrErr.takeError(); |
| 4895 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4896 | TemplateTypeParmDecl *ToD = nullptr; |
| 4897 | (void)GetImportedOrCreateDecl( |
| 4898 | ToD, D, Importer.getToContext(), |
| 4899 | Importer.getToContext().getTranslationUnitDecl(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4900 | *BeginLocOrErr, *LocationOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4901 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), |
| 4902 | D->wasDeclaredWithTypename(), D->isParameterPack()); |
| 4903 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4904 | } |
| 4905 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4906 | ExpectedDecl |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4907 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4908 | DeclarationName ToDeclName; |
| 4909 | SourceLocation ToLocation, ToInnerLocStart; |
| 4910 | QualType ToType; |
| 4911 | TypeSourceInfo *ToTypeSourceInfo; |
| 4912 | if (auto Imp = importSeq( |
| 4913 | D->getDeclName(), D->getLocation(), D->getType(), D->getTypeSourceInfo(), |
| 4914 | D->getInnerLocStart())) |
| 4915 | std::tie( |
| 4916 | ToDeclName, ToLocation, ToType, ToTypeSourceInfo, |
| 4917 | ToInnerLocStart) = *Imp; |
| 4918 | else |
| 4919 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4920 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4921 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4922 | |
| 4923 | NonTypeTemplateParmDecl *ToD = nullptr; |
| 4924 | (void)GetImportedOrCreateDecl( |
| 4925 | ToD, D, Importer.getToContext(), |
| 4926 | Importer.getToContext().getTranslationUnitDecl(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4927 | ToInnerLocStart, ToLocation, D->getDepth(), |
| 4928 | D->getPosition(), ToDeclName.getAsIdentifierInfo(), ToType, |
| 4929 | D->isParameterPack(), ToTypeSourceInfo); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4930 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4931 | } |
| 4932 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4933 | ExpectedDecl |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4934 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 4935 | // Import the name of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4936 | auto NameOrErr = import(D->getDeclName()); |
| 4937 | if (!NameOrErr) |
| 4938 | return NameOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4939 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4940 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4941 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 4942 | if (!LocationOrErr) |
| 4943 | return LocationOrErr.takeError(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4944 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4945 | // Import template parameters. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4946 | auto TemplateParamsOrErr = ImportTemplateParameterList( |
| 4947 | D->getTemplateParameters()); |
| 4948 | if (!TemplateParamsOrErr) |
| 4949 | return TemplateParamsOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4950 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4951 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4952 | |
| 4953 | TemplateTemplateParmDecl *ToD = nullptr; |
| 4954 | (void)GetImportedOrCreateDecl( |
| 4955 | ToD, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4956 | Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr, |
| 4957 | D->getDepth(), D->getPosition(), D->isParameterPack(), |
| 4958 | (*NameOrErr).getAsIdentifierInfo(), |
| 4959 | *TemplateParamsOrErr); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4960 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4961 | } |
| 4962 | |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4963 | // Returns the definition for a (forward) declaration of a ClassTemplateDecl, if |
| 4964 | // it has any definition in the redecl chain. |
| 4965 | static ClassTemplateDecl *getDefinition(ClassTemplateDecl *D) { |
| 4966 | CXXRecordDecl *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); |
| 4967 | if (!ToTemplatedDef) |
| 4968 | return nullptr; |
| 4969 | ClassTemplateDecl *TemplateWithDef = |
| 4970 | ToTemplatedDef->getDescribedClassTemplate(); |
| 4971 | return TemplateWithDef; |
| 4972 | } |
| 4973 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4974 | ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4975 | bool IsFriend = D->getFriendObjectKind() != Decl::FOK_None; |
| 4976 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4977 | // If this record has a definition in the translation unit we're coming from, |
| 4978 | // but this particular declaration is not that definition, import the |
| 4979 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4980 | auto *Definition = |
| 4981 | cast_or_null<CXXRecordDecl>(D->getTemplatedDecl()->getDefinition()); |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4982 | if (Definition && Definition != D->getTemplatedDecl() && !IsFriend) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4983 | if (ExpectedDecl ImportedDefOrErr = import( |
| 4984 | Definition->getDescribedClassTemplate())) |
| 4985 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4986 | else |
| 4987 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4988 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4989 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4990 | // Import the major distinguishing characteristics of this class template. |
| 4991 | DeclContext *DC, *LexicalDC; |
| 4992 | DeclarationName Name; |
| 4993 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4994 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4995 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4996 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4997 | if (ToD) |
| 4998 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4999 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5000 | // We may already have a template of the same name; try to find and match it. |
| 5001 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5002 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 5003 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 5004 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5005 | for (auto *FoundDecl : FoundDecls) { |
| 5006 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5007 | continue; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5008 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5009 | Decl *Found = FoundDecl; |
| 5010 | if (auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found)) { |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5011 | |
| 5012 | // The class to be imported is a definition. |
| 5013 | if (D->isThisDeclarationADefinition()) { |
| 5014 | // Lookup will find the fwd decl only if that is more recent than the |
| 5015 | // definition. So, try to get the definition if that is available in |
| 5016 | // the redecl chain. |
| 5017 | ClassTemplateDecl *TemplateWithDef = getDefinition(FoundTemplate); |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5018 | if (TemplateWithDef) |
| 5019 | FoundTemplate = TemplateWithDef; |
| 5020 | else |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5021 | continue; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5022 | } |
| 5023 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5024 | if (IsStructuralMatch(D, FoundTemplate)) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5025 | if (!IsFriend) { |
| 5026 | Importer.MapImported(D->getTemplatedDecl(), |
| 5027 | FoundTemplate->getTemplatedDecl()); |
| 5028 | return Importer.MapImported(D, FoundTemplate); |
| 5029 | } |
Aleksei Sidorin | 761c224 | 2018-05-15 11:09:07 +0000 | [diff] [blame] | 5030 | |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5031 | continue; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5032 | } |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5033 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5034 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5035 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5036 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5037 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5038 | if (!ConflictingDecls.empty()) { |
| 5039 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5040 | ConflictingDecls.data(), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5041 | ConflictingDecls.size()); |
| 5042 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5043 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5044 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5045 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5046 | } |
| 5047 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5048 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); |
| 5049 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5050 | // Create the declaration that is being templated. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5051 | CXXRecordDecl *ToTemplated; |
| 5052 | if (Error Err = importInto(ToTemplated, FromTemplated)) |
| 5053 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5054 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5055 | // Create the class template declaration itself. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5056 | auto TemplateParamsOrErr = ImportTemplateParameterList( |
| 5057 | D->getTemplateParameters()); |
| 5058 | if (!TemplateParamsOrErr) |
| 5059 | return TemplateParamsOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5060 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5061 | ClassTemplateDecl *D2; |
| 5062 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5063 | *TemplateParamsOrErr, ToTemplated)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5064 | return D2; |
| 5065 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5066 | ToTemplated->setDescribedClassTemplate(D2); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5067 | |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5068 | if (ToTemplated->getPreviousDecl()) { |
| 5069 | assert( |
| 5070 | ToTemplated->getPreviousDecl()->getDescribedClassTemplate() && |
| 5071 | "Missing described template"); |
| 5072 | D2->setPreviousDecl( |
| 5073 | ToTemplated->getPreviousDecl()->getDescribedClassTemplate()); |
| 5074 | } |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5075 | D2->setAccess(D->getAccess()); |
| 5076 | D2->setLexicalDeclContext(LexicalDC); |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5077 | if (!IsFriend) |
| 5078 | LexicalDC->addDeclInternal(D2); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5079 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5080 | if (FromTemplated->isCompleteDefinition() && |
| 5081 | !ToTemplated->isCompleteDefinition()) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5082 | // FIXME: Import definition! |
| 5083 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5084 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5085 | return D2; |
| 5086 | } |
| 5087 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5088 | ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5089 | ClassTemplateSpecializationDecl *D) { |
| 5090 | // If this record has a definition in the translation unit we're coming from, |
| 5091 | // but this particular declaration is not that definition, import the |
| 5092 | // definition and map to that. |
| 5093 | TagDecl *Definition = D->getDefinition(); |
| 5094 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5095 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 5096 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5097 | else |
| 5098 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5099 | } |
| 5100 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5101 | ClassTemplateDecl *ClassTemplate; |
| 5102 | if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate())) |
| 5103 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5104 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5105 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5106 | DeclContext *DC, *LexicalDC; |
| 5107 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5108 | return std::move(Err); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5109 | |
| 5110 | // Import template arguments. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5111 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5112 | if (Error Err = ImportTemplateArguments( |
| 5113 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5114 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5115 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5116 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5117 | void *InsertPos = nullptr; |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5118 | ClassTemplateSpecializationDecl *D2 = nullptr; |
| 5119 | ClassTemplatePartialSpecializationDecl *PartialSpec = |
| 5120 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D); |
| 5121 | if (PartialSpec) |
| 5122 | D2 = ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos); |
| 5123 | else |
| 5124 | D2 = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
| 5125 | ClassTemplateSpecializationDecl * const PrevDecl = D2; |
| 5126 | RecordDecl *FoundDef = D2 ? D2->getDefinition() : nullptr; |
| 5127 | if (FoundDef) { |
| 5128 | if (!D->isCompleteDefinition()) { |
| 5129 | // The "From" translation unit only had a forward declaration; call it |
| 5130 | // the same declaration. |
| 5131 | // TODO Handle the redecl chain properly! |
| 5132 | return Importer.MapImported(D, FoundDef); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5133 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5134 | |
| 5135 | if (IsStructuralMatch(D, FoundDef)) { |
| 5136 | |
| 5137 | Importer.MapImported(D, FoundDef); |
| 5138 | |
| 5139 | // Import those those default field initializers which have been |
| 5140 | // instantiated in the "From" context, but not in the "To" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5141 | for (auto *FromField : D->fields()) { |
| 5142 | auto ToOrErr = import(FromField); |
| 5143 | if (!ToOrErr) |
| 5144 | // FIXME: return the error? |
| 5145 | consumeError(ToOrErr.takeError()); |
| 5146 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5147 | |
| 5148 | // Import those methods which have been instantiated in the |
| 5149 | // "From" context, but not in the "To" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5150 | for (CXXMethodDecl *FromM : D->methods()) { |
| 5151 | auto ToOrErr = import(FromM); |
| 5152 | if (!ToOrErr) |
| 5153 | // FIXME: return the error? |
| 5154 | consumeError(ToOrErr.takeError()); |
| 5155 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5156 | |
| 5157 | // TODO Import instantiated default arguments. |
| 5158 | // TODO Import instantiated exception specifications. |
| 5159 | // |
| 5160 | // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint what |
| 5161 | // else could be fused during an AST merge. |
| 5162 | |
| 5163 | return FoundDef; |
| 5164 | } |
| 5165 | } else { // We either couldn't find any previous specialization in the "To" |
| 5166 | // context, or we found one but without definition. Let's create a |
| 5167 | // new specialization and register that at the class template. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5168 | |
| 5169 | // Import the location of this declaration. |
| 5170 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5171 | if (!BeginLocOrErr) |
| 5172 | return BeginLocOrErr.takeError(); |
| 5173 | ExpectedSLoc IdLocOrErr = import(D->getLocation()); |
| 5174 | if (!IdLocOrErr) |
| 5175 | return IdLocOrErr.takeError(); |
| 5176 | |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5177 | if (PartialSpec) { |
| 5178 | // Import TemplateArgumentListInfo. |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5179 | TemplateArgumentListInfo ToTAInfo; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5180 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5181 | if (Error Err = ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) |
| 5182 | return std::move(Err); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5183 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5184 | QualType CanonInjType; |
| 5185 | if (Error Err = importInto( |
| 5186 | CanonInjType, PartialSpec->getInjectedSpecializationType())) |
| 5187 | return std::move(Err); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5188 | CanonInjType = CanonInjType.getCanonicalType(); |
| 5189 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5190 | auto ToTPListOrErr = ImportTemplateParameterList( |
| 5191 | PartialSpec->getTemplateParameters()); |
| 5192 | if (!ToTPListOrErr) |
| 5193 | return ToTPListOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5194 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5195 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5196 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| 5197 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, ClassTemplate, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5198 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5199 | ToTAInfo, CanonInjType, |
| 5200 | cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl))) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5201 | return D2; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5202 | |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5203 | // Update InsertPos, because preceding import calls may have invalidated |
| 5204 | // it by adding new specializations. |
| 5205 | if (!ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos)) |
| 5206 | // Add this partial specialization to the class template. |
| 5207 | ClassTemplate->AddPartialSpecialization( |
| 5208 | cast<ClassTemplatePartialSpecializationDecl>(D2), InsertPos); |
| 5209 | |
| 5210 | } else { // Not a partial specialization. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5211 | if (GetImportedOrCreateDecl( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5212 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| 5213 | *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs, |
| 5214 | PrevDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5215 | return D2; |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5216 | |
| 5217 | // Update InsertPos, because preceding import calls may have invalidated |
| 5218 | // it by adding new specializations. |
| 5219 | if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos)) |
| 5220 | // Add this specialization to the class template. |
| 5221 | ClassTemplate->AddSpecialization(D2, InsertPos); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5222 | } |
| 5223 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5224 | D2->setSpecializationKind(D->getSpecializationKind()); |
| 5225 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5226 | // Import the qualifier, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5227 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5228 | D2->setQualifierInfo(*LocOrErr); |
| 5229 | else |
| 5230 | return LocOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5231 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5232 | if (auto *TSI = D->getTypeAsWritten()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5233 | if (auto TInfoOrErr = import(TSI)) |
| 5234 | D2->setTypeAsWritten(*TInfoOrErr); |
| 5235 | else |
| 5236 | return TInfoOrErr.takeError(); |
| 5237 | |
| 5238 | if (auto LocOrErr = import(D->getTemplateKeywordLoc())) |
| 5239 | D2->setTemplateKeywordLoc(*LocOrErr); |
| 5240 | else |
| 5241 | return LocOrErr.takeError(); |
| 5242 | |
| 5243 | if (auto LocOrErr = import(D->getExternLoc())) |
| 5244 | D2->setExternLoc(*LocOrErr); |
| 5245 | else |
| 5246 | return LocOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5247 | } |
| 5248 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5249 | if (D->getPointOfInstantiation().isValid()) { |
| 5250 | if (auto POIOrErr = import(D->getPointOfInstantiation())) |
| 5251 | D2->setPointOfInstantiation(*POIOrErr); |
| 5252 | else |
| 5253 | return POIOrErr.takeError(); |
| 5254 | } |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5255 | |
| 5256 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 5257 | |
Gabor Marton | b14056b | 2018-05-25 11:21:24 +0000 | [diff] [blame] | 5258 | // Set the context of this specialization/instantiation. |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5259 | D2->setLexicalDeclContext(LexicalDC); |
Gabor Marton | b14056b | 2018-05-25 11:21:24 +0000 | [diff] [blame] | 5260 | |
| 5261 | // Add to the DC only if it was an explicit specialization/instantiation. |
| 5262 | if (D2->isExplicitInstantiationOrSpecialization()) { |
| 5263 | LexicalDC->addDeclInternal(D2); |
| 5264 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5265 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5266 | if (D->isCompleteDefinition()) |
| 5267 | if (Error Err = ImportDefinition(D, D2)) |
| 5268 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5269 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5270 | return D2; |
| 5271 | } |
| 5272 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5273 | ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5274 | // If this variable has a definition in the translation unit we're coming |
| 5275 | // from, |
| 5276 | // but this particular declaration is not that definition, import the |
| 5277 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5278 | auto *Definition = |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5279 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); |
| 5280 | if (Definition && Definition != D->getTemplatedDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5281 | if (ExpectedDecl ImportedDefOrErr = import( |
| 5282 | Definition->getDescribedVarTemplate())) |
| 5283 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5284 | else |
| 5285 | return ImportedDefOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5286 | } |
| 5287 | |
| 5288 | // Import the major distinguishing characteristics of this variable template. |
| 5289 | DeclContext *DC, *LexicalDC; |
| 5290 | DeclarationName Name; |
| 5291 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5292 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5293 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5294 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5295 | if (ToD) |
| 5296 | return ToD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5297 | |
| 5298 | // We may already have a template of the same name; try to find and match it. |
| 5299 | assert(!DC->isFunctionOrMethod() && |
| 5300 | "Variable templates cannot be declared at function scope"); |
| 5301 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 5302 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 5303 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5304 | for (auto *FoundDecl : FoundDecls) { |
| 5305 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5306 | continue; |
| 5307 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5308 | Decl *Found = FoundDecl; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5309 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5310 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 5311 | // The variable templates structurally match; call it the same template. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5312 | Importer.MapImported(D->getTemplatedDecl(), |
| 5313 | FoundTemplate->getTemplatedDecl()); |
| 5314 | return Importer.MapImported(D, FoundTemplate); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5315 | } |
| 5316 | } |
| 5317 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5318 | ConflictingDecls.push_back(FoundDecl); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5319 | } |
| 5320 | |
| 5321 | if (!ConflictingDecls.empty()) { |
| 5322 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 5323 | ConflictingDecls.data(), |
| 5324 | ConflictingDecls.size()); |
| 5325 | } |
| 5326 | |
| 5327 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5328 | // FIXME: Is it possible to get other error than name conflict? |
| 5329 | // (Put this `if` into the previous `if`?) |
| 5330 | return make_error<ImportError>(ImportError::NameConflict); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5331 | |
| 5332 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 5333 | |
| 5334 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5335 | // FIXME: Value not used? |
| 5336 | ExpectedType TypeOrErr = import(DTemplated->getType()); |
| 5337 | if (!TypeOrErr) |
| 5338 | return TypeOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5339 | |
| 5340 | // Create the declaration that is being templated. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5341 | VarDecl *ToTemplated; |
| 5342 | if (Error Err = importInto(ToTemplated, DTemplated)) |
| 5343 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5344 | |
| 5345 | // Create the variable template declaration itself. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5346 | auto TemplateParamsOrErr = ImportTemplateParameterList( |
| 5347 | D->getTemplateParameters()); |
| 5348 | if (!TemplateParamsOrErr) |
| 5349 | return TemplateParamsOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5350 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5351 | VarTemplateDecl *ToVarTD; |
| 5352 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5353 | Name, *TemplateParamsOrErr, ToTemplated)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5354 | return ToVarTD; |
| 5355 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5356 | ToTemplated->setDescribedVarTemplate(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5357 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5358 | ToVarTD->setAccess(D->getAccess()); |
| 5359 | ToVarTD->setLexicalDeclContext(LexicalDC); |
| 5360 | LexicalDC->addDeclInternal(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5361 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5362 | if (DTemplated->isThisDeclarationADefinition() && |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5363 | !ToTemplated->isThisDeclarationADefinition()) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5364 | // FIXME: Import definition! |
| 5365 | } |
| 5366 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5367 | return ToVarTD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5368 | } |
| 5369 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5370 | ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5371 | VarTemplateSpecializationDecl *D) { |
| 5372 | // If this record has a definition in the translation unit we're coming from, |
| 5373 | // but this particular declaration is not that definition, import the |
| 5374 | // definition and map to that. |
| 5375 | VarDecl *Definition = D->getDefinition(); |
| 5376 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5377 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 5378 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5379 | else |
| 5380 | return ImportedDefOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5381 | } |
| 5382 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5383 | VarTemplateDecl *VarTemplate; |
| 5384 | if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate())) |
| 5385 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5386 | |
| 5387 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5388 | DeclContext *DC, *LexicalDC; |
| 5389 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5390 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5391 | |
| 5392 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5393 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5394 | if (!BeginLocOrErr) |
| 5395 | return BeginLocOrErr.takeError(); |
| 5396 | |
| 5397 | auto IdLocOrErr = import(D->getLocation()); |
| 5398 | if (!IdLocOrErr) |
| 5399 | return IdLocOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5400 | |
| 5401 | // Import template arguments. |
| 5402 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5403 | if (Error Err = ImportTemplateArguments( |
| 5404 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5405 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5406 | |
| 5407 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5408 | void *InsertPos = nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5409 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 5410 | TemplateArgs, InsertPos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5411 | if (D2) { |
| 5412 | // We already have a variable template specialization with these template |
| 5413 | // arguments. |
| 5414 | |
| 5415 | // FIXME: Check for specialization vs. instantiation errors. |
| 5416 | |
| 5417 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 5418 | if (!D->isThisDeclarationADefinition() || |
| 5419 | IsStructuralMatch(D, FoundDef)) { |
| 5420 | // The record types structurally match, or the "from" translation |
| 5421 | // unit only had a forward declaration anyway; call it the same |
| 5422 | // variable. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5423 | return Importer.MapImported(D, FoundDef); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5424 | } |
| 5425 | } |
| 5426 | } else { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5427 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5428 | QualType T; |
| 5429 | if (Error Err = importInto(T, D->getType())) |
| 5430 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5431 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5432 | auto TInfoOrErr = import(D->getTypeSourceInfo()); |
| 5433 | if (!TInfoOrErr) |
| 5434 | return TInfoOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5435 | |
| 5436 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5437 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5438 | D->getTemplateArgsInfo(), ToTAInfo)) |
| 5439 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5440 | |
| 5441 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5442 | // Create a new specialization. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5443 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { |
| 5444 | // Import TemplateArgumentListInfo |
| 5445 | TemplateArgumentListInfo ArgInfos; |
| 5446 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); |
| 5447 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5448 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5449 | *FromTAArgsAsWritten, ArgInfos)) |
| 5450 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5451 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5452 | auto ToTPListOrErr = ImportTemplateParameterList( |
| 5453 | FromPartial->getTemplateParameters()); |
| 5454 | if (!ToTPListOrErr) |
| 5455 | return ToTPListOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5456 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5457 | PartVarSpecDecl *ToPartial; |
| 5458 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5459 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, |
| 5460 | VarTemplate, T, *TInfoOrErr, |
| 5461 | D->getStorageClass(), TemplateArgs, ArgInfos)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5462 | return ToPartial; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5463 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5464 | if (Expected<PartVarSpecDecl *> ToInstOrErr = import( |
| 5465 | FromPartial->getInstantiatedFromMember())) |
| 5466 | ToPartial->setInstantiatedFromMember(*ToInstOrErr); |
| 5467 | else |
| 5468 | return ToInstOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5469 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5470 | if (FromPartial->isMemberSpecialization()) |
| 5471 | ToPartial->setMemberSpecialization(); |
| 5472 | |
| 5473 | D2 = ToPartial; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5474 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5475 | } else { // Full specialization |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5476 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, |
| 5477 | *BeginLocOrErr, *IdLocOrErr, VarTemplate, |
| 5478 | T, *TInfoOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5479 | D->getStorageClass(), TemplateArgs)) |
| 5480 | return D2; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5481 | } |
| 5482 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5483 | if (D->getPointOfInstantiation().isValid()) { |
| 5484 | if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation())) |
| 5485 | D2->setPointOfInstantiation(*POIOrErr); |
| 5486 | else |
| 5487 | return POIOrErr.takeError(); |
| 5488 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5489 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5490 | D2->setSpecializationKind(D->getSpecializationKind()); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5491 | D2->setTemplateArgsInfo(ToTAInfo); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5492 | |
| 5493 | // Add this specialization to the class template. |
| 5494 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 5495 | |
| 5496 | // Import the qualifier, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5497 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5498 | D2->setQualifierInfo(*LocOrErr); |
| 5499 | else |
| 5500 | return LocOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5501 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5502 | if (D->isConstexpr()) |
| 5503 | D2->setConstexpr(true); |
| 5504 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5505 | // Add the specialization to this context. |
| 5506 | D2->setLexicalDeclContext(LexicalDC); |
| 5507 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5508 | |
| 5509 | D2->setAccess(D->getAccess()); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5510 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5511 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5512 | if (Error Err = ImportInitializer(D, D2)) |
| 5513 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5514 | |
| 5515 | return D2; |
| 5516 | } |
| 5517 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5518 | ExpectedDecl |
| 5519 | ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5520 | DeclContext *DC, *LexicalDC; |
| 5521 | DeclarationName Name; |
| 5522 | SourceLocation Loc; |
| 5523 | NamedDecl *ToD; |
| 5524 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5525 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5526 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5527 | |
| 5528 | if (ToD) |
| 5529 | return ToD; |
| 5530 | |
| 5531 | // Try to find a function in our own ("to") context with the same name, same |
| 5532 | // type, and in the same context as the function we're importing. |
| 5533 | if (!LexicalDC->isFunctionOrMethod()) { |
| 5534 | unsigned IDNS = Decl::IDNS_Ordinary; |
| 5535 | SmallVector<NamedDecl *, 2> FoundDecls; |
| 5536 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5537 | for (auto *FoundDecl : FoundDecls) { |
| 5538 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5539 | continue; |
| 5540 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5541 | if (auto *FoundFunction = |
| 5542 | dyn_cast<FunctionTemplateDecl>(FoundDecl)) { |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5543 | if (FoundFunction->hasExternalFormalLinkage() && |
| 5544 | D->hasExternalFormalLinkage()) { |
| 5545 | if (IsStructuralMatch(D, FoundFunction)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5546 | Importer.MapImported(D, FoundFunction); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5547 | // FIXME: Actually try to merge the body and other attributes. |
| 5548 | return FoundFunction; |
| 5549 | } |
| 5550 | } |
| 5551 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5552 | // TODO: handle conflicting names |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5553 | } |
| 5554 | } |
| 5555 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5556 | auto ParamsOrErr = ImportTemplateParameterList( |
| 5557 | D->getTemplateParameters()); |
| 5558 | if (!ParamsOrErr) |
| 5559 | return ParamsOrErr.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5560 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5561 | FunctionDecl *TemplatedFD; |
| 5562 | if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl())) |
| 5563 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5564 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5565 | FunctionTemplateDecl *ToFunc; |
| 5566 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5567 | *ParamsOrErr, TemplatedFD)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5568 | return ToFunc; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5569 | |
| 5570 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); |
| 5571 | ToFunc->setAccess(D->getAccess()); |
| 5572 | ToFunc->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5573 | |
| 5574 | LexicalDC->addDeclInternal(ToFunc); |
| 5575 | return ToFunc; |
| 5576 | } |
| 5577 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5578 | //---------------------------------------------------------------------------- |
| 5579 | // Import Statements |
| 5580 | //---------------------------------------------------------------------------- |
| 5581 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5582 | ExpectedStmt ASTNodeImporter::VisitStmt(Stmt *S) { |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5583 | Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node) |
| 5584 | << S->getStmtClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5585 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5586 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5587 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5588 | |
| 5589 | ExpectedStmt ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5590 | SmallVector<IdentifierInfo *, 4> Names; |
| 5591 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 5592 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5593 | // ToII is nullptr when no symbolic name is given for output operand |
| 5594 | // see ParseStmtAsm::ParseAsmOperandsOpt |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5595 | Names.push_back(ToII); |
| 5596 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5597 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5598 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 5599 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5600 | // ToII is nullptr when no symbolic name is given for input operand |
| 5601 | // see ParseStmtAsm::ParseAsmOperandsOpt |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5602 | Names.push_back(ToII); |
| 5603 | } |
| 5604 | |
| 5605 | SmallVector<StringLiteral *, 4> Clobbers; |
| 5606 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5607 | if (auto ClobberOrErr = import(S->getClobberStringLiteral(I))) |
| 5608 | Clobbers.push_back(*ClobberOrErr); |
| 5609 | else |
| 5610 | return ClobberOrErr.takeError(); |
| 5611 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5612 | } |
| 5613 | |
| 5614 | SmallVector<StringLiteral *, 4> Constraints; |
| 5615 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5616 | if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I))) |
| 5617 | Constraints.push_back(*OutputOrErr); |
| 5618 | else |
| 5619 | return OutputOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5620 | } |
| 5621 | |
| 5622 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5623 | if (auto InputOrErr = import(S->getInputConstraintLiteral(I))) |
| 5624 | Constraints.push_back(*InputOrErr); |
| 5625 | else |
| 5626 | return InputOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5627 | } |
| 5628 | |
| 5629 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5630 | if (Error Err = ImportContainerChecked(S->outputs(), Exprs)) |
| 5631 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5632 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5633 | if (Error Err = ImportArrayChecked( |
| 5634 | S->inputs(), Exprs.begin() + S->getNumOutputs())) |
| 5635 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5636 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5637 | ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc()); |
| 5638 | if (!AsmLocOrErr) |
| 5639 | return AsmLocOrErr.takeError(); |
| 5640 | auto AsmStrOrErr = import(S->getAsmString()); |
| 5641 | if (!AsmStrOrErr) |
| 5642 | return AsmStrOrErr.takeError(); |
| 5643 | ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc()); |
| 5644 | if (!RParenLocOrErr) |
| 5645 | return RParenLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5646 | |
| 5647 | return new (Importer.getToContext()) GCCAsmStmt( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5648 | Importer.getToContext(), |
| 5649 | *AsmLocOrErr, |
| 5650 | S->isSimple(), |
| 5651 | S->isVolatile(), |
| 5652 | S->getNumOutputs(), |
| 5653 | S->getNumInputs(), |
| 5654 | Names.data(), |
| 5655 | Constraints.data(), |
| 5656 | Exprs.data(), |
| 5657 | *AsmStrOrErr, |
| 5658 | S->getNumClobbers(), |
| 5659 | Clobbers.data(), |
| 5660 | *RParenLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5661 | } |
| 5662 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5663 | ExpectedStmt ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| 5664 | auto Imp = importSeq(S->getDeclGroup(), S->getBeginLoc(), S->getEndLoc()); |
| 5665 | if (!Imp) |
| 5666 | return Imp.takeError(); |
| 5667 | |
| 5668 | DeclGroupRef ToDG; |
| 5669 | SourceLocation ToBeginLoc, ToEndLoc; |
| 5670 | std::tie(ToDG, ToBeginLoc, ToEndLoc) = *Imp; |
| 5671 | |
| 5672 | return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5673 | } |
| 5674 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5675 | ExpectedStmt ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 5676 | ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc()); |
| 5677 | if (!ToSemiLocOrErr) |
| 5678 | return ToSemiLocOrErr.takeError(); |
| 5679 | return new (Importer.getToContext()) NullStmt( |
| 5680 | *ToSemiLocOrErr, S->hasLeadingEmptyMacro()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5681 | } |
| 5682 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5683 | ExpectedStmt ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5684 | SmallVector<Stmt *, 8> ToStmts(S->size()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5685 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5686 | if (Error Err = ImportContainerChecked(S->body(), ToStmts)) |
| 5687 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5688 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5689 | ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc()); |
| 5690 | if (!ToLBracLocOrErr) |
| 5691 | return ToLBracLocOrErr.takeError(); |
| 5692 | |
| 5693 | ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc()); |
| 5694 | if (!ToRBracLocOrErr) |
| 5695 | return ToRBracLocOrErr.takeError(); |
| 5696 | |
| 5697 | return CompoundStmt::Create( |
| 5698 | Importer.getToContext(), ToStmts, |
| 5699 | *ToLBracLocOrErr, *ToRBracLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5700 | } |
| 5701 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5702 | ExpectedStmt ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| 5703 | auto Imp = importSeq( |
| 5704 | S->getLHS(), S->getRHS(), S->getSubStmt(), S->getCaseLoc(), |
| 5705 | S->getEllipsisLoc(), S->getColonLoc()); |
| 5706 | if (!Imp) |
| 5707 | return Imp.takeError(); |
| 5708 | |
| 5709 | Expr *ToLHS, *ToRHS; |
| 5710 | Stmt *ToSubStmt; |
| 5711 | SourceLocation ToCaseLoc, ToEllipsisLoc, ToColonLoc; |
| 5712 | std::tie(ToLHS, ToRHS, ToSubStmt, ToCaseLoc, ToEllipsisLoc, ToColonLoc) = |
| 5713 | *Imp; |
| 5714 | |
Bruno Ricci | 5b3057175 | 2018-10-28 12:30:53 +0000 | [diff] [blame] | 5715 | auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS, |
| 5716 | ToCaseLoc, ToEllipsisLoc, ToColonLoc); |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5717 | ToStmt->setSubStmt(ToSubStmt); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5718 | |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5719 | return ToStmt; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5720 | } |
| 5721 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5722 | ExpectedStmt ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| 5723 | auto Imp = importSeq(S->getDefaultLoc(), S->getColonLoc(), S->getSubStmt()); |
| 5724 | if (!Imp) |
| 5725 | return Imp.takeError(); |
| 5726 | |
| 5727 | SourceLocation ToDefaultLoc, ToColonLoc; |
| 5728 | Stmt *ToSubStmt; |
| 5729 | std::tie(ToDefaultLoc, ToColonLoc, ToSubStmt) = *Imp; |
| 5730 | |
| 5731 | return new (Importer.getToContext()) DefaultStmt( |
| 5732 | ToDefaultLoc, ToColonLoc, ToSubStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5733 | } |
| 5734 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5735 | ExpectedStmt ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| 5736 | auto Imp = importSeq(S->getIdentLoc(), S->getDecl(), S->getSubStmt()); |
| 5737 | if (!Imp) |
| 5738 | return Imp.takeError(); |
| 5739 | |
| 5740 | SourceLocation ToIdentLoc; |
| 5741 | LabelDecl *ToLabelDecl; |
| 5742 | Stmt *ToSubStmt; |
| 5743 | std::tie(ToIdentLoc, ToLabelDecl, ToSubStmt) = *Imp; |
| 5744 | |
| 5745 | return new (Importer.getToContext()) LabelStmt( |
| 5746 | ToIdentLoc, ToLabelDecl, ToSubStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5747 | } |
| 5748 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5749 | ExpectedStmt ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { |
| 5750 | ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc()); |
| 5751 | if (!ToAttrLocOrErr) |
| 5752 | return ToAttrLocOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5753 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 5754 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5755 | if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs)) |
| 5756 | return std::move(Err); |
| 5757 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 5758 | if (!ToSubStmtOrErr) |
| 5759 | return ToSubStmtOrErr.takeError(); |
| 5760 | |
| 5761 | return AttributedStmt::Create( |
| 5762 | Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5763 | } |
| 5764 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5765 | ExpectedStmt ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| 5766 | auto Imp = importSeq( |
| 5767 | S->getIfLoc(), S->getInit(), S->getConditionVariable(), S->getCond(), |
| 5768 | S->getThen(), S->getElseLoc(), S->getElse()); |
| 5769 | if (!Imp) |
| 5770 | return Imp.takeError(); |
| 5771 | |
| 5772 | SourceLocation ToIfLoc, ToElseLoc; |
| 5773 | Stmt *ToInit, *ToThen, *ToElse; |
| 5774 | VarDecl *ToConditionVariable; |
| 5775 | Expr *ToCond; |
| 5776 | std::tie( |
| 5777 | ToIfLoc, ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, ToElse) = |
| 5778 | *Imp; |
| 5779 | |
Bruno Ricci | b1cc94b | 2018-10-27 21:12:20 +0000 | [diff] [blame] | 5780 | return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->isConstexpr(), |
| 5781 | ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, |
| 5782 | ToElse); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5783 | } |
| 5784 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5785 | ExpectedStmt ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
| 5786 | auto Imp = importSeq( |
| 5787 | S->getInit(), S->getConditionVariable(), S->getCond(), |
| 5788 | S->getBody(), S->getSwitchLoc()); |
| 5789 | if (!Imp) |
| 5790 | return Imp.takeError(); |
| 5791 | |
| 5792 | Stmt *ToInit, *ToBody; |
| 5793 | VarDecl *ToConditionVariable; |
| 5794 | Expr *ToCond; |
| 5795 | SourceLocation ToSwitchLoc; |
| 5796 | std::tie(ToInit, ToConditionVariable, ToCond, ToBody, ToSwitchLoc) = *Imp; |
| 5797 | |
Bruno Ricci | e2806f8 | 2018-10-29 16:12:37 +0000 | [diff] [blame] | 5798 | auto *ToStmt = SwitchStmt::Create(Importer.getToContext(), ToInit, |
| 5799 | ToConditionVariable, ToCond); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5800 | ToStmt->setBody(ToBody); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5801 | ToStmt->setSwitchLoc(ToSwitchLoc); |
| 5802 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5803 | // Now we have to re-chain the cases. |
| 5804 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 5805 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 5806 | SC = SC->getNextSwitchCase()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5807 | Expected<SwitchCase *> ToSCOrErr = import(SC); |
| 5808 | if (!ToSCOrErr) |
| 5809 | return ToSCOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5810 | if (LastChainedSwitchCase) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5811 | LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5812 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5813 | ToStmt->setSwitchCaseList(*ToSCOrErr); |
| 5814 | LastChainedSwitchCase = *ToSCOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5815 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5816 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5817 | return ToStmt; |
| 5818 | } |
| 5819 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5820 | ExpectedStmt ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| 5821 | auto Imp = importSeq( |
| 5822 | S->getConditionVariable(), S->getCond(), S->getBody(), S->getWhileLoc()); |
| 5823 | if (!Imp) |
| 5824 | return Imp.takeError(); |
| 5825 | |
| 5826 | VarDecl *ToConditionVariable; |
| 5827 | Expr *ToCond; |
| 5828 | Stmt *ToBody; |
| 5829 | SourceLocation ToWhileLoc; |
| 5830 | std::tie(ToConditionVariable, ToCond, ToBody, ToWhileLoc) = *Imp; |
| 5831 | |
Bruno Ricci | bacf751 | 2018-10-30 13:42:41 +0000 | [diff] [blame] | 5832 | return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond, |
| 5833 | ToBody, ToWhileLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5834 | } |
| 5835 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5836 | ExpectedStmt ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| 5837 | auto Imp = importSeq( |
| 5838 | S->getBody(), S->getCond(), S->getDoLoc(), S->getWhileLoc(), |
| 5839 | S->getRParenLoc()); |
| 5840 | if (!Imp) |
| 5841 | return Imp.takeError(); |
| 5842 | |
| 5843 | Stmt *ToBody; |
| 5844 | Expr *ToCond; |
| 5845 | SourceLocation ToDoLoc, ToWhileLoc, ToRParenLoc; |
| 5846 | std::tie(ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc) = *Imp; |
| 5847 | |
| 5848 | return new (Importer.getToContext()) DoStmt( |
| 5849 | ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5850 | } |
| 5851 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5852 | ExpectedStmt ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| 5853 | auto Imp = importSeq( |
| 5854 | S->getInit(), S->getCond(), S->getConditionVariable(), S->getInc(), |
| 5855 | S->getBody(), S->getForLoc(), S->getLParenLoc(), S->getRParenLoc()); |
| 5856 | if (!Imp) |
| 5857 | return Imp.takeError(); |
| 5858 | |
| 5859 | Stmt *ToInit; |
| 5860 | Expr *ToCond, *ToInc; |
| 5861 | VarDecl *ToConditionVariable; |
| 5862 | Stmt *ToBody; |
| 5863 | SourceLocation ToForLoc, ToLParenLoc, ToRParenLoc; |
| 5864 | std::tie( |
| 5865 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, |
| 5866 | ToLParenLoc, ToRParenLoc) = *Imp; |
| 5867 | |
| 5868 | return new (Importer.getToContext()) ForStmt( |
| 5869 | Importer.getToContext(), |
| 5870 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc, |
| 5871 | ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5872 | } |
| 5873 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5874 | ExpectedStmt ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| 5875 | auto Imp = importSeq(S->getLabel(), S->getGotoLoc(), S->getLabelLoc()); |
| 5876 | if (!Imp) |
| 5877 | return Imp.takeError(); |
| 5878 | |
| 5879 | LabelDecl *ToLabel; |
| 5880 | SourceLocation ToGotoLoc, ToLabelLoc; |
| 5881 | std::tie(ToLabel, ToGotoLoc, ToLabelLoc) = *Imp; |
| 5882 | |
| 5883 | return new (Importer.getToContext()) GotoStmt( |
| 5884 | ToLabel, ToGotoLoc, ToLabelLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5885 | } |
| 5886 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5887 | ExpectedStmt ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 5888 | auto Imp = importSeq(S->getGotoLoc(), S->getStarLoc(), S->getTarget()); |
| 5889 | if (!Imp) |
| 5890 | return Imp.takeError(); |
| 5891 | |
| 5892 | SourceLocation ToGotoLoc, ToStarLoc; |
| 5893 | Expr *ToTarget; |
| 5894 | std::tie(ToGotoLoc, ToStarLoc, ToTarget) = *Imp; |
| 5895 | |
| 5896 | return new (Importer.getToContext()) IndirectGotoStmt( |
| 5897 | ToGotoLoc, ToStarLoc, ToTarget); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5898 | } |
| 5899 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5900 | ExpectedStmt ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 5901 | ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc()); |
| 5902 | if (!ToContinueLocOrErr) |
| 5903 | return ToContinueLocOrErr.takeError(); |
| 5904 | return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5905 | } |
| 5906 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5907 | ExpectedStmt ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 5908 | auto ToBreakLocOrErr = import(S->getBreakLoc()); |
| 5909 | if (!ToBreakLocOrErr) |
| 5910 | return ToBreakLocOrErr.takeError(); |
| 5911 | return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5912 | } |
| 5913 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5914 | ExpectedStmt ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| 5915 | auto Imp = importSeq( |
| 5916 | S->getReturnLoc(), S->getRetValue(), S->getNRVOCandidate()); |
| 5917 | if (!Imp) |
| 5918 | return Imp.takeError(); |
| 5919 | |
| 5920 | SourceLocation ToReturnLoc; |
| 5921 | Expr *ToRetValue; |
| 5922 | const VarDecl *ToNRVOCandidate; |
| 5923 | std::tie(ToReturnLoc, ToRetValue, ToNRVOCandidate) = *Imp; |
| 5924 | |
Bruno Ricci | 023b1d1 | 2018-10-30 14:40:49 +0000 | [diff] [blame] | 5925 | return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue, |
| 5926 | ToNRVOCandidate); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5927 | } |
| 5928 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5929 | ExpectedStmt ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| 5930 | auto Imp = importSeq( |
| 5931 | S->getCatchLoc(), S->getExceptionDecl(), S->getHandlerBlock()); |
| 5932 | if (!Imp) |
| 5933 | return Imp.takeError(); |
| 5934 | |
| 5935 | SourceLocation ToCatchLoc; |
| 5936 | VarDecl *ToExceptionDecl; |
| 5937 | Stmt *ToHandlerBlock; |
| 5938 | std::tie(ToCatchLoc, ToExceptionDecl, ToHandlerBlock) = *Imp; |
| 5939 | |
| 5940 | return new (Importer.getToContext()) CXXCatchStmt ( |
| 5941 | ToCatchLoc, ToExceptionDecl, ToHandlerBlock); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5942 | } |
| 5943 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5944 | ExpectedStmt ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 5945 | ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc()); |
| 5946 | if (!ToTryLocOrErr) |
| 5947 | return ToTryLocOrErr.takeError(); |
| 5948 | |
| 5949 | ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock()); |
| 5950 | if (!ToTryBlockOrErr) |
| 5951 | return ToTryBlockOrErr.takeError(); |
| 5952 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5953 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 5954 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 5955 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5956 | if (auto ToHandlerOrErr = import(FromHandler)) |
| 5957 | ToHandlers[HI] = *ToHandlerOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5958 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5959 | return ToHandlerOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5960 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5961 | |
| 5962 | return CXXTryStmt::Create( |
| 5963 | Importer.getToContext(), *ToTryLocOrErr,*ToTryBlockOrErr, ToHandlers); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5964 | } |
| 5965 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5966 | ExpectedStmt ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
| 5967 | auto Imp1 = importSeq( |
| 5968 | S->getInit(), S->getRangeStmt(), S->getBeginStmt(), S->getEndStmt(), |
| 5969 | S->getCond(), S->getInc(), S->getLoopVarStmt(), S->getBody()); |
| 5970 | if (!Imp1) |
| 5971 | return Imp1.takeError(); |
| 5972 | auto Imp2 = importSeq( |
| 5973 | S->getForLoc(), S->getCoawaitLoc(), S->getColonLoc(), S->getRParenLoc()); |
| 5974 | if (!Imp2) |
| 5975 | return Imp2.takeError(); |
| 5976 | |
| 5977 | DeclStmt *ToRangeStmt, *ToBeginStmt, *ToEndStmt, *ToLoopVarStmt; |
| 5978 | Expr *ToCond, *ToInc; |
| 5979 | Stmt *ToInit, *ToBody; |
| 5980 | std::tie( |
| 5981 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 5982 | ToBody) = *Imp1; |
| 5983 | SourceLocation ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc; |
| 5984 | std::tie(ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc) = *Imp2; |
| 5985 | |
| 5986 | return new (Importer.getToContext()) CXXForRangeStmt( |
| 5987 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 5988 | ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5989 | } |
| 5990 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5991 | ExpectedStmt |
| 5992 | ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 5993 | auto Imp = importSeq( |
| 5994 | S->getElement(), S->getCollection(), S->getBody(), |
| 5995 | S->getForLoc(), S->getRParenLoc()); |
| 5996 | if (!Imp) |
| 5997 | return Imp.takeError(); |
| 5998 | |
| 5999 | Stmt *ToElement, *ToBody; |
| 6000 | Expr *ToCollection; |
| 6001 | SourceLocation ToForLoc, ToRParenLoc; |
| 6002 | std::tie(ToElement, ToCollection, ToBody, ToForLoc, ToRParenLoc) = *Imp; |
| 6003 | |
| 6004 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement, |
| 6005 | ToCollection, |
| 6006 | ToBody, |
| 6007 | ToForLoc, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6008 | ToRParenLoc); |
| 6009 | } |
| 6010 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6011 | ExpectedStmt ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 6012 | auto Imp = importSeq( |
| 6013 | S->getAtCatchLoc(), S->getRParenLoc(), S->getCatchParamDecl(), |
| 6014 | S->getCatchBody()); |
| 6015 | if (!Imp) |
| 6016 | return Imp.takeError(); |
| 6017 | |
| 6018 | SourceLocation ToAtCatchLoc, ToRParenLoc; |
| 6019 | VarDecl *ToCatchParamDecl; |
| 6020 | Stmt *ToCatchBody; |
| 6021 | std::tie(ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody) = *Imp; |
| 6022 | |
| 6023 | return new (Importer.getToContext()) ObjCAtCatchStmt ( |
| 6024 | ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6025 | } |
| 6026 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6027 | ExpectedStmt ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 6028 | ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc()); |
| 6029 | if (!ToAtFinallyLocOrErr) |
| 6030 | return ToAtFinallyLocOrErr.takeError(); |
| 6031 | ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody()); |
| 6032 | if (!ToAtFinallyStmtOrErr) |
| 6033 | return ToAtFinallyStmtOrErr.takeError(); |
| 6034 | return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr, |
| 6035 | *ToAtFinallyStmtOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6036 | } |
| 6037 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6038 | ExpectedStmt ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 6039 | auto Imp = importSeq( |
| 6040 | S->getAtTryLoc(), S->getTryBody(), S->getFinallyStmt()); |
| 6041 | if (!Imp) |
| 6042 | return Imp.takeError(); |
| 6043 | |
| 6044 | SourceLocation ToAtTryLoc; |
| 6045 | Stmt *ToTryBody, *ToFinallyStmt; |
| 6046 | std::tie(ToAtTryLoc, ToTryBody, ToFinallyStmt) = *Imp; |
| 6047 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6048 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 6049 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 6050 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6051 | if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt)) |
| 6052 | ToCatchStmts[CI] = *ToCatchStmtOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6053 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6054 | return ToCatchStmtOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6055 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6056 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6057 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6058 | ToAtTryLoc, ToTryBody, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6059 | ToCatchStmts.begin(), ToCatchStmts.size(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6060 | ToFinallyStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6061 | } |
| 6062 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6063 | ExpectedStmt ASTNodeImporter::VisitObjCAtSynchronizedStmt |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6064 | (ObjCAtSynchronizedStmt *S) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6065 | auto Imp = importSeq( |
| 6066 | S->getAtSynchronizedLoc(), S->getSynchExpr(), S->getSynchBody()); |
| 6067 | if (!Imp) |
| 6068 | return Imp.takeError(); |
| 6069 | |
| 6070 | SourceLocation ToAtSynchronizedLoc; |
| 6071 | Expr *ToSynchExpr; |
| 6072 | Stmt *ToSynchBody; |
| 6073 | std::tie(ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody) = *Imp; |
| 6074 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6075 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 6076 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 6077 | } |
| 6078 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6079 | ExpectedStmt ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 6080 | ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc()); |
| 6081 | if (!ToThrowLocOrErr) |
| 6082 | return ToThrowLocOrErr.takeError(); |
| 6083 | ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr()); |
| 6084 | if (!ToThrowExprOrErr) |
| 6085 | return ToThrowExprOrErr.takeError(); |
| 6086 | return new (Importer.getToContext()) ObjCAtThrowStmt( |
| 6087 | *ToThrowLocOrErr, *ToThrowExprOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6088 | } |
| 6089 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6090 | ExpectedStmt ASTNodeImporter::VisitObjCAutoreleasePoolStmt( |
| 6091 | ObjCAutoreleasePoolStmt *S) { |
| 6092 | ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc()); |
| 6093 | if (!ToAtLocOrErr) |
| 6094 | return ToAtLocOrErr.takeError(); |
| 6095 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 6096 | if (!ToSubStmtOrErr) |
| 6097 | return ToSubStmtOrErr.takeError(); |
| 6098 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr, |
| 6099 | *ToSubStmtOrErr); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6100 | } |
| 6101 | |
| 6102 | //---------------------------------------------------------------------------- |
| 6103 | // Import Expressions |
| 6104 | //---------------------------------------------------------------------------- |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6105 | ExpectedStmt ASTNodeImporter::VisitExpr(Expr *E) { |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6106 | Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node) |
| 6107 | << E->getStmtClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6108 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6109 | } |
| 6110 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6111 | ExpectedStmt ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| 6112 | auto Imp = importSeq( |
| 6113 | E->getBuiltinLoc(), E->getSubExpr(), E->getWrittenTypeInfo(), |
| 6114 | E->getRParenLoc(), E->getType()); |
| 6115 | if (!Imp) |
| 6116 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6117 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6118 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6119 | Expr *ToSubExpr; |
| 6120 | TypeSourceInfo *ToWrittenTypeInfo; |
| 6121 | QualType ToType; |
| 6122 | std::tie(ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType) = |
| 6123 | *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6124 | |
| 6125 | return new (Importer.getToContext()) VAArgExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6126 | ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType, |
| 6127 | E->isMicrosoftABI()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6128 | } |
| 6129 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6130 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6131 | ExpectedStmt ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 6132 | ExpectedType TypeOrErr = import(E->getType()); |
| 6133 | if (!TypeOrErr) |
| 6134 | return TypeOrErr.takeError(); |
| 6135 | |
| 6136 | ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc()); |
| 6137 | if (!BeginLocOrErr) |
| 6138 | return BeginLocOrErr.takeError(); |
| 6139 | |
| 6140 | return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6141 | } |
| 6142 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6143 | ExpectedStmt ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { |
| 6144 | auto Imp = importSeq( |
| 6145 | E->getBeginLoc(), E->getType(), E->getFunctionName()); |
| 6146 | if (!Imp) |
| 6147 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6148 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6149 | SourceLocation ToBeginLoc; |
| 6150 | QualType ToType; |
| 6151 | StringLiteral *ToFunctionName; |
| 6152 | std::tie(ToBeginLoc, ToType, ToFunctionName) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6153 | |
Bruno Ricci | 17ff026 | 2018-10-27 19:21:19 +0000 | [diff] [blame] | 6154 | return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType, |
| 6155 | E->getIdentKind(), ToFunctionName); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6156 | } |
| 6157 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6158 | ExpectedStmt ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
| 6159 | auto Imp = importSeq( |
| 6160 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDecl(), |
| 6161 | E->getLocation(), E->getType()); |
| 6162 | if (!Imp) |
| 6163 | return Imp.takeError(); |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6164 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6165 | NestedNameSpecifierLoc ToQualifierLoc; |
| 6166 | SourceLocation ToTemplateKeywordLoc, ToLocation; |
| 6167 | ValueDecl *ToDecl; |
| 6168 | QualType ToType; |
| 6169 | std::tie(ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, ToLocation, ToType) = |
| 6170 | *Imp; |
| 6171 | |
| 6172 | NamedDecl *ToFoundD = nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6173 | if (E->getDecl() != E->getFoundDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6174 | auto FoundDOrErr = import(E->getFoundDecl()); |
| 6175 | if (!FoundDOrErr) |
| 6176 | return FoundDOrErr.takeError(); |
| 6177 | ToFoundD = *FoundDOrErr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6178 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6179 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6180 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6181 | TemplateArgumentListInfo *ToResInfo = nullptr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6182 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6183 | if (Error Err = |
| 6184 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 6185 | return std::move(Err); |
| 6186 | ToResInfo = &ToTAInfo; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6187 | } |
| 6188 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6189 | auto *ToE = DeclRefExpr::Create( |
| 6190 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, |
| 6191 | E->refersToEnclosingVariableOrCapture(), ToLocation, ToType, |
| 6192 | E->getValueKind(), ToFoundD, ToResInfo); |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 6193 | if (E->hadMultipleCandidates()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6194 | ToE->setHadMultipleCandidates(true); |
| 6195 | return ToE; |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 6196 | } |
| 6197 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6198 | ExpectedStmt ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 6199 | ExpectedType TypeOrErr = import(E->getType()); |
| 6200 | if (!TypeOrErr) |
| 6201 | return TypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6202 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6203 | return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6204 | } |
| 6205 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6206 | ExpectedStmt ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { |
| 6207 | ExpectedExpr ToInitOrErr = import(E->getInit()); |
| 6208 | if (!ToInitOrErr) |
| 6209 | return ToInitOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6210 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6211 | ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc()); |
| 6212 | if (!ToEqualOrColonLocOrErr) |
| 6213 | return ToEqualOrColonLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6214 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6215 | SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6216 | // List elements from the second, the first is Init itself |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6217 | for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) { |
| 6218 | if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I))) |
| 6219 | ToIndexExprs[I - 1] = *ToArgOrErr; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6220 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6221 | return ToArgOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6222 | } |
| 6223 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6224 | SmallVector<Designator, 4> ToDesignators(E->size()); |
| 6225 | if (Error Err = ImportContainerChecked(E->designators(), ToDesignators)) |
| 6226 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6227 | |
| 6228 | return DesignatedInitExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6229 | Importer.getToContext(), ToDesignators, |
| 6230 | ToIndexExprs, *ToEqualOrColonLocOrErr, |
| 6231 | E->usesGNUSyntax(), *ToInitOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6232 | } |
| 6233 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6234 | ExpectedStmt |
| 6235 | ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 6236 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6237 | if (!ToTypeOrErr) |
| 6238 | return ToTypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6239 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6240 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6241 | if (!ToLocationOrErr) |
| 6242 | return ToLocationOrErr.takeError(); |
| 6243 | |
| 6244 | return new (Importer.getToContext()) CXXNullPtrLiteralExpr( |
| 6245 | *ToTypeOrErr, *ToLocationOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6246 | } |
| 6247 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6248 | ExpectedStmt ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 6249 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6250 | if (!ToTypeOrErr) |
| 6251 | return ToTypeOrErr.takeError(); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6252 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6253 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6254 | if (!ToLocationOrErr) |
| 6255 | return ToLocationOrErr.takeError(); |
| 6256 | |
| 6257 | return IntegerLiteral::Create( |
| 6258 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6259 | } |
| 6260 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6261 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6262 | ExpectedStmt ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 6263 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6264 | if (!ToTypeOrErr) |
| 6265 | return ToTypeOrErr.takeError(); |
| 6266 | |
| 6267 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6268 | if (!ToLocationOrErr) |
| 6269 | return ToLocationOrErr.takeError(); |
| 6270 | |
| 6271 | return FloatingLiteral::Create( |
| 6272 | Importer.getToContext(), E->getValue(), E->isExact(), |
| 6273 | *ToTypeOrErr, *ToLocationOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6274 | } |
| 6275 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6276 | ExpectedStmt ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) { |
| 6277 | auto ToTypeOrErr = import(E->getType()); |
| 6278 | if (!ToTypeOrErr) |
| 6279 | return ToTypeOrErr.takeError(); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6280 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6281 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6282 | if (!ToSubExprOrErr) |
| 6283 | return ToSubExprOrErr.takeError(); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6284 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6285 | return new (Importer.getToContext()) ImaginaryLiteral( |
| 6286 | *ToSubExprOrErr, *ToTypeOrErr); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6287 | } |
| 6288 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6289 | ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 6290 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6291 | if (!ToTypeOrErr) |
| 6292 | return ToTypeOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6293 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6294 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6295 | if (!ToLocationOrErr) |
| 6296 | return ToLocationOrErr.takeError(); |
| 6297 | |
| 6298 | return new (Importer.getToContext()) CharacterLiteral( |
| 6299 | E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr); |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 6300 | } |
| 6301 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6302 | ExpectedStmt ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 6303 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6304 | if (!ToTypeOrErr) |
| 6305 | return ToTypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6306 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6307 | SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated()); |
| 6308 | if (Error Err = ImportArrayChecked( |
| 6309 | E->tokloc_begin(), E->tokloc_end(), ToLocations.begin())) |
| 6310 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6311 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6312 | return StringLiteral::Create( |
| 6313 | Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(), |
| 6314 | *ToTypeOrErr, ToLocations.data(), ToLocations.size()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6315 | } |
| 6316 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6317 | ExpectedStmt ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 6318 | auto Imp = importSeq( |
| 6319 | E->getLParenLoc(), E->getTypeSourceInfo(), E->getType(), |
| 6320 | E->getInitializer()); |
| 6321 | if (!Imp) |
| 6322 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6323 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6324 | SourceLocation ToLParenLoc; |
| 6325 | TypeSourceInfo *ToTypeSourceInfo; |
| 6326 | QualType ToType; |
| 6327 | Expr *ToInitializer; |
| 6328 | std::tie(ToLParenLoc, ToTypeSourceInfo, ToType, ToInitializer) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6329 | |
| 6330 | return new (Importer.getToContext()) CompoundLiteralExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6331 | ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(), |
| 6332 | ToInitializer, E->isFileScope()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6333 | } |
| 6334 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6335 | ExpectedStmt ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { |
| 6336 | auto Imp = importSeq( |
| 6337 | E->getBuiltinLoc(), E->getType(), E->getRParenLoc()); |
| 6338 | if (!Imp) |
| 6339 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6340 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6341 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6342 | QualType ToType; |
| 6343 | std::tie(ToBuiltinLoc, ToType, ToRParenLoc) = *Imp; |
| 6344 | |
| 6345 | SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs()); |
| 6346 | if (Error Err = ImportArrayChecked( |
| 6347 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 6348 | ToExprs.begin())) |
| 6349 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6350 | |
| 6351 | return new (Importer.getToContext()) AtomicExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6352 | ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6353 | } |
| 6354 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6355 | ExpectedStmt ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 6356 | auto Imp = importSeq( |
| 6357 | E->getAmpAmpLoc(), E->getLabelLoc(), E->getLabel(), E->getType()); |
| 6358 | if (!Imp) |
| 6359 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6360 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6361 | SourceLocation ToAmpAmpLoc, ToLabelLoc; |
| 6362 | LabelDecl *ToLabel; |
| 6363 | QualType ToType; |
| 6364 | std::tie(ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6365 | |
| 6366 | return new (Importer.getToContext()) AddrLabelExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6367 | ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6368 | } |
| 6369 | |
Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6370 | ExpectedStmt ASTNodeImporter::VisitConstantExpr(ConstantExpr *E) { |
| 6371 | auto Imp = importSeq(E->getSubExpr()); |
| 6372 | if (!Imp) |
| 6373 | return Imp.takeError(); |
| 6374 | |
| 6375 | Expr *ToSubExpr; |
| 6376 | std::tie(ToSubExpr) = *Imp; |
| 6377 | |
Bill Wendling | 107b0e9 | 2018-11-20 08:53:30 +0000 | [diff] [blame] | 6378 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr); |
Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6379 | } |
| 6380 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6381 | ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| 6382 | auto Imp = importSeq(E->getLParen(), E->getRParen(), E->getSubExpr()); |
| 6383 | if (!Imp) |
| 6384 | return Imp.takeError(); |
| 6385 | |
| 6386 | SourceLocation ToLParen, ToRParen; |
| 6387 | Expr *ToSubExpr; |
| 6388 | std::tie(ToLParen, ToRParen, ToSubExpr) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6389 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6390 | return new (Importer.getToContext()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6391 | ParenExpr(ToLParen, ToRParen, ToSubExpr); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6392 | } |
| 6393 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6394 | ExpectedStmt ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 6395 | SmallVector<Expr *, 4> ToExprs(E->getNumExprs()); |
| 6396 | if (Error Err = ImportContainerChecked(E->exprs(), ToExprs)) |
| 6397 | return std::move(Err); |
| 6398 | |
| 6399 | ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc()); |
| 6400 | if (!ToLParenLocOrErr) |
| 6401 | return ToLParenLocOrErr.takeError(); |
| 6402 | |
| 6403 | ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc()); |
| 6404 | if (!ToRParenLocOrErr) |
| 6405 | return ToRParenLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6406 | |
| 6407 | return new (Importer.getToContext()) ParenListExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6408 | Importer.getToContext(), *ToLParenLocOrErr, ToExprs, *ToRParenLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6409 | } |
| 6410 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6411 | ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| 6412 | auto Imp = importSeq( |
| 6413 | E->getSubStmt(), E->getType(), E->getLParenLoc(), E->getRParenLoc()); |
| 6414 | if (!Imp) |
| 6415 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6416 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6417 | CompoundStmt *ToSubStmt; |
| 6418 | QualType ToType; |
| 6419 | SourceLocation ToLParenLoc, ToRParenLoc; |
| 6420 | std::tie(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6421 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6422 | return new (Importer.getToContext()) StmtExpr( |
| 6423 | ToSubStmt, ToType, ToLParenLoc, ToRParenLoc); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6424 | } |
| 6425 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6426 | ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| 6427 | auto Imp = importSeq( |
| 6428 | E->getSubExpr(), E->getType(), E->getOperatorLoc()); |
| 6429 | if (!Imp) |
| 6430 | return Imp.takeError(); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6431 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6432 | Expr *ToSubExpr; |
| 6433 | QualType ToType; |
| 6434 | SourceLocation ToOperatorLoc; |
| 6435 | std::tie(ToSubExpr, ToType, ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6436 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6437 | return new (Importer.getToContext()) UnaryOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6438 | ToSubExpr, E->getOpcode(), ToType, E->getValueKind(), E->getObjectKind(), |
| 6439 | ToOperatorLoc, E->canOverflow()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6440 | } |
| 6441 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6442 | ExpectedStmt |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6443 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6444 | auto Imp = importSeq(E->getType(), E->getOperatorLoc(), E->getRParenLoc()); |
| 6445 | if (!Imp) |
| 6446 | return Imp.takeError(); |
| 6447 | |
| 6448 | QualType ToType; |
| 6449 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 6450 | std::tie(ToType, ToOperatorLoc, ToRParenLoc) = *Imp; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6451 | |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6452 | if (E->isArgumentType()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6453 | Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr = |
| 6454 | import(E->getArgumentTypeInfo()); |
| 6455 | if (!ToArgumentTypeInfoOrErr) |
| 6456 | return ToArgumentTypeInfoOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6457 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6458 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6459 | E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc, |
| 6460 | ToRParenLoc); |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6461 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6462 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6463 | ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr()); |
| 6464 | if (!ToArgumentExprOrErr) |
| 6465 | return ToArgumentExprOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6466 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6467 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6468 | E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc); |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6469 | } |
| 6470 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6471 | ExpectedStmt ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| 6472 | auto Imp = importSeq( |
| 6473 | E->getLHS(), E->getRHS(), E->getType(), E->getOperatorLoc()); |
| 6474 | if (!Imp) |
| 6475 | return Imp.takeError(); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6476 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6477 | Expr *ToLHS, *ToRHS; |
| 6478 | QualType ToType; |
| 6479 | SourceLocation ToOperatorLoc; |
| 6480 | std::tie(ToLHS, ToRHS, ToType, ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6481 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6482 | return new (Importer.getToContext()) BinaryOperator( |
| 6483 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6484 | E->getObjectKind(), ToOperatorLoc, E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6485 | } |
| 6486 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6487 | ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| 6488 | auto Imp = importSeq( |
| 6489 | E->getCond(), E->getQuestionLoc(), E->getLHS(), E->getColonLoc(), |
| 6490 | E->getRHS(), E->getType()); |
| 6491 | if (!Imp) |
| 6492 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6493 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6494 | Expr *ToCond, *ToLHS, *ToRHS; |
| 6495 | SourceLocation ToQuestionLoc, ToColonLoc; |
| 6496 | QualType ToType; |
| 6497 | std::tie(ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6498 | |
| 6499 | return new (Importer.getToContext()) ConditionalOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6500 | ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType, |
| 6501 | E->getValueKind(), E->getObjectKind()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6502 | } |
| 6503 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6504 | ExpectedStmt ASTNodeImporter::VisitBinaryConditionalOperator( |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6505 | BinaryConditionalOperator *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6506 | auto Imp = importSeq( |
| 6507 | E->getCommon(), E->getOpaqueValue(), E->getCond(), E->getTrueExpr(), |
| 6508 | E->getFalseExpr(), E->getQuestionLoc(), E->getColonLoc(), E->getType()); |
| 6509 | if (!Imp) |
| 6510 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6511 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6512 | Expr *ToCommon, *ToCond, *ToTrueExpr, *ToFalseExpr; |
| 6513 | OpaqueValueExpr *ToOpaqueValue; |
| 6514 | SourceLocation ToQuestionLoc, ToColonLoc; |
| 6515 | QualType ToType; |
| 6516 | std::tie( |
| 6517 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, ToQuestionLoc, |
| 6518 | ToColonLoc, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6519 | |
| 6520 | return new (Importer.getToContext()) BinaryConditionalOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6521 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, |
| 6522 | ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(), |
| 6523 | E->getObjectKind()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6524 | } |
| 6525 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6526 | ExpectedStmt ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 6527 | auto Imp = importSeq( |
| 6528 | E->getBeginLoc(), E->getQueriedTypeSourceInfo(), |
| 6529 | E->getDimensionExpression(), E->getEndLoc(), E->getType()); |
| 6530 | if (!Imp) |
| 6531 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6532 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6533 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6534 | TypeSourceInfo *ToQueriedTypeSourceInfo; |
| 6535 | Expr *ToDimensionExpression; |
| 6536 | QualType ToType; |
| 6537 | std::tie( |
| 6538 | ToBeginLoc, ToQueriedTypeSourceInfo, ToDimensionExpression, ToEndLoc, |
| 6539 | ToType) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6540 | |
| 6541 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6542 | ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(), |
| 6543 | ToDimensionExpression, ToEndLoc, ToType); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6544 | } |
| 6545 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6546 | ExpectedStmt ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 6547 | auto Imp = importSeq( |
| 6548 | E->getBeginLoc(), E->getQueriedExpression(), E->getEndLoc(), E->getType()); |
| 6549 | if (!Imp) |
| 6550 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6551 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6552 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6553 | Expr *ToQueriedExpression; |
| 6554 | QualType ToType; |
| 6555 | std::tie(ToBeginLoc, ToQueriedExpression, ToEndLoc, ToType) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6556 | |
| 6557 | return new (Importer.getToContext()) ExpressionTraitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6558 | ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(), |
| 6559 | ToEndLoc, ToType); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6560 | } |
| 6561 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6562 | ExpectedStmt ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| 6563 | auto Imp = importSeq( |
| 6564 | E->getLocation(), E->getType(), E->getSourceExpr()); |
| 6565 | if (!Imp) |
| 6566 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6567 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6568 | SourceLocation ToLocation; |
| 6569 | QualType ToType; |
| 6570 | Expr *ToSourceExpr; |
| 6571 | std::tie(ToLocation, ToType, ToSourceExpr) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6572 | |
| 6573 | return new (Importer.getToContext()) OpaqueValueExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6574 | ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6575 | } |
| 6576 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6577 | ExpectedStmt ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 6578 | auto Imp = importSeq( |
| 6579 | E->getLHS(), E->getRHS(), E->getType(), E->getRBracketLoc()); |
| 6580 | if (!Imp) |
| 6581 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6582 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6583 | Expr *ToLHS, *ToRHS; |
| 6584 | SourceLocation ToRBracketLoc; |
| 6585 | QualType ToType; |
| 6586 | std::tie(ToLHS, ToRHS, ToType, ToRBracketLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6587 | |
| 6588 | return new (Importer.getToContext()) ArraySubscriptExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6589 | ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(), |
| 6590 | ToRBracketLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6591 | } |
| 6592 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6593 | ExpectedStmt |
| 6594 | ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 6595 | auto Imp = importSeq( |
| 6596 | E->getLHS(), E->getRHS(), E->getType(), E->getComputationLHSType(), |
| 6597 | E->getComputationResultType(), E->getOperatorLoc()); |
| 6598 | if (!Imp) |
| 6599 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6600 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6601 | Expr *ToLHS, *ToRHS; |
| 6602 | QualType ToType, ToComputationLHSType, ToComputationResultType; |
| 6603 | SourceLocation ToOperatorLoc; |
| 6604 | std::tie(ToLHS, ToRHS, ToType, ToComputationLHSType, ToComputationResultType, |
| 6605 | ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6606 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6607 | return new (Importer.getToContext()) CompoundAssignOperator( |
| 6608 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6609 | E->getObjectKind(), ToComputationLHSType, ToComputationResultType, |
| 6610 | ToOperatorLoc, E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6611 | } |
| 6612 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6613 | Expected<CXXCastPath> |
| 6614 | ASTNodeImporter::ImportCastPath(CastExpr *CE) { |
| 6615 | CXXCastPath Path; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6616 | 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] | 6617 | if (auto SpecOrErr = import(*I)) |
| 6618 | Path.push_back(*SpecOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6619 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6620 | return SpecOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6621 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6622 | return Path; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6623 | } |
| 6624 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6625 | ExpectedStmt ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 6626 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6627 | if (!ToTypeOrErr) |
| 6628 | return ToTypeOrErr.takeError(); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6629 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6630 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6631 | if (!ToSubExprOrErr) |
| 6632 | return ToSubExprOrErr.takeError(); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6633 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6634 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6635 | if (!ToBasePathOrErr) |
| 6636 | return ToBasePathOrErr.takeError(); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6637 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6638 | return ImplicitCastExpr::Create( |
| 6639 | Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr, |
| 6640 | &(*ToBasePathOrErr), E->getValueKind()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6641 | } |
| 6642 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6643 | ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
| 6644 | auto Imp1 = importSeq( |
| 6645 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten()); |
| 6646 | if (!Imp1) |
| 6647 | return Imp1.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6648 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6649 | QualType ToType; |
| 6650 | Expr *ToSubExpr; |
| 6651 | TypeSourceInfo *ToTypeInfoAsWritten; |
| 6652 | std::tie(ToType, ToSubExpr, ToTypeInfoAsWritten) = *Imp1; |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6653 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6654 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6655 | if (!ToBasePathOrErr) |
| 6656 | return ToBasePathOrErr.takeError(); |
| 6657 | CXXCastPath *ToBasePath = &(*ToBasePathOrErr); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6658 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6659 | switch (E->getStmtClass()) { |
| 6660 | case Stmt::CStyleCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6661 | auto *CCE = cast<CStyleCastExpr>(E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6662 | ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc()); |
| 6663 | if (!ToLParenLocOrErr) |
| 6664 | return ToLParenLocOrErr.takeError(); |
| 6665 | ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc()); |
| 6666 | if (!ToRParenLocOrErr) |
| 6667 | return ToRParenLocOrErr.takeError(); |
| 6668 | return CStyleCastExpr::Create( |
| 6669 | Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(), |
| 6670 | ToSubExpr, ToBasePath, ToTypeInfoAsWritten, *ToLParenLocOrErr, |
| 6671 | *ToRParenLocOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6672 | } |
| 6673 | |
| 6674 | case Stmt::CXXFunctionalCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6675 | auto *FCE = cast<CXXFunctionalCastExpr>(E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6676 | ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc()); |
| 6677 | if (!ToLParenLocOrErr) |
| 6678 | return ToLParenLocOrErr.takeError(); |
| 6679 | ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc()); |
| 6680 | if (!ToRParenLocOrErr) |
| 6681 | return ToRParenLocOrErr.takeError(); |
| 6682 | return CXXFunctionalCastExpr::Create( |
| 6683 | Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten, |
| 6684 | E->getCastKind(), ToSubExpr, ToBasePath, *ToLParenLocOrErr, |
| 6685 | *ToRParenLocOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6686 | } |
| 6687 | |
| 6688 | case Stmt::ObjCBridgedCastExprClass: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6689 | auto *OCE = cast<ObjCBridgedCastExpr>(E); |
| 6690 | ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc()); |
| 6691 | if (!ToLParenLocOrErr) |
| 6692 | return ToLParenLocOrErr.takeError(); |
| 6693 | ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc()); |
| 6694 | if (!ToBridgeKeywordLocOrErr) |
| 6695 | return ToBridgeKeywordLocOrErr.takeError(); |
| 6696 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 6697 | *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), |
| 6698 | *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6699 | } |
| 6700 | default: |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6701 | llvm_unreachable("Cast expression of unsupported type!"); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6702 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6703 | } |
| 6704 | } |
| 6705 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6706 | ExpectedStmt ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *E) { |
| 6707 | SmallVector<OffsetOfNode, 4> ToNodes; |
| 6708 | for (int I = 0, N = E->getNumComponents(); I < N; ++I) { |
| 6709 | const OffsetOfNode &FromNode = E->getComponent(I); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6710 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6711 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6712 | if (FromNode.getKind() != OffsetOfNode::Base) { |
| 6713 | auto Imp = importSeq(FromNode.getBeginLoc(), FromNode.getEndLoc()); |
| 6714 | if (!Imp) |
| 6715 | return Imp.takeError(); |
| 6716 | std::tie(ToBeginLoc, ToEndLoc) = *Imp; |
| 6717 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6718 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6719 | switch (FromNode.getKind()) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6720 | case OffsetOfNode::Array: |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6721 | ToNodes.push_back( |
| 6722 | OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6723 | break; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6724 | case OffsetOfNode::Base: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6725 | auto ToBSOrErr = import(FromNode.getBase()); |
| 6726 | if (!ToBSOrErr) |
| 6727 | return ToBSOrErr.takeError(); |
| 6728 | ToNodes.push_back(OffsetOfNode(*ToBSOrErr)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6729 | break; |
| 6730 | } |
| 6731 | case OffsetOfNode::Field: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6732 | auto ToFieldOrErr = import(FromNode.getField()); |
| 6733 | if (!ToFieldOrErr) |
| 6734 | return ToFieldOrErr.takeError(); |
| 6735 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6736 | break; |
| 6737 | } |
| 6738 | case OffsetOfNode::Identifier: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6739 | IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName()); |
| 6740 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6741 | break; |
| 6742 | } |
| 6743 | } |
| 6744 | } |
| 6745 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6746 | SmallVector<Expr *, 4> ToExprs(E->getNumExpressions()); |
| 6747 | for (int I = 0, N = E->getNumExpressions(); I < N; ++I) { |
| 6748 | ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I)); |
| 6749 | if (!ToIndexExprOrErr) |
| 6750 | return ToIndexExprOrErr.takeError(); |
| 6751 | ToExprs[I] = *ToIndexExprOrErr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6752 | } |
| 6753 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6754 | auto Imp = importSeq( |
| 6755 | E->getType(), E->getTypeSourceInfo(), E->getOperatorLoc(), |
| 6756 | E->getRParenLoc()); |
| 6757 | if (!Imp) |
| 6758 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6759 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6760 | QualType ToType; |
| 6761 | TypeSourceInfo *ToTypeSourceInfo; |
| 6762 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 6763 | std::tie(ToType, ToTypeSourceInfo, ToOperatorLoc, ToRParenLoc) = *Imp; |
| 6764 | |
| 6765 | return OffsetOfExpr::Create( |
| 6766 | Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes, |
| 6767 | ToExprs, ToRParenLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6768 | } |
| 6769 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6770 | ExpectedStmt ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 6771 | auto Imp = importSeq( |
| 6772 | E->getType(), E->getOperand(), E->getBeginLoc(), E->getEndLoc()); |
| 6773 | if (!Imp) |
| 6774 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6775 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6776 | QualType ToType; |
| 6777 | Expr *ToOperand; |
| 6778 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6779 | std::tie(ToType, ToOperand, ToBeginLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6780 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6781 | CanThrowResult ToCanThrow; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6782 | if (E->isValueDependent()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6783 | ToCanThrow = CT_Dependent; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6784 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6785 | ToCanThrow = E->getValue() ? CT_Can : CT_Cannot; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6786 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6787 | return new (Importer.getToContext()) CXXNoexceptExpr( |
| 6788 | ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6789 | } |
| 6790 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6791 | ExpectedStmt ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| 6792 | auto Imp = importSeq(E->getSubExpr(), E->getType(), E->getThrowLoc()); |
| 6793 | if (!Imp) |
| 6794 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6795 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6796 | Expr *ToSubExpr; |
| 6797 | QualType ToType; |
| 6798 | SourceLocation ToThrowLoc; |
| 6799 | std::tie(ToSubExpr, ToType, ToThrowLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6800 | |
| 6801 | return new (Importer.getToContext()) CXXThrowExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6802 | ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6803 | } |
| 6804 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6805 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| 6806 | ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation()); |
| 6807 | if (!ToUsedLocOrErr) |
| 6808 | return ToUsedLocOrErr.takeError(); |
| 6809 | |
| 6810 | auto ToParamOrErr = import(E->getParam()); |
| 6811 | if (!ToParamOrErr) |
| 6812 | return ToParamOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6813 | |
| 6814 | return CXXDefaultArgExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6815 | Importer.getToContext(), *ToUsedLocOrErr, *ToParamOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6816 | } |
| 6817 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6818 | ExpectedStmt |
| 6819 | ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| 6820 | auto Imp = importSeq( |
| 6821 | E->getType(), E->getTypeSourceInfo(), E->getRParenLoc()); |
| 6822 | if (!Imp) |
| 6823 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6824 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6825 | QualType ToType; |
| 6826 | TypeSourceInfo *ToTypeSourceInfo; |
| 6827 | SourceLocation ToRParenLoc; |
| 6828 | std::tie(ToType, ToTypeSourceInfo, ToRParenLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6829 | |
| 6830 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6831 | ToType, ToTypeSourceInfo, ToRParenLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6832 | } |
| 6833 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6834 | ExpectedStmt |
| 6835 | ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 6836 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6837 | if (!ToSubExprOrErr) |
| 6838 | return ToSubExprOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6839 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6840 | auto ToDtorOrErr = import(E->getTemporary()->getDestructor()); |
| 6841 | if (!ToDtorOrErr) |
| 6842 | return ToDtorOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6843 | |
| 6844 | ASTContext &ToCtx = Importer.getToContext(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6845 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr); |
| 6846 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6847 | } |
| 6848 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6849 | ExpectedStmt |
| 6850 | ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { |
| 6851 | auto Imp = importSeq( |
| 6852 | E->getConstructor(), E->getType(), E->getTypeSourceInfo(), |
| 6853 | E->getParenOrBraceRange()); |
| 6854 | if (!Imp) |
| 6855 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6856 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6857 | CXXConstructorDecl *ToConstructor; |
| 6858 | QualType ToType; |
| 6859 | TypeSourceInfo *ToTypeSourceInfo; |
| 6860 | SourceRange ToParenOrBraceRange; |
| 6861 | std::tie(ToConstructor, ToType, ToTypeSourceInfo, ToParenOrBraceRange) = *Imp; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6862 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6863 | SmallVector<Expr *, 8> ToArgs(E->getNumArgs()); |
| 6864 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 6865 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6866 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6867 | return new (Importer.getToContext()) CXXTemporaryObjectExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6868 | Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs, |
| 6869 | ToParenOrBraceRange, E->hadMultipleCandidates(), |
| 6870 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 6871 | E->requiresZeroInitialization()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6872 | } |
| 6873 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6874 | ExpectedStmt |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6875 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6876 | auto Imp = importSeq( |
| 6877 | E->getType(), E->GetTemporaryExpr(), E->getExtendingDecl()); |
| 6878 | if (!Imp) |
| 6879 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6880 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6881 | QualType ToType; |
| 6882 | Expr *ToTemporaryExpr; |
| 6883 | const ValueDecl *ToExtendingDecl; |
| 6884 | std::tie(ToType, ToTemporaryExpr, ToExtendingDecl) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6885 | |
| 6886 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6887 | ToType, ToTemporaryExpr, E->isBoundToLvalueReference()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6888 | |
| 6889 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6890 | ToMTE->setExtendingDecl(ToExtendingDecl, E->getManglingNumber()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6891 | return ToMTE; |
| 6892 | } |
| 6893 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6894 | ExpectedStmt ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { |
| 6895 | auto Imp = importSeq( |
| 6896 | E->getType(), E->getPattern(), E->getEllipsisLoc()); |
| 6897 | if (!Imp) |
| 6898 | return Imp.takeError(); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6899 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6900 | QualType ToType; |
| 6901 | Expr *ToPattern; |
| 6902 | SourceLocation ToEllipsisLoc; |
| 6903 | std::tie(ToType, ToPattern, ToEllipsisLoc) = *Imp; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6904 | |
| 6905 | return new (Importer.getToContext()) PackExpansionExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6906 | ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions()); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6907 | } |
| 6908 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6909 | ExpectedStmt ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { |
| 6910 | auto Imp = importSeq( |
| 6911 | E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc()); |
| 6912 | if (!Imp) |
| 6913 | return Imp.takeError(); |
| 6914 | |
| 6915 | SourceLocation ToOperatorLoc, ToPackLoc, ToRParenLoc; |
| 6916 | NamedDecl *ToPack; |
| 6917 | std::tie(ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc) = *Imp; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6918 | |
| 6919 | Optional<unsigned> Length; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6920 | if (!E->isValueDependent()) |
| 6921 | Length = E->getPackLength(); |
| 6922 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6923 | SmallVector<TemplateArgument, 8> ToPartialArguments; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6924 | if (E->isPartiallySubstituted()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6925 | if (Error Err = ImportTemplateArguments( |
| 6926 | E->getPartialArguments().data(), |
| 6927 | E->getPartialArguments().size(), |
| 6928 | ToPartialArguments)) |
| 6929 | return std::move(Err); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6930 | } |
| 6931 | |
| 6932 | return SizeOfPackExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6933 | Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc, |
| 6934 | Length, ToPartialArguments); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6935 | } |
| 6936 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6937 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6938 | ExpectedStmt ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) { |
| 6939 | auto Imp = importSeq( |
| 6940 | E->getOperatorNew(), E->getOperatorDelete(), E->getTypeIdParens(), |
| 6941 | E->getArraySize(), E->getInitializer(), E->getType(), |
| 6942 | E->getAllocatedTypeSourceInfo(), E->getSourceRange(), |
| 6943 | E->getDirectInitRange()); |
| 6944 | if (!Imp) |
| 6945 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6946 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6947 | FunctionDecl *ToOperatorNew, *ToOperatorDelete; |
| 6948 | SourceRange ToTypeIdParens, ToSourceRange, ToDirectInitRange; |
| 6949 | Expr *ToArraySize, *ToInitializer; |
| 6950 | QualType ToType; |
| 6951 | TypeSourceInfo *ToAllocatedTypeSourceInfo; |
| 6952 | std::tie( |
| 6953 | ToOperatorNew, ToOperatorDelete, ToTypeIdParens, ToArraySize, ToInitializer, |
| 6954 | ToType, ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6955 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6956 | SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs()); |
| 6957 | if (Error Err = |
| 6958 | ImportContainerChecked(E->placement_arguments(), ToPlacementArgs)) |
| 6959 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6960 | |
| 6961 | return new (Importer.getToContext()) CXXNewExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6962 | Importer.getToContext(), E->isGlobalNew(), ToOperatorNew, |
| 6963 | ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(), |
| 6964 | ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(), |
| 6965 | ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange, |
| 6966 | ToDirectInitRange); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6967 | } |
| 6968 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6969 | ExpectedStmt ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 6970 | auto Imp = importSeq( |
| 6971 | E->getType(), E->getOperatorDelete(), E->getArgument(), E->getBeginLoc()); |
| 6972 | if (!Imp) |
| 6973 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6974 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6975 | QualType ToType; |
| 6976 | FunctionDecl *ToOperatorDelete; |
| 6977 | Expr *ToArgument; |
| 6978 | SourceLocation ToBeginLoc; |
| 6979 | std::tie(ToType, ToOperatorDelete, ToArgument, ToBeginLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6980 | |
| 6981 | return new (Importer.getToContext()) CXXDeleteExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6982 | ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(), |
| 6983 | E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument, |
| 6984 | ToBeginLoc); |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6985 | } |
| 6986 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6987 | ExpectedStmt ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| 6988 | auto Imp = importSeq( |
| 6989 | E->getType(), E->getLocation(), E->getConstructor(), |
| 6990 | E->getParenOrBraceRange()); |
| 6991 | if (!Imp) |
| 6992 | return Imp.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6993 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6994 | QualType ToType; |
| 6995 | SourceLocation ToLocation; |
| 6996 | CXXConstructorDecl *ToConstructor; |
| 6997 | SourceRange ToParenOrBraceRange; |
| 6998 | std::tie(ToType, ToLocation, ToConstructor, ToParenOrBraceRange) = *Imp; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6999 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7000 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7001 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7002 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7003 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7004 | return CXXConstructExpr::Create( |
| 7005 | Importer.getToContext(), ToType, ToLocation, ToConstructor, |
| 7006 | E->isElidable(), ToArgs, E->hadMultipleCandidates(), |
| 7007 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 7008 | E->requiresZeroInitialization(), E->getConstructionKind(), |
| 7009 | ToParenOrBraceRange); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7010 | } |
| 7011 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7012 | ExpectedStmt ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *E) { |
| 7013 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7014 | if (!ToSubExprOrErr) |
| 7015 | return ToSubExprOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7016 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7017 | SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects()); |
| 7018 | if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects)) |
| 7019 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7020 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7021 | return ExprWithCleanups::Create( |
| 7022 | Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(), |
| 7023 | ToObjects); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7024 | } |
| 7025 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7026 | ExpectedStmt ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 7027 | auto Imp = importSeq( |
| 7028 | E->getCallee(), E->getType(), E->getRParenLoc()); |
| 7029 | if (!Imp) |
| 7030 | return Imp.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7031 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7032 | Expr *ToCallee; |
| 7033 | QualType ToType; |
| 7034 | SourceLocation ToRParenLoc; |
| 7035 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7036 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7037 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7038 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7039 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7040 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7041 | return new (Importer.getToContext()) CXXMemberCallExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7042 | Importer.getToContext(), ToCallee, ToArgs, ToType, E->getValueKind(), |
| 7043 | ToRParenLoc); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7044 | } |
| 7045 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7046 | ExpectedStmt ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 7047 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7048 | if (!ToTypeOrErr) |
| 7049 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7050 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7051 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7052 | if (!ToLocationOrErr) |
| 7053 | return ToLocationOrErr.takeError(); |
| 7054 | |
| 7055 | return new (Importer.getToContext()) CXXThisExpr( |
| 7056 | *ToLocationOrErr, *ToTypeOrErr, E->isImplicit()); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7057 | } |
| 7058 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7059 | ExpectedStmt ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 7060 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7061 | if (!ToTypeOrErr) |
| 7062 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7063 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7064 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7065 | if (!ToLocationOrErr) |
| 7066 | return ToLocationOrErr.takeError(); |
| 7067 | |
| 7068 | return new (Importer.getToContext()) CXXBoolLiteralExpr( |
| 7069 | E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7070 | } |
| 7071 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7072 | ExpectedStmt ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| 7073 | auto Imp1 = importSeq( |
| 7074 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7075 | E->getTemplateKeywordLoc(), E->getMemberDecl(), E->getType()); |
| 7076 | if (!Imp1) |
| 7077 | return Imp1.takeError(); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7078 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7079 | Expr *ToBase; |
| 7080 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7081 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7082 | ValueDecl *ToMemberDecl; |
| 7083 | QualType ToType; |
| 7084 | std::tie( |
| 7085 | ToBase, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, |
| 7086 | ToType) = *Imp1; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7087 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7088 | auto Imp2 = importSeq( |
| 7089 | E->getFoundDecl().getDecl(), E->getMemberNameInfo().getName(), |
| 7090 | E->getMemberNameInfo().getLoc(), E->getLAngleLoc(), E->getRAngleLoc()); |
| 7091 | if (!Imp2) |
| 7092 | return Imp2.takeError(); |
| 7093 | NamedDecl *ToDecl; |
| 7094 | DeclarationName ToName; |
| 7095 | SourceLocation ToLoc, ToLAngleLoc, ToRAngleLoc; |
| 7096 | std::tie(ToDecl, ToName, ToLoc, ToLAngleLoc, ToRAngleLoc) = *Imp2; |
Peter Szecsi | ef97252 | 2018-05-02 11:52:54 +0000 | [diff] [blame] | 7097 | |
| 7098 | DeclAccessPair ToFoundDecl = |
| 7099 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7100 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7101 | DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7102 | |
| 7103 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7104 | // FIXME: handle template arguments |
| 7105 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7106 | } |
| 7107 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7108 | return MemberExpr::Create( |
| 7109 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, |
| 7110 | ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, ToFoundDecl, |
| 7111 | ToMemberNameInfo, nullptr, ToType, E->getValueKind(), E->getObjectKind()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7112 | } |
| 7113 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7114 | ExpectedStmt |
| 7115 | ASTNodeImporter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { |
| 7116 | auto Imp = importSeq( |
| 7117 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7118 | E->getScopeTypeInfo(), E->getColonColonLoc(), E->getTildeLoc()); |
| 7119 | if (!Imp) |
| 7120 | return Imp.takeError(); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7121 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7122 | Expr *ToBase; |
| 7123 | SourceLocation ToOperatorLoc, ToColonColonLoc, ToTildeLoc; |
| 7124 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7125 | TypeSourceInfo *ToScopeTypeInfo; |
| 7126 | std::tie( |
| 7127 | ToBase, ToOperatorLoc, ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, |
| 7128 | ToTildeLoc) = *Imp; |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7129 | |
| 7130 | PseudoDestructorTypeStorage Storage; |
| 7131 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { |
| 7132 | IdentifierInfo *ToII = Importer.Import(FromII); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7133 | ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc()); |
| 7134 | if (!ToDestroyedTypeLocOrErr) |
| 7135 | return ToDestroyedTypeLocOrErr.takeError(); |
| 7136 | Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7137 | } else { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7138 | if (auto ToTIOrErr = import(E->getDestroyedTypeInfo())) |
| 7139 | Storage = PseudoDestructorTypeStorage(*ToTIOrErr); |
| 7140 | else |
| 7141 | return ToTIOrErr.takeError(); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7142 | } |
| 7143 | |
| 7144 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7145 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, |
| 7146 | ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7147 | } |
| 7148 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7149 | ExpectedStmt ASTNodeImporter::VisitCXXDependentScopeMemberExpr( |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7150 | CXXDependentScopeMemberExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7151 | auto Imp = importSeq( |
| 7152 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7153 | E->getTemplateKeywordLoc(), E->getFirstQualifierFoundInScope()); |
| 7154 | if (!Imp) |
| 7155 | return Imp.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7156 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7157 | QualType ToType; |
| 7158 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7159 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7160 | NamedDecl *ToFirstQualifierFoundInScope; |
| 7161 | std::tie( |
| 7162 | ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7163 | ToFirstQualifierFoundInScope) = *Imp; |
| 7164 | |
| 7165 | Expr *ToBase = nullptr; |
| 7166 | if (!E->isImplicitAccess()) { |
| 7167 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7168 | ToBase = *ToBaseOrErr; |
| 7169 | else |
| 7170 | return ToBaseOrErr.takeError(); |
| 7171 | } |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7172 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7173 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7174 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7175 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7176 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7177 | ToTAInfo)) |
| 7178 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7179 | ResInfo = &ToTAInfo; |
| 7180 | } |
| 7181 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7182 | auto ToMemberNameInfoOrErr = importSeq(E->getMember(), E->getMemberLoc()); |
| 7183 | if (!ToMemberNameInfoOrErr) |
| 7184 | return ToMemberNameInfoOrErr.takeError(); |
| 7185 | DeclarationNameInfo ToMemberNameInfo( |
| 7186 | std::get<0>(*ToMemberNameInfoOrErr), std::get<1>(*ToMemberNameInfoOrErr)); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7187 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7188 | if (Error Err = ImportDeclarationNameLoc( |
| 7189 | E->getMemberNameInfo(), ToMemberNameInfo)) |
| 7190 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7191 | |
| 7192 | return CXXDependentScopeMemberExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7193 | Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc, |
| 7194 | ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope, |
| 7195 | ToMemberNameInfo, ResInfo); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7196 | } |
| 7197 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7198 | ExpectedStmt |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7199 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7200 | auto Imp = importSeq( |
| 7201 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDeclName(), |
| 7202 | E->getExprLoc(), E->getLAngleLoc(), E->getRAngleLoc()); |
| 7203 | if (!Imp) |
| 7204 | return Imp.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7205 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7206 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7207 | SourceLocation ToTemplateKeywordLoc, ToExprLoc, ToLAngleLoc, ToRAngleLoc; |
| 7208 | DeclarationName ToDeclName; |
| 7209 | std::tie( |
| 7210 | ToQualifierLoc, ToTemplateKeywordLoc, ToDeclName, ToExprLoc, |
| 7211 | ToLAngleLoc, ToRAngleLoc) = *Imp; |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7212 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7213 | DeclarationNameInfo ToNameInfo(ToDeclName, ToExprLoc); |
| 7214 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7215 | return std::move(Err); |
| 7216 | |
| 7217 | TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7218 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7219 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7220 | if (Error Err = |
| 7221 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 7222 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7223 | ResInfo = &ToTAInfo; |
| 7224 | } |
| 7225 | |
| 7226 | return DependentScopeDeclRefExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7227 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, |
| 7228 | ToNameInfo, ResInfo); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7229 | } |
| 7230 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7231 | ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr( |
| 7232 | CXXUnresolvedConstructExpr *E) { |
| 7233 | auto Imp = importSeq( |
| 7234 | E->getLParenLoc(), E->getRParenLoc(), E->getTypeSourceInfo()); |
| 7235 | if (!Imp) |
| 7236 | return Imp.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7237 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7238 | SourceLocation ToLParenLoc, ToRParenLoc; |
| 7239 | TypeSourceInfo *ToTypeSourceInfo; |
| 7240 | std::tie(ToLParenLoc, ToRParenLoc, ToTypeSourceInfo) = *Imp; |
| 7241 | |
| 7242 | SmallVector<Expr *, 8> ToArgs(E->arg_size()); |
| 7243 | if (Error Err = |
| 7244 | ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin())) |
| 7245 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7246 | |
| 7247 | return CXXUnresolvedConstructExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7248 | Importer.getToContext(), ToTypeSourceInfo, ToLParenLoc, |
| 7249 | llvm::makeArrayRef(ToArgs), ToRParenLoc); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7250 | } |
| 7251 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7252 | ExpectedStmt |
| 7253 | ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { |
| 7254 | Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass()); |
| 7255 | if (!ToNamingClassOrErr) |
| 7256 | return ToNamingClassOrErr.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7257 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7258 | auto ToQualifierLocOrErr = import(E->getQualifierLoc()); |
| 7259 | if (!ToQualifierLocOrErr) |
| 7260 | return ToQualifierLocOrErr.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7261 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7262 | auto ToNameInfoOrErr = importSeq(E->getName(), E->getNameLoc()); |
| 7263 | if (!ToNameInfoOrErr) |
| 7264 | return ToNameInfoOrErr.takeError(); |
| 7265 | DeclarationNameInfo ToNameInfo( |
| 7266 | std::get<0>(*ToNameInfoOrErr), std::get<1>(*ToNameInfoOrErr)); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7267 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7268 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7269 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7270 | |
| 7271 | UnresolvedSet<8> ToDecls; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7272 | for (auto *D : E->decls()) |
| 7273 | if (auto ToDOrErr = import(D)) |
| 7274 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7275 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7276 | return ToDOrErr.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7277 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7278 | if (E->hasExplicitTemplateArgs() && E->getTemplateKeywordLoc().isValid()) { |
| 7279 | TemplateArgumentListInfo ToTAInfo; |
| 7280 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7281 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7282 | ToTAInfo)) |
| 7283 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7284 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7285 | ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc()); |
| 7286 | if (!ToTemplateKeywordLocOrErr) |
| 7287 | return ToTemplateKeywordLocOrErr.takeError(); |
| 7288 | |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7289 | return UnresolvedLookupExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7290 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7291 | *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo, |
| 7292 | ToDecls.begin(), ToDecls.end()); |
| 7293 | } |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7294 | |
| 7295 | return UnresolvedLookupExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7296 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7297 | ToNameInfo, E->requiresADL(), E->isOverloaded(), ToDecls.begin(), |
| 7298 | ToDecls.end()); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7299 | } |
| 7300 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7301 | ExpectedStmt |
| 7302 | ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { |
| 7303 | auto Imp1 = importSeq( |
| 7304 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7305 | E->getTemplateKeywordLoc()); |
| 7306 | if (!Imp1) |
| 7307 | return Imp1.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7308 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7309 | QualType ToType; |
| 7310 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7311 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7312 | std::tie(ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc) = *Imp1; |
| 7313 | |
| 7314 | auto Imp2 = importSeq(E->getName(), E->getNameLoc()); |
| 7315 | if (!Imp2) |
| 7316 | return Imp2.takeError(); |
| 7317 | DeclarationNameInfo ToNameInfo(std::get<0>(*Imp2), std::get<1>(*Imp2)); |
| 7318 | // Import additional name location/type info. |
| 7319 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7320 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7321 | |
| 7322 | UnresolvedSet<8> ToDecls; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7323 | for (Decl *D : E->decls()) |
| 7324 | if (auto ToDOrErr = import(D)) |
| 7325 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7326 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7327 | return ToDOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7328 | |
| 7329 | TemplateArgumentListInfo ToTAInfo; |
| 7330 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7331 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7332 | if (Error Err = |
| 7333 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 7334 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7335 | ResInfo = &ToTAInfo; |
| 7336 | } |
| 7337 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7338 | Expr *ToBase = nullptr; |
| 7339 | if (!E->isImplicitAccess()) { |
| 7340 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7341 | ToBase = *ToBaseOrErr; |
| 7342 | else |
| 7343 | return ToBaseOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7344 | } |
| 7345 | |
| 7346 | return UnresolvedMemberExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7347 | Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType, |
| 7348 | E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7349 | ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end()); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7350 | } |
| 7351 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7352 | ExpectedStmt ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| 7353 | auto Imp = importSeq(E->getCallee(), E->getType(), E->getRParenLoc()); |
| 7354 | if (!Imp) |
| 7355 | return Imp.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7356 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7357 | Expr *ToCallee; |
| 7358 | QualType ToType; |
| 7359 | SourceLocation ToRParenLoc; |
| 7360 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7361 | |
| 7362 | unsigned NumArgs = E->getNumArgs(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7363 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); |
| 7364 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7365 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7366 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7367 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { |
| 7368 | return new (Importer.getToContext()) CXXOperatorCallExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7369 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType, |
| 7370 | OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures()); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7371 | } |
| 7372 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7373 | return new (Importer.getToContext()) CallExpr( |
| 7374 | Importer.getToContext(), ToCallee, ToArgs, ToType, E->getValueKind(), |
| 7375 | ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7376 | } |
| 7377 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7378 | ExpectedStmt ASTNodeImporter::VisitLambdaExpr(LambdaExpr *E) { |
| 7379 | CXXRecordDecl *FromClass = E->getLambdaClass(); |
| 7380 | auto ToClassOrErr = import(FromClass); |
| 7381 | if (!ToClassOrErr) |
| 7382 | return ToClassOrErr.takeError(); |
| 7383 | CXXRecordDecl *ToClass = *ToClassOrErr; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7384 | |
| 7385 | // NOTE: lambda classes are created with BeingDefined flag set up. |
| 7386 | // It means that ImportDefinition doesn't work for them and we should fill it |
| 7387 | // manually. |
| 7388 | if (ToClass->isBeingDefined()) { |
| 7389 | for (auto FromField : FromClass->fields()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7390 | auto ToFieldOrErr = import(FromField); |
| 7391 | if (!ToFieldOrErr) |
| 7392 | return ToFieldOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7393 | } |
| 7394 | } |
| 7395 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7396 | auto ToCallOpOrErr = import(E->getCallOperator()); |
| 7397 | if (!ToCallOpOrErr) |
| 7398 | return ToCallOpOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7399 | |
| 7400 | ToClass->completeDefinition(); |
| 7401 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7402 | SmallVector<LambdaCapture, 8> ToCaptures; |
| 7403 | ToCaptures.reserve(E->capture_size()); |
| 7404 | for (const auto &FromCapture : E->captures()) { |
| 7405 | if (auto ToCaptureOrErr = import(FromCapture)) |
| 7406 | ToCaptures.push_back(*ToCaptureOrErr); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7407 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7408 | return ToCaptureOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7409 | } |
| 7410 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7411 | SmallVector<Expr *, 8> ToCaptureInits(E->capture_size()); |
| 7412 | if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits)) |
| 7413 | return std::move(Err); |
| 7414 | |
| 7415 | auto Imp = importSeq( |
| 7416 | E->getIntroducerRange(), E->getCaptureDefaultLoc(), E->getEndLoc()); |
| 7417 | if (!Imp) |
| 7418 | return Imp.takeError(); |
| 7419 | |
| 7420 | SourceRange ToIntroducerRange; |
| 7421 | SourceLocation ToCaptureDefaultLoc, ToEndLoc; |
| 7422 | std::tie(ToIntroducerRange, ToCaptureDefaultLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7423 | |
Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 7424 | return LambdaExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7425 | Importer.getToContext(), ToClass, ToIntroducerRange, |
| 7426 | E->getCaptureDefault(), ToCaptureDefaultLoc, ToCaptures, |
| 7427 | E->hasExplicitParameters(), E->hasExplicitResultType(), ToCaptureInits, |
| 7428 | ToEndLoc, E->containsUnexpandedParameterPack()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7429 | } |
| 7430 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7431 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7432 | ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) { |
| 7433 | auto Imp = importSeq(E->getLBraceLoc(), E->getRBraceLoc(), E->getType()); |
| 7434 | if (!Imp) |
| 7435 | return Imp.takeError(); |
| 7436 | |
| 7437 | SourceLocation ToLBraceLoc, ToRBraceLoc; |
| 7438 | QualType ToType; |
| 7439 | std::tie(ToLBraceLoc, ToRBraceLoc, ToType) = *Imp; |
| 7440 | |
| 7441 | SmallVector<Expr *, 4> ToExprs(E->getNumInits()); |
| 7442 | if (Error Err = ImportContainerChecked(E->inits(), ToExprs)) |
| 7443 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7444 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7445 | ASTContext &ToCtx = Importer.getToContext(); |
| 7446 | InitListExpr *To = new (ToCtx) InitListExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7447 | ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc); |
| 7448 | To->setType(ToType); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7449 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7450 | if (E->hasArrayFiller()) { |
| 7451 | if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller())) |
| 7452 | To->setArrayFiller(*ToFillerOrErr); |
| 7453 | else |
| 7454 | return ToFillerOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7455 | } |
| 7456 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7457 | if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) { |
| 7458 | if (auto ToFDOrErr = import(FromFD)) |
| 7459 | To->setInitializedFieldInUnion(*ToFDOrErr); |
| 7460 | else |
| 7461 | return ToFDOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7462 | } |
| 7463 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7464 | if (InitListExpr *SyntForm = E->getSyntacticForm()) { |
| 7465 | if (auto ToSyntFormOrErr = import(SyntForm)) |
| 7466 | To->setSyntacticForm(*ToSyntFormOrErr); |
| 7467 | else |
| 7468 | return ToSyntFormOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7469 | } |
| 7470 | |
Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7471 | // Copy InitListExprBitfields, which are not handled in the ctor of |
| 7472 | // InitListExpr. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7473 | To->sawArrayRangeDesignator(E->hadArrayRangeDesignator()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7474 | |
| 7475 | return To; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7476 | } |
| 7477 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7478 | ExpectedStmt ASTNodeImporter::VisitCXXStdInitializerListExpr( |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7479 | CXXStdInitializerListExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7480 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7481 | if (!ToTypeOrErr) |
| 7482 | return ToTypeOrErr.takeError(); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7483 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7484 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7485 | if (!ToSubExprOrErr) |
| 7486 | return ToSubExprOrErr.takeError(); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7487 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7488 | return new (Importer.getToContext()) CXXStdInitializerListExpr( |
| 7489 | *ToTypeOrErr, *ToSubExprOrErr); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7490 | } |
| 7491 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7492 | ExpectedStmt ASTNodeImporter::VisitCXXInheritedCtorInitExpr( |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7493 | CXXInheritedCtorInitExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7494 | auto Imp = importSeq(E->getLocation(), E->getType(), E->getConstructor()); |
| 7495 | if (!Imp) |
| 7496 | return Imp.takeError(); |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7497 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7498 | SourceLocation ToLocation; |
| 7499 | QualType ToType; |
| 7500 | CXXConstructorDecl *ToConstructor; |
| 7501 | std::tie(ToLocation, ToType, ToConstructor) = *Imp; |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7502 | |
| 7503 | return new (Importer.getToContext()) CXXInheritedCtorInitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7504 | ToLocation, ToType, ToConstructor, E->constructsVBase(), |
| 7505 | E->inheritedFromVBase()); |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7506 | } |
| 7507 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7508 | ExpectedStmt ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 7509 | auto Imp = importSeq(E->getType(), E->getCommonExpr(), E->getSubExpr()); |
| 7510 | if (!Imp) |
| 7511 | return Imp.takeError(); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7512 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7513 | QualType ToType; |
| 7514 | Expr *ToCommonExpr, *ToSubExpr; |
| 7515 | std::tie(ToType, ToCommonExpr, ToSubExpr) = *Imp; |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7516 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7517 | return new (Importer.getToContext()) ArrayInitLoopExpr( |
| 7518 | ToType, ToCommonExpr, ToSubExpr); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7519 | } |
| 7520 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7521 | ExpectedStmt ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 7522 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7523 | if (!ToTypeOrErr) |
| 7524 | return ToTypeOrErr.takeError(); |
| 7525 | return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7526 | } |
| 7527 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7528 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 7529 | ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc()); |
| 7530 | if (!ToBeginLocOrErr) |
| 7531 | return ToBeginLocOrErr.takeError(); |
| 7532 | |
| 7533 | auto ToFieldOrErr = import(E->getField()); |
| 7534 | if (!ToFieldOrErr) |
| 7535 | return ToFieldOrErr.takeError(); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7536 | |
| 7537 | return CXXDefaultInitExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7538 | Importer.getToContext(), *ToBeginLocOrErr, *ToFieldOrErr); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7539 | } |
| 7540 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7541 | ExpectedStmt ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 7542 | auto Imp = importSeq( |
| 7543 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten(), |
| 7544 | E->getOperatorLoc(), E->getRParenLoc(), E->getAngleBrackets()); |
| 7545 | if (!Imp) |
| 7546 | return Imp.takeError(); |
| 7547 | |
| 7548 | QualType ToType; |
| 7549 | Expr *ToSubExpr; |
| 7550 | TypeSourceInfo *ToTypeInfoAsWritten; |
| 7551 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 7552 | SourceRange ToAngleBrackets; |
| 7553 | std::tie( |
| 7554 | ToType, ToSubExpr, ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, |
| 7555 | ToAngleBrackets) = *Imp; |
| 7556 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7557 | ExprValueKind VK = E->getValueKind(); |
| 7558 | CastKind CK = E->getCastKind(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7559 | auto ToBasePathOrErr = ImportCastPath(E); |
| 7560 | if (!ToBasePathOrErr) |
| 7561 | return ToBasePathOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7562 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7563 | if (isa<CXXStaticCastExpr>(E)) { |
| 7564 | return CXXStaticCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7565 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7566 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7567 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 7568 | return CXXDynamicCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7569 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7570 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7571 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 7572 | return CXXReinterpretCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7573 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7574 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Raphael Isemann | c705bb8 | 2018-08-20 16:20:01 +0000 | [diff] [blame] | 7575 | } else if (isa<CXXConstCastExpr>(E)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7576 | return CXXConstCastExpr::Create( |
| 7577 | Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten, |
| 7578 | ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7579 | } else { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7580 | llvm_unreachable("Unknown cast type"); |
| 7581 | return make_error<ImportError>(); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7582 | } |
| 7583 | } |
| 7584 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7585 | ExpectedStmt ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7586 | SubstNonTypeTemplateParmExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7587 | auto Imp = importSeq( |
| 7588 | E->getType(), E->getExprLoc(), E->getParameter(), E->getReplacement()); |
| 7589 | if (!Imp) |
| 7590 | return Imp.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7591 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7592 | QualType ToType; |
| 7593 | SourceLocation ToExprLoc; |
| 7594 | NonTypeTemplateParmDecl *ToParameter; |
| 7595 | Expr *ToReplacement; |
| 7596 | std::tie(ToType, ToExprLoc, ToParameter, ToReplacement) = *Imp; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7597 | |
| 7598 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7599 | ToType, E->getValueKind(), ToExprLoc, ToParameter, ToReplacement); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7600 | } |
| 7601 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7602 | ExpectedStmt ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { |
| 7603 | auto Imp = importSeq( |
| 7604 | E->getType(), E->getBeginLoc(), E->getEndLoc()); |
| 7605 | if (!Imp) |
| 7606 | return Imp.takeError(); |
| 7607 | |
| 7608 | QualType ToType; |
| 7609 | SourceLocation ToBeginLoc, ToEndLoc; |
| 7610 | std::tie(ToType, ToBeginLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7611 | |
| 7612 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7613 | if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs)) |
| 7614 | return std::move(Err); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7615 | |
| 7616 | // According to Sema::BuildTypeTrait(), if E is value-dependent, |
| 7617 | // Value is always false. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7618 | bool ToValue = (E->isValueDependent() ? false : E->getValue()); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7619 | |
| 7620 | return TypeTraitExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7621 | Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs, |
| 7622 | ToEndLoc, ToValue); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7623 | } |
| 7624 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7625 | ExpectedStmt ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { |
| 7626 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7627 | if (!ToTypeOrErr) |
| 7628 | return ToTypeOrErr.takeError(); |
| 7629 | |
| 7630 | auto ToSourceRangeOrErr = import(E->getSourceRange()); |
| 7631 | if (!ToSourceRangeOrErr) |
| 7632 | return ToSourceRangeOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7633 | |
| 7634 | if (E->isTypeOperand()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7635 | if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo())) |
| 7636 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7637 | *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr); |
| 7638 | else |
| 7639 | return ToTSIOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7640 | } |
| 7641 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7642 | ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand()); |
| 7643 | if (!ToExprOperandOrErr) |
| 7644 | return ToExprOperandOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7645 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7646 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7647 | *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7648 | } |
| 7649 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7650 | void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod, |
| 7651 | CXXMethodDecl *FromMethod) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7652 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) { |
| 7653 | if (auto ImportedOrErr = import(FromOverriddenMethod)) |
| 7654 | ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>( |
| 7655 | (*ImportedOrErr)->getCanonicalDecl())); |
| 7656 | else |
| 7657 | consumeError(ImportedOrErr.takeError()); |
| 7658 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7659 | } |
| 7660 | |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7661 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7662 | ASTContext &FromContext, FileManager &FromFileManager, |
| 7663 | bool MinimalImport) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7664 | : ToContext(ToContext), FromContext(FromContext), |
| 7665 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
| 7666 | Minimal(MinimalImport) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7667 | ImportedDecls[FromContext.getTranslationUnitDecl()] |
| 7668 | = ToContext.getTranslationUnitDecl(); |
| 7669 | } |
| 7670 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7671 | ASTImporter::~ASTImporter() = default; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7672 | |
| 7673 | QualType ASTImporter::Import(QualType FromT) { |
| 7674 | if (FromT.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7675 | return {}; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7676 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7677 | const Type *FromTy = FromT.getTypePtr(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7678 | |
| 7679 | // Check whether we've already imported this type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7680 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7681 | = ImportedTypes.find(FromTy); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7682 | if (Pos != ImportedTypes.end()) |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7683 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7684 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7685 | // Import the type |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7686 | ASTNodeImporter Importer(*this); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7687 | ExpectedType ToTOrErr = Importer.Visit(FromTy); |
| 7688 | if (!ToTOrErr) { |
| 7689 | llvm::consumeError(ToTOrErr.takeError()); |
| 7690 | return {}; |
| 7691 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7692 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7693 | // Record the imported type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7694 | ImportedTypes[FromTy] = (*ToTOrErr).getTypePtr(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7695 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7696 | return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7697 | } |
| 7698 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7699 | TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) { |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7700 | if (!FromTSI) |
| 7701 | return FromTSI; |
| 7702 | |
| 7703 | // FIXME: For now we just create a "trivial" type source info based |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 7704 | // 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] | 7705 | QualType T = Import(FromTSI->getType()); |
| 7706 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7707 | return nullptr; |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7708 | |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7709 | return ToContext.getTrivialTypeSourceInfo( |
| 7710 | T, Import(FromTSI->getTypeLoc().getBeginLoc())); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7711 | } |
| 7712 | |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 7713 | Attr *ASTImporter::Import(const Attr *FromAttr) { |
| 7714 | Attr *ToAttr = FromAttr->clone(ToContext); |
| 7715 | ToAttr->setRange(Import(FromAttr->getRange())); |
| 7716 | return ToAttr; |
| 7717 | } |
| 7718 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7719 | Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) { |
| 7720 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD); |
| 7721 | if (Pos != ImportedDecls.end()) { |
| 7722 | Decl *ToD = Pos->second; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7723 | // FIXME: move this call to ImportDeclParts(). |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7724 | if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(FromD, ToD)) |
| 7725 | llvm::consumeError(std::move(Err)); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7726 | return ToD; |
| 7727 | } else { |
| 7728 | return nullptr; |
| 7729 | } |
| 7730 | } |
| 7731 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7732 | Decl *ASTImporter::Import(Decl *FromD) { |
| 7733 | if (!FromD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7734 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7735 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7736 | ASTNodeImporter Importer(*this); |
| 7737 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7738 | // Check whether we've already imported this declaration. |
| 7739 | Decl *ToD = GetAlreadyImportedOrNull(FromD); |
| 7740 | if (ToD) { |
| 7741 | // If FromD has some updated flags after last import, apply it |
| 7742 | updateFlags(FromD, ToD); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7743 | return ToD; |
| 7744 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7745 | |
| 7746 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7747 | ExpectedDecl ToDOrErr = Importer.Visit(FromD); |
| 7748 | if (!ToDOrErr) { |
| 7749 | llvm::consumeError(ToDOrErr.takeError()); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7750 | return nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7751 | } |
| 7752 | ToD = *ToDOrErr; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7753 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7754 | // Notify subclasses. |
| 7755 | Imported(FromD, ToD); |
| 7756 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 7757 | updateFlags(FromD, ToD); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7758 | return ToD; |
| 7759 | } |
| 7760 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7761 | Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7762 | if (!FromDC) |
| 7763 | return FromDC; |
| 7764 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7765 | auto *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC))); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7766 | if (!ToDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7767 | return nullptr; |
| 7768 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7769 | // 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] | 7770 | // need it to have a definition. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7771 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
| 7772 | auto *FromRecord = cast<RecordDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7773 | if (ToRecord->isCompleteDefinition()) { |
| 7774 | // Do nothing. |
| 7775 | } else if (FromRecord->isCompleteDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7776 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7777 | FromRecord, ToRecord, ASTNodeImporter::IDK_Basic)) |
| 7778 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7779 | } else { |
| 7780 | CompleteDecl(ToRecord); |
| 7781 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7782 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 7783 | auto *FromEnum = cast<EnumDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7784 | if (ToEnum->isCompleteDefinition()) { |
| 7785 | // Do nothing. |
| 7786 | } else if (FromEnum->isCompleteDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7787 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7788 | FromEnum, ToEnum, ASTNodeImporter::IDK_Basic)) |
| 7789 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7790 | } else { |
| 7791 | CompleteDecl(ToEnum); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7792 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7793 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 7794 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7795 | if (ToClass->getDefinition()) { |
| 7796 | // Do nothing. |
| 7797 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7798 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7799 | FromDef, ToClass, ASTNodeImporter::IDK_Basic)) |
| 7800 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7801 | } else { |
| 7802 | CompleteDecl(ToClass); |
| 7803 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7804 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 7805 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7806 | if (ToProto->getDefinition()) { |
| 7807 | // Do nothing. |
| 7808 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7809 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7810 | FromDef, ToProto, ASTNodeImporter::IDK_Basic)) |
| 7811 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7812 | } else { |
| 7813 | CompleteDecl(ToProto); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7814 | } |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7815 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7816 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7817 | return ToDC; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7818 | } |
| 7819 | |
| 7820 | Expr *ASTImporter::Import(Expr *FromE) { |
| 7821 | if (!FromE) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7822 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7823 | |
| 7824 | return cast_or_null<Expr>(Import(cast<Stmt>(FromE))); |
| 7825 | } |
| 7826 | |
| 7827 | Stmt *ASTImporter::Import(Stmt *FromS) { |
| 7828 | if (!FromS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7829 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7830 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7831 | // Check whether we've already imported this declaration. |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7832 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 7833 | if (Pos != ImportedStmts.end()) |
| 7834 | return Pos->second; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7835 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7836 | // Import the statement. |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7837 | ASTNodeImporter Importer(*this); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7838 | ExpectedStmt ToSOrErr = Importer.Visit(FromS); |
| 7839 | if (!ToSOrErr) { |
| 7840 | llvm::consumeError(ToSOrErr.takeError()); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7841 | return nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7842 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7843 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7844 | if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) { |
Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7845 | auto *FromE = cast<Expr>(FromS); |
| 7846 | // Copy ExprBitfields, which may not be handled in Expr subclasses |
| 7847 | // constructors. |
| 7848 | ToE->setValueKind(FromE->getValueKind()); |
| 7849 | ToE->setObjectKind(FromE->getObjectKind()); |
| 7850 | ToE->setTypeDependent(FromE->isTypeDependent()); |
| 7851 | ToE->setValueDependent(FromE->isValueDependent()); |
| 7852 | ToE->setInstantiationDependent(FromE->isInstantiationDependent()); |
| 7853 | ToE->setContainsUnexpandedParameterPack( |
| 7854 | FromE->containsUnexpandedParameterPack()); |
| 7855 | } |
| 7856 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7857 | // Record the imported declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7858 | ImportedStmts[FromS] = *ToSOrErr; |
| 7859 | return *ToSOrErr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7860 | } |
| 7861 | |
| 7862 | NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) { |
| 7863 | if (!FromNNS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7864 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7865 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7866 | NestedNameSpecifier *prefix = Import(FromNNS->getPrefix()); |
| 7867 | |
| 7868 | switch (FromNNS->getKind()) { |
| 7869 | case NestedNameSpecifier::Identifier: |
| 7870 | if (IdentifierInfo *II = Import(FromNNS->getAsIdentifier())) { |
| 7871 | return NestedNameSpecifier::Create(ToContext, prefix, II); |
| 7872 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7873 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7874 | |
| 7875 | case NestedNameSpecifier::Namespace: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7876 | if (auto *NS = |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7877 | cast_or_null<NamespaceDecl>(Import(FromNNS->getAsNamespace()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7878 | return NestedNameSpecifier::Create(ToContext, prefix, NS); |
| 7879 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7880 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7881 | |
| 7882 | case NestedNameSpecifier::NamespaceAlias: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7883 | if (auto *NSAD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7884 | cast_or_null<NamespaceAliasDecl>(Import(FromNNS->getAsNamespaceAlias()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7885 | return NestedNameSpecifier::Create(ToContext, prefix, NSAD); |
| 7886 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7887 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7888 | |
| 7889 | case NestedNameSpecifier::Global: |
| 7890 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 7891 | |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7892 | case NestedNameSpecifier::Super: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7893 | if (auto *RD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7894 | cast_or_null<CXXRecordDecl>(Import(FromNNS->getAsRecordDecl()))) { |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7895 | return NestedNameSpecifier::SuperSpecifier(ToContext, RD); |
| 7896 | } |
| 7897 | return nullptr; |
| 7898 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7899 | case NestedNameSpecifier::TypeSpec: |
| 7900 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 7901 | QualType T = Import(QualType(FromNNS->getAsType(), 0u)); |
| 7902 | if (!T.isNull()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7903 | bool bTemplate = FromNNS->getKind() == |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7904 | NestedNameSpecifier::TypeSpecWithTemplate; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7905 | return NestedNameSpecifier::Create(ToContext, prefix, |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7906 | bTemplate, T.getTypePtr()); |
| 7907 | } |
| 7908 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7909 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7910 | } |
| 7911 | |
| 7912 | llvm_unreachable("Invalid nested name specifier kind"); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7913 | } |
| 7914 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 7915 | NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7916 | // Copied from NestedNameSpecifier mostly. |
| 7917 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 7918 | NestedNameSpecifierLoc NNS = FromNNS; |
| 7919 | |
| 7920 | // Push each of the nested-name-specifiers's onto a stack for |
| 7921 | // serialization in reverse order. |
| 7922 | while (NNS) { |
| 7923 | NestedNames.push_back(NNS); |
| 7924 | NNS = NNS.getPrefix(); |
| 7925 | } |
| 7926 | |
| 7927 | NestedNameSpecifierLocBuilder Builder; |
| 7928 | |
| 7929 | while (!NestedNames.empty()) { |
| 7930 | NNS = NestedNames.pop_back_val(); |
| 7931 | NestedNameSpecifier *Spec = Import(NNS.getNestedNameSpecifier()); |
| 7932 | if (!Spec) |
| 7933 | return NestedNameSpecifierLoc(); |
| 7934 | |
| 7935 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
| 7936 | switch (Kind) { |
| 7937 | case NestedNameSpecifier::Identifier: |
| 7938 | Builder.Extend(getToContext(), |
| 7939 | Spec->getAsIdentifier(), |
| 7940 | Import(NNS.getLocalBeginLoc()), |
| 7941 | Import(NNS.getLocalEndLoc())); |
| 7942 | break; |
| 7943 | |
| 7944 | case NestedNameSpecifier::Namespace: |
| 7945 | Builder.Extend(getToContext(), |
| 7946 | Spec->getAsNamespace(), |
| 7947 | Import(NNS.getLocalBeginLoc()), |
| 7948 | Import(NNS.getLocalEndLoc())); |
| 7949 | break; |
| 7950 | |
| 7951 | case NestedNameSpecifier::NamespaceAlias: |
| 7952 | Builder.Extend(getToContext(), |
| 7953 | Spec->getAsNamespaceAlias(), |
| 7954 | Import(NNS.getLocalBeginLoc()), |
| 7955 | Import(NNS.getLocalEndLoc())); |
| 7956 | break; |
| 7957 | |
| 7958 | case NestedNameSpecifier::TypeSpec: |
| 7959 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 7960 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
| 7961 | QualType(Spec->getAsType(), 0)); |
| 7962 | Builder.Extend(getToContext(), |
| 7963 | Import(NNS.getLocalBeginLoc()), |
| 7964 | TSI->getTypeLoc(), |
| 7965 | Import(NNS.getLocalEndLoc())); |
| 7966 | break; |
| 7967 | } |
| 7968 | |
| 7969 | case NestedNameSpecifier::Global: |
| 7970 | Builder.MakeGlobal(getToContext(), Import(NNS.getLocalBeginLoc())); |
| 7971 | break; |
| 7972 | |
| 7973 | case NestedNameSpecifier::Super: { |
| 7974 | SourceRange ToRange = Import(NNS.getSourceRange()); |
| 7975 | Builder.MakeSuper(getToContext(), |
| 7976 | Spec->getAsRecordDecl(), |
| 7977 | ToRange.getBegin(), |
| 7978 | ToRange.getEnd()); |
| 7979 | } |
| 7980 | } |
| 7981 | } |
| 7982 | |
| 7983 | return Builder.getWithLocInContext(getToContext()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 7984 | } |
| 7985 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7986 | TemplateName ASTImporter::Import(TemplateName From) { |
| 7987 | switch (From.getKind()) { |
| 7988 | case TemplateName::Template: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7989 | if (auto *ToTemplate = |
| 7990 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7991 | return TemplateName(ToTemplate); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7992 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7993 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7994 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7995 | case TemplateName::OverloadedTemplate: { |
| 7996 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 7997 | UnresolvedSet<2> ToTemplates; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7998 | for (auto *I : *FromStorage) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7999 | if (auto *To = cast_or_null<NamedDecl>(Import(I))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8000 | ToTemplates.addDecl(To); |
| 8001 | else |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8002 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8003 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8004 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8005 | ToTemplates.end()); |
| 8006 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8007 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8008 | case TemplateName::QualifiedTemplate: { |
| 8009 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
| 8010 | NestedNameSpecifier *Qualifier = Import(QTN->getQualifier()); |
| 8011 | if (!Qualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8012 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8013 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8014 | if (auto *ToTemplate = |
| 8015 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8016 | return ToContext.getQualifiedTemplateName(Qualifier, |
| 8017 | QTN->hasTemplateKeyword(), |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8018 | ToTemplate); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8019 | |
| 8020 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8021 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8022 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8023 | case TemplateName::DependentTemplate: { |
| 8024 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
| 8025 | NestedNameSpecifier *Qualifier = Import(DTN->getQualifier()); |
| 8026 | if (!Qualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8027 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8028 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8029 | if (DTN->isIdentifier()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8030 | return ToContext.getDependentTemplateName(Qualifier, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8031 | Import(DTN->getIdentifier())); |
| 8032 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8033 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8034 | return ToContext.getDependentTemplateName(Qualifier, DTN->getOperator()); |
| 8035 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8036 | |
| 8037 | case TemplateName::SubstTemplateTemplateParm: { |
| 8038 | SubstTemplateTemplateParmStorage *subst |
| 8039 | = From.getAsSubstTemplateTemplateParm(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8040 | auto *param = |
| 8041 | cast_or_null<TemplateTemplateParmDecl>(Import(subst->getParameter())); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8042 | if (!param) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8043 | return {}; |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8044 | |
| 8045 | TemplateName replacement = Import(subst->getReplacement()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8046 | if (replacement.isNull()) |
| 8047 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8048 | |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8049 | return ToContext.getSubstTemplateTemplateParm(param, replacement); |
| 8050 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8051 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8052 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 8053 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 8054 | = From.getAsSubstTemplateTemplateParmPack(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8055 | auto *Param = |
| 8056 | cast_or_null<TemplateTemplateParmDecl>( |
| 8057 | Import(SubstPack->getParameterPack())); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8058 | if (!Param) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8059 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8060 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8061 | ASTNodeImporter Importer(*this); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8062 | Expected<TemplateArgument> ArgPack |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8063 | = Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8064 | if (!ArgPack) { |
| 8065 | llvm::consumeError(ArgPack.takeError()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8066 | return {}; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8067 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8068 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8069 | return ToContext.getSubstTemplateTemplateParmPack(Param, *ArgPack); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8070 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8071 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8072 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8073 | llvm_unreachable("Invalid template name kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8074 | } |
| 8075 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8076 | SourceLocation ASTImporter::Import(SourceLocation FromLoc) { |
| 8077 | if (FromLoc.isInvalid()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8078 | return {}; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8079 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8080 | SourceManager &FromSM = FromContext.getSourceManager(); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8081 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8082 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
Sean Callanan | 238d897 | 2014-12-10 01:26:39 +0000 | [diff] [blame] | 8083 | FileID ToFileID = Import(Decomposed.first); |
| 8084 | if (ToFileID.isInvalid()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8085 | return {}; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8086 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 8087 | return ToSM.getComposedLoc(ToFileID, Decomposed.second); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8088 | } |
| 8089 | |
| 8090 | SourceRange ASTImporter::Import(SourceRange FromRange) { |
| 8091 | return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd())); |
| 8092 | } |
| 8093 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8094 | FileID ASTImporter::Import(FileID FromID) { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8095 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8096 | if (Pos != ImportedFileIDs.end()) |
| 8097 | return Pos->second; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8098 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8099 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 8100 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 8101 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8102 | |
| 8103 | // Map the FromID to the "to" source manager. |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8104 | FileID ToID; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8105 | if (FromSLoc.isExpansion()) { |
| 8106 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); |
| 8107 | SourceLocation ToSpLoc = Import(FromEx.getSpellingLoc()); |
| 8108 | SourceLocation ToExLocS = Import(FromEx.getExpansionLocStart()); |
| 8109 | unsigned TokenLen = FromSM.getFileIDSize(FromID); |
| 8110 | SourceLocation MLoc; |
| 8111 | if (FromEx.isMacroArgExpansion()) { |
| 8112 | MLoc = ToSM.createMacroArgExpansionLoc(ToSpLoc, ToExLocS, TokenLen); |
| 8113 | } else { |
| 8114 | SourceLocation ToExLocE = Import(FromEx.getExpansionLocEnd()); |
| 8115 | MLoc = ToSM.createExpansionLoc(ToSpLoc, ToExLocS, ToExLocE, TokenLen, |
| 8116 | FromEx.isExpansionTokenRange()); |
| 8117 | } |
| 8118 | ToID = ToSM.getFileID(MLoc); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8119 | } else { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8120 | // Include location of this file. |
| 8121 | SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); |
| 8122 | |
| 8123 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
| 8124 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
| 8125 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 8126 | // disk again |
| 8127 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 8128 | // than mmap the files several times. |
| 8129 | const FileEntry *Entry = |
| 8130 | ToFileManager.getFile(Cache->OrigEntry->getName()); |
| 8131 | if (!Entry) |
| 8132 | return {}; |
| 8133 | ToID = ToSM.createFileID(Entry, ToIncludeLoc, |
| 8134 | FromSLoc.getFile().getFileCharacteristic()); |
| 8135 | } else { |
| 8136 | // FIXME: We want to re-use the existing MemoryBuffer! |
| 8137 | const llvm::MemoryBuffer *FromBuf = |
| 8138 | Cache->getBuffer(FromContext.getDiagnostics(), FromSM); |
| 8139 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = |
| 8140 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
| 8141 | FromBuf->getBufferIdentifier()); |
| 8142 | ToID = ToSM.createFileID(std::move(ToBuf), |
| 8143 | FromSLoc.getFile().getFileCharacteristic()); |
| 8144 | } |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8145 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8146 | |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 8147 | ImportedFileIDs[FromID] = ToID; |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8148 | return ToID; |
| 8149 | } |
| 8150 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8151 | CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) { |
| 8152 | Expr *ToExpr = Import(From->getInit()); |
| 8153 | if (!ToExpr && From->getInit()) |
| 8154 | return nullptr; |
| 8155 | |
| 8156 | if (From->isBaseInitializer()) { |
| 8157 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 8158 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 8159 | return nullptr; |
| 8160 | |
| 8161 | return new (ToContext) CXXCtorInitializer( |
| 8162 | ToContext, ToTInfo, From->isBaseVirtual(), Import(From->getLParenLoc()), |
| 8163 | ToExpr, Import(From->getRParenLoc()), |
| 8164 | From->isPackExpansion() ? Import(From->getEllipsisLoc()) |
| 8165 | : SourceLocation()); |
| 8166 | } else if (From->isMemberInitializer()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8167 | auto *ToField = cast_or_null<FieldDecl>(Import(From->getMember())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8168 | if (!ToField && From->getMember()) |
| 8169 | return nullptr; |
| 8170 | |
| 8171 | return new (ToContext) CXXCtorInitializer( |
| 8172 | ToContext, ToField, Import(From->getMemberLocation()), |
| 8173 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 8174 | } else if (From->isIndirectMemberInitializer()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8175 | auto *ToIField = cast_or_null<IndirectFieldDecl>( |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8176 | Import(From->getIndirectMember())); |
| 8177 | if (!ToIField && From->getIndirectMember()) |
| 8178 | return nullptr; |
| 8179 | |
| 8180 | return new (ToContext) CXXCtorInitializer( |
| 8181 | ToContext, ToIField, Import(From->getMemberLocation()), |
| 8182 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 8183 | } else if (From->isDelegatingInitializer()) { |
| 8184 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 8185 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 8186 | return nullptr; |
| 8187 | |
| 8188 | return new (ToContext) |
| 8189 | CXXCtorInitializer(ToContext, ToTInfo, Import(From->getLParenLoc()), |
| 8190 | ToExpr, Import(From->getRParenLoc())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8191 | } else { |
| 8192 | return nullptr; |
| 8193 | } |
| 8194 | } |
| 8195 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8196 | CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { |
| 8197 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 8198 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 8199 | return Pos->second; |
| 8200 | |
| 8201 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
| 8202 | Import(BaseSpec->getSourceRange()), |
| 8203 | BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 8204 | BaseSpec->getAccessSpecifierAsWritten(), |
| 8205 | Import(BaseSpec->getTypeSourceInfo()), |
| 8206 | Import(BaseSpec->getEllipsisLoc())); |
| 8207 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 8208 | return Imported; |
| 8209 | } |
| 8210 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8211 | Error ASTImporter::ImportDefinition_New(Decl *From) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8212 | Decl *To = Import(From); |
| 8213 | if (!To) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8214 | return llvm::make_error<ImportError>(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8215 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8216 | if (auto *FromDC = cast<DeclContext>(From)) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8217 | ASTNodeImporter Importer(*this); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8218 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8219 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 8220 | if (!ToRecord->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8221 | return Importer.ImportDefinition( |
| 8222 | cast<RecordDecl>(FromDC), ToRecord, |
| 8223 | ASTNodeImporter::IDK_Everything); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8224 | } |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 8225 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8226 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8227 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8228 | if (!ToEnum->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8229 | return Importer.ImportDefinition( |
| 8230 | cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8231 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8232 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8233 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8234 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 8235 | if (!ToIFace->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8236 | return Importer.ImportDefinition( |
| 8237 | cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
| 8238 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 8239 | } |
| 8240 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8241 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8242 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 8243 | if (!ToProto->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8244 | return Importer.ImportDefinition( |
| 8245 | cast<ObjCProtocolDecl>(FromDC), ToProto, |
| 8246 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 8247 | } |
| 8248 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8249 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8250 | return Importer.ImportDeclContext(FromDC, true); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8251 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8252 | |
| 8253 | return Error::success(); |
| 8254 | } |
| 8255 | |
| 8256 | void ASTImporter::ImportDefinition(Decl *From) { |
| 8257 | Error Err = ImportDefinition_New(From); |
| 8258 | llvm::consumeError(std::move(Err)); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8259 | } |
| 8260 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8261 | DeclarationName ASTImporter::Import(DeclarationName FromName) { |
| 8262 | if (!FromName) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8263 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8264 | |
| 8265 | switch (FromName.getNameKind()) { |
| 8266 | case DeclarationName::Identifier: |
| 8267 | return Import(FromName.getAsIdentifierInfo()); |
| 8268 | |
| 8269 | case DeclarationName::ObjCZeroArgSelector: |
| 8270 | case DeclarationName::ObjCOneArgSelector: |
| 8271 | case DeclarationName::ObjCMultiArgSelector: |
| 8272 | return Import(FromName.getObjCSelector()); |
| 8273 | |
| 8274 | case DeclarationName::CXXConstructorName: { |
| 8275 | QualType T = Import(FromName.getCXXNameType()); |
| 8276 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8277 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8278 | |
| 8279 | return ToContext.DeclarationNames.getCXXConstructorName( |
| 8280 | ToContext.getCanonicalType(T)); |
| 8281 | } |
| 8282 | |
| 8283 | case DeclarationName::CXXDestructorName: { |
| 8284 | QualType T = Import(FromName.getCXXNameType()); |
| 8285 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8286 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8287 | |
| 8288 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 8289 | ToContext.getCanonicalType(T)); |
| 8290 | } |
| 8291 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8292 | case DeclarationName::CXXDeductionGuideName: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8293 | auto *Template = cast_or_null<TemplateDecl>( |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8294 | Import(FromName.getCXXDeductionGuideTemplate())); |
| 8295 | if (!Template) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8296 | return {}; |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8297 | return ToContext.DeclarationNames.getCXXDeductionGuideName(Template); |
| 8298 | } |
| 8299 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8300 | case DeclarationName::CXXConversionFunctionName: { |
| 8301 | QualType T = Import(FromName.getCXXNameType()); |
| 8302 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8303 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8304 | |
| 8305 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 8306 | ToContext.getCanonicalType(T)); |
| 8307 | } |
| 8308 | |
| 8309 | case DeclarationName::CXXOperatorName: |
| 8310 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 8311 | FromName.getCXXOverloadedOperator()); |
| 8312 | |
| 8313 | case DeclarationName::CXXLiteralOperatorName: |
| 8314 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
| 8315 | Import(FromName.getCXXLiteralIdentifier())); |
| 8316 | |
| 8317 | case DeclarationName::CXXUsingDirective: |
| 8318 | // FIXME: STATICS! |
| 8319 | return DeclarationName::getUsingDirectiveName(); |
| 8320 | } |
| 8321 | |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 8322 | llvm_unreachable("Invalid DeclarationName Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8323 | } |
| 8324 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8325 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8326 | if (!FromId) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8327 | return nullptr; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8328 | |
Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 8329 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 8330 | |
| 8331 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 8332 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 8333 | |
| 8334 | return ToId; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8335 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8336 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8337 | Selector ASTImporter::Import(Selector FromSel) { |
| 8338 | if (FromSel.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8339 | return {}; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8340 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 8341 | SmallVector<IdentifierInfo *, 4> Idents; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8342 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 8343 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 8344 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 8345 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 8346 | } |
| 8347 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8348 | DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, |
| 8349 | DeclContext *DC, |
| 8350 | unsigned IDNS, |
| 8351 | NamedDecl **Decls, |
| 8352 | unsigned NumDecls) { |
| 8353 | return Name; |
| 8354 | } |
| 8355 | |
| 8356 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8357 | if (LastDiagFromFrom) |
| 8358 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8359 | FromContext.getDiagnostics()); |
| 8360 | LastDiagFromFrom = false; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8361 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8362 | } |
| 8363 | |
| 8364 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8365 | if (!LastDiagFromFrom) |
| 8366 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8367 | ToContext.getDiagnostics()); |
| 8368 | LastDiagFromFrom = true; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8369 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8370 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8371 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8372 | void ASTImporter::CompleteDecl (Decl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8373 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8374 | if (!ID->getDefinition()) |
| 8375 | ID->startDefinition(); |
| 8376 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8377 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8378 | if (!PD->getDefinition()) |
| 8379 | PD->startDefinition(); |
| 8380 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8381 | else if (auto *TD = dyn_cast<TagDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8382 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 8383 | TD->startDefinition(); |
| 8384 | TD->setCompleteDefinition(true); |
| 8385 | } |
| 8386 | } |
| 8387 | else { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8388 | assert(0 && "CompleteDecl called on a Decl that can't be completed"); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8389 | } |
| 8390 | } |
| 8391 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8392 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { |
| 8393 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); |
| 8394 | assert((Pos == ImportedDecls.end() || Pos->second == To) && |
| 8395 | "Try to import an already imported Decl"); |
| 8396 | if (Pos != ImportedDecls.end()) |
| 8397 | return Pos->second; |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8398 | ImportedDecls[From] = To; |
| 8399 | return To; |
Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 8400 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8401 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8402 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 8403 | bool Complain) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 8404 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8405 | = ImportedTypes.find(From.getTypePtr()); |
| 8406 | if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To)) |
| 8407 | return true; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 8408 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8409 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8410 | getStructuralEquivalenceKind(*this), false, |
| 8411 | Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 8412 | return Ctx.IsEquivalent(From, To); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8413 | } |