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; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3147 | } else if (isa<CXXDestructorDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3148 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3149 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3150 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| 3151 | D->isImplicit())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3152 | return ToFunction; |
| 3153 | } else if (CXXConversionDecl *FromConversion = |
| 3154 | dyn_cast<CXXConversionDecl>(D)) { |
| 3155 | if (GetImportedOrCreateDecl<CXXConversionDecl>( |
| 3156 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3157 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3158 | FromConversion->isExplicit(), D->isConstexpr(), SourceLocation())) |
| 3159 | return ToFunction; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3160 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3161 | if (GetImportedOrCreateDecl<CXXMethodDecl>( |
| 3162 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3163 | ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3164 | Method->isInlineSpecified(), D->isConstexpr(), SourceLocation())) |
| 3165 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3166 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3167 | if (GetImportedOrCreateDecl(ToFunction, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3168 | ToInnerLocStart, NameInfo, T, TInfo, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3169 | D->getStorageClass(), D->isInlineSpecified(), |
| 3170 | D->hasWrittenPrototype(), D->isConstexpr())) |
| 3171 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3172 | } |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3173 | |
Gabor Marton | f5e4f0a | 2018-11-20 14:19:39 +0000 | [diff] [blame] | 3174 | // Connect the redecl chain. |
| 3175 | if (FoundByLookup) { |
| 3176 | auto *Recent = const_cast<FunctionDecl *>( |
| 3177 | FoundByLookup->getMostRecentDecl()); |
| 3178 | ToFunction->setPreviousDecl(Recent); |
| 3179 | } |
| 3180 | |
| 3181 | // Import Ctor initializers. |
| 3182 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
| 3183 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
| 3184 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers); |
| 3185 | // Import first, then allocate memory and copy if there was no error. |
| 3186 | if (Error Err = ImportContainerChecked( |
| 3187 | FromConstructor->inits(), CtorInitializers)) |
| 3188 | return std::move(Err); |
| 3189 | auto **Memory = |
| 3190 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 3191 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
| 3192 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); |
| 3193 | ToCtor->setCtorInitializers(Memory); |
| 3194 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 3195 | } |
| 3196 | } |
| 3197 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3198 | ToFunction->setQualifierInfo(ToQualifierLoc); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3199 | ToFunction->setAccess(D->getAccess()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3200 | ToFunction->setLexicalDeclContext(LexicalDC); |
John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 3201 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 3202 | ToFunction->setTrivial(D->isTrivial()); |
| 3203 | ToFunction->setPure(D->isPure()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3204 | ToFunction->setRangeEnd(ToEndLoc); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3205 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3206 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3207 | for (auto *Param : Parameters) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3208 | Param->setOwningFunction(ToFunction); |
| 3209 | ToFunction->addDeclInternal(Param); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3210 | } |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 3211 | ToFunction->setParams(Parameters); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3212 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3213 | // We need to complete creation of FunctionProtoTypeLoc manually with setting |
| 3214 | // params it refers to. |
| 3215 | if (TInfo) { |
| 3216 | if (auto ProtoLoc = |
| 3217 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { |
| 3218 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) |
| 3219 | ProtoLoc.setParam(I, Parameters[I]); |
| 3220 | } |
| 3221 | } |
| 3222 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3223 | if (usedDifferentExceptionSpec) { |
| 3224 | // Update FunctionProtoType::ExtProtoInfo. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3225 | if (ExpectedType TyOrErr = import(D->getType())) |
| 3226 | ToFunction->setType(*TyOrErr); |
| 3227 | else |
| 3228 | return TyOrErr.takeError(); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 3229 | } |
| 3230 | |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3231 | // Import the describing template function, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3232 | if (FromFT) { |
| 3233 | auto ToFTOrErr = import(FromFT); |
| 3234 | if (!ToFTOrErr) |
| 3235 | return ToFTOrErr.takeError(); |
| 3236 | } |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3237 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3238 | if (D->doesThisDeclarationHaveABody()) { |
| 3239 | if (Stmt *FromBody = D->getBody()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3240 | if (ExpectedStmt ToBodyOrErr = import(FromBody)) |
| 3241 | ToFunction->setBody(*ToBodyOrErr); |
| 3242 | else |
| 3243 | return ToBodyOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3244 | } |
| 3245 | } |
| 3246 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3247 | // FIXME: Other bits to merge? |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3248 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3249 | // If it is a template, import all related things. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3250 | if (Error Err = ImportTemplateInformation(D, ToFunction)) |
| 3251 | return std::move(Err); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3252 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3253 | bool IsFriend = D->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend); |
| 3254 | |
| 3255 | // TODO Can we generalize this approach to other AST nodes as well? |
| 3256 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 3257 | DC->addDeclInternal(ToFunction); |
| 3258 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3259 | LexicalDC->addDeclInternal(ToFunction); |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3260 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3261 | // Friend declaration's lexical context is the befriending class, but the |
| 3262 | // semantic context is the enclosing scope of the befriending class. |
| 3263 | // We want the friend functions to be found in the semantic context by lookup. |
| 3264 | // FIXME should we handle this generically in VisitFriendDecl? |
| 3265 | // In Other cases when LexicalDC != DC we don't want it to be added, |
| 3266 | // e.g out-of-class definitions like void B::f() {} . |
| 3267 | if (LexicalDC != DC && IsFriend) { |
| 3268 | DC->makeDeclVisibleInContext(ToFunction); |
| 3269 | } |
| 3270 | |
Gabor Marton | 7a0841e | 2018-10-29 10:18:28 +0000 | [diff] [blame] | 3271 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) |
| 3272 | ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod); |
| 3273 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3274 | // Import the rest of the chain. I.e. import all subsequent declarations. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3275 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3276 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 3277 | if (!ToRedeclOrErr) |
| 3278 | return ToRedeclOrErr.takeError(); |
| 3279 | } |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3280 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3281 | return ToFunction; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3282 | } |
| 3283 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3284 | ExpectedDecl ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3285 | return VisitFunctionDecl(D); |
| 3286 | } |
| 3287 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3288 | ExpectedDecl ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3289 | return VisitCXXMethodDecl(D); |
| 3290 | } |
| 3291 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3292 | ExpectedDecl ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3293 | return VisitCXXMethodDecl(D); |
| 3294 | } |
| 3295 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3296 | ExpectedDecl ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3297 | return VisitCXXMethodDecl(D); |
| 3298 | } |
| 3299 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3300 | ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3301 | // Import the major distinguishing characteristics of a variable. |
| 3302 | DeclContext *DC, *LexicalDC; |
| 3303 | DeclarationName Name; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3304 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3305 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3306 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3307 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3308 | if (ToD) |
| 3309 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3310 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3311 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3312 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3313 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3314 | for (auto *FoundDecl : FoundDecls) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3315 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3316 | // For anonymous fields, match up by index. |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3317 | if (!Name && |
| 3318 | ASTImporter::getFieldIndex(D) != |
| 3319 | ASTImporter::getFieldIndex(FoundField)) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3320 | continue; |
| 3321 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3322 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3323 | FoundField->getType())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3324 | Importer.MapImported(D, FoundField); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3325 | // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the |
| 3326 | // initializer of a FieldDecl might not had been instantiated in the |
| 3327 | // "To" context. However, the "From" context might instantiated that, |
| 3328 | // thus we have to merge that. |
| 3329 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
| 3330 | // We don't have yet the initializer set. |
| 3331 | if (FoundField->hasInClassInitializer() && |
| 3332 | !FoundField->getInClassInitializer()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3333 | if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) |
| 3334 | FoundField->setInClassInitializer(*ToInitializerOrErr); |
| 3335 | else { |
| 3336 | // We can't return error here, |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3337 | // since we already mapped D as imported. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3338 | // FIXME: warning message? |
| 3339 | consumeError(ToInitializerOrErr.takeError()); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3340 | return FoundField; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3341 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3342 | } |
| 3343 | } |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3344 | return FoundField; |
| 3345 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3346 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3347 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3348 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 3349 | << Name << D->getType() << FoundField->getType(); |
| 3350 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3351 | << FoundField->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3352 | |
| 3353 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3354 | } |
| 3355 | } |
| 3356 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3357 | QualType ToType; |
| 3358 | TypeSourceInfo *ToTInfo; |
| 3359 | Expr *ToBitWidth; |
| 3360 | SourceLocation ToInnerLocStart; |
| 3361 | Expr *ToInitializer; |
| 3362 | if (auto Imp = importSeq( |
| 3363 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), |
| 3364 | D->getInnerLocStart(), D->getInClassInitializer())) |
| 3365 | std::tie( |
| 3366 | ToType, ToTInfo, ToBitWidth, ToInnerLocStart, ToInitializer) = *Imp; |
| 3367 | else |
| 3368 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3369 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3370 | FieldDecl *ToField; |
| 3371 | if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3372 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3373 | ToType, ToTInfo, ToBitWidth, D->isMutable(), |
| 3374 | D->getInClassInitStyle())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3375 | return ToField; |
| 3376 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3377 | ToField->setAccess(D->getAccess()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3378 | ToField->setLexicalDeclContext(LexicalDC); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3379 | if (ToInitializer) |
| 3380 | ToField->setInClassInitializer(ToInitializer); |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3381 | ToField->setImplicit(D->isImplicit()); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3382 | LexicalDC->addDeclInternal(ToField); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3383 | return ToField; |
| 3384 | } |
| 3385 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3386 | ExpectedDecl ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3387 | // Import the major distinguishing characteristics of a variable. |
| 3388 | DeclContext *DC, *LexicalDC; |
| 3389 | DeclarationName Name; |
| 3390 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3391 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3392 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3393 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3394 | if (ToD) |
| 3395 | return ToD; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3396 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3397 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3398 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3399 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3400 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3401 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3402 | // For anonymous indirect fields, match up by index. |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3403 | if (!Name && |
| 3404 | ASTImporter::getFieldIndex(D) != |
| 3405 | ASTImporter::getFieldIndex(FoundField)) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3406 | continue; |
| 3407 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3408 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3409 | FoundField->getType(), |
David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 3410 | !Name.isEmpty())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3411 | Importer.MapImported(D, FoundField); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3412 | return FoundField; |
| 3413 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3414 | |
| 3415 | // If there are more anonymous fields to check, continue. |
| 3416 | if (!Name && I < N-1) |
| 3417 | continue; |
| 3418 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3419 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3420 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 3421 | << Name << D->getType() << FoundField->getType(); |
| 3422 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3423 | << FoundField->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3424 | |
| 3425 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3426 | } |
| 3427 | } |
| 3428 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3429 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3430 | auto TypeOrErr = import(D->getType()); |
| 3431 | if (!TypeOrErr) |
| 3432 | return TypeOrErr.takeError(); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3433 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3434 | auto **NamedChain = |
| 3435 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3436 | |
| 3437 | unsigned i = 0; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3438 | for (auto *PI : D->chain()) |
| 3439 | if (Expected<NamedDecl *> ToD = import(PI)) |
| 3440 | NamedChain[i++] = *ToD; |
| 3441 | else |
| 3442 | return ToD.takeError(); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3443 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3444 | llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()}; |
| 3445 | IndirectFieldDecl *ToIndirectField; |
| 3446 | if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3447 | Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3448 | // FIXME here we leak `NamedChain` which is allocated before |
| 3449 | return ToIndirectField; |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 3450 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3451 | for (const auto *Attr : D->attrs()) |
| 3452 | ToIndirectField->addAttr(Importer.Import(Attr)); |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 3453 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3454 | ToIndirectField->setAccess(D->getAccess()); |
| 3455 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3456 | LexicalDC->addDeclInternal(ToIndirectField); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3457 | return ToIndirectField; |
| 3458 | } |
| 3459 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3460 | ExpectedDecl ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3461 | // Import the major distinguishing characteristics of a declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3462 | DeclContext *DC, *LexicalDC; |
| 3463 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 3464 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3465 | |
| 3466 | // Determine whether we've already imported this decl. |
| 3467 | // FriendDecl is not a NamedDecl so we cannot use localUncachedLookup. |
| 3468 | auto *RD = cast<CXXRecordDecl>(DC); |
| 3469 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3470 | |
| 3471 | while (ImportedFriend) { |
| 3472 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 3473 | if (IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(), |
| 3474 | /*Complain=*/false)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3475 | return Importer.MapImported(D, ImportedFriend); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3476 | |
| 3477 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| 3478 | if (Importer.IsStructurallyEquivalent( |
| 3479 | D->getFriendType()->getType(), |
| 3480 | ImportedFriend->getFriendType()->getType(), true)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3481 | return Importer.MapImported(D, ImportedFriend); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3482 | } |
| 3483 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 3484 | } |
| 3485 | |
| 3486 | // Not found. Create it. |
| 3487 | FriendDecl::FriendUnion ToFU; |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3488 | if (NamedDecl *FriendD = D->getFriendDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3489 | NamedDecl *ToFriendD; |
| 3490 | if (Error Err = importInto(ToFriendD, FriendD)) |
| 3491 | return std::move(Err); |
| 3492 | |
| 3493 | if (FriendD->getFriendObjectKind() != Decl::FOK_None && |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3494 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) |
| 3495 | ToFriendD->setObjectOfFriendDecl(false); |
| 3496 | |
| 3497 | ToFU = ToFriendD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3498 | } else { // The friend is a type, not a decl. |
| 3499 | if (auto TSIOrErr = import(D->getFriendType())) |
| 3500 | ToFU = *TSIOrErr; |
| 3501 | else |
| 3502 | return TSIOrErr.takeError(); |
| 3503 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3504 | |
| 3505 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3506 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3507 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3508 | if (auto ListOrErr = ImportTemplateParameterList(FromTPLists[I])) |
| 3509 | ToTPLists[I] = *ListOrErr; |
| 3510 | else |
| 3511 | return ListOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3512 | } |
| 3513 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3514 | auto LocationOrErr = import(D->getLocation()); |
| 3515 | if (!LocationOrErr) |
| 3516 | return LocationOrErr.takeError(); |
| 3517 | auto FriendLocOrErr = import(D->getFriendLoc()); |
| 3518 | if (!FriendLocOrErr) |
| 3519 | return FriendLocOrErr.takeError(); |
| 3520 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3521 | FriendDecl *FrD; |
| 3522 | if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3523 | *LocationOrErr, ToFU, |
| 3524 | *FriendLocOrErr, ToTPLists)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3525 | return FrD; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3526 | |
| 3527 | FrD->setAccess(D->getAccess()); |
| 3528 | FrD->setLexicalDeclContext(LexicalDC); |
| 3529 | LexicalDC->addDeclInternal(FrD); |
| 3530 | return FrD; |
| 3531 | } |
| 3532 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3533 | ExpectedDecl ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3534 | // Import the major distinguishing characteristics of an ivar. |
| 3535 | DeclContext *DC, *LexicalDC; |
| 3536 | DeclarationName Name; |
| 3537 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3538 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3539 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3540 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3541 | if (ToD) |
| 3542 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3543 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3544 | // Determine whether we've already imported this ivar |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3545 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3546 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3547 | for (auto *FoundDecl : FoundDecls) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3548 | if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3549 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3550 | FoundIvar->getType())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3551 | Importer.MapImported(D, FoundIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3552 | return FoundIvar; |
| 3553 | } |
| 3554 | |
| 3555 | Importer.ToDiag(Loc, diag::err_odr_ivar_type_inconsistent) |
| 3556 | << Name << D->getType() << FoundIvar->getType(); |
| 3557 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) |
| 3558 | << FoundIvar->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3559 | |
| 3560 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3561 | } |
| 3562 | } |
| 3563 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3564 | QualType ToType; |
| 3565 | TypeSourceInfo *ToTypeSourceInfo; |
| 3566 | Expr *ToBitWidth; |
| 3567 | SourceLocation ToInnerLocStart; |
| 3568 | if (auto Imp = importSeq( |
| 3569 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), D->getInnerLocStart())) |
| 3570 | std::tie(ToType, ToTypeSourceInfo, ToBitWidth, ToInnerLocStart) = *Imp; |
| 3571 | else |
| 3572 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3573 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3574 | ObjCIvarDecl *ToIvar; |
| 3575 | if (GetImportedOrCreateDecl( |
| 3576 | ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3577 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3578 | ToType, ToTypeSourceInfo, |
| 3579 | D->getAccessControl(),ToBitWidth, D->getSynthesize())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3580 | return ToIvar; |
| 3581 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3582 | ToIvar->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3583 | LexicalDC->addDeclInternal(ToIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3584 | return ToIvar; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3585 | } |
| 3586 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3587 | ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) { |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3588 | |
| 3589 | SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D); |
| 3590 | auto RedeclIt = Redecls.begin(); |
| 3591 | // Import the first part of the decl chain. I.e. import all previous |
| 3592 | // declarations starting from the canonical decl. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3593 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 3594 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3595 | if (!RedeclOrErr) |
| 3596 | return RedeclOrErr.takeError(); |
| 3597 | } |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3598 | assert(*RedeclIt == D); |
| 3599 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3600 | // Import the major distinguishing characteristics of a variable. |
| 3601 | DeclContext *DC, *LexicalDC; |
| 3602 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3603 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3604 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3605 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3606 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3607 | if (ToD) |
| 3608 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3609 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3610 | // Try to find a variable in our own ("to") context with the same name and |
| 3611 | // in the same context as the variable we're importing. |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3612 | VarDecl *FoundByLookup = nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3613 | if (D->isFileVarDecl()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3614 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3615 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3616 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3617 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3618 | for (auto *FoundDecl : FoundDecls) { |
| 3619 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3620 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3621 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3622 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3623 | // 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] | 3624 | if (FoundVar->hasExternalFormalLinkage() && |
| 3625 | D->hasExternalFormalLinkage()) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3626 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3627 | FoundVar->getType())) { |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3628 | |
| 3629 | // The VarDecl in the "From" context has a definition, but in the |
| 3630 | // "To" context we already have a definition. |
| 3631 | VarDecl *FoundDef = FoundVar->getDefinition(); |
| 3632 | if (D->isThisDeclarationADefinition() && FoundDef) |
| 3633 | // FIXME Check for ODR error if the two definitions have |
| 3634 | // different initializers? |
| 3635 | return Importer.MapImported(D, FoundDef); |
| 3636 | |
| 3637 | // The VarDecl in the "From" context has an initializer, but in the |
| 3638 | // "To" context we already have an initializer. |
| 3639 | const VarDecl *FoundDInit = nullptr; |
| 3640 | if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit)) |
| 3641 | // FIXME Diagnose ODR error if the two initializers are different? |
| 3642 | return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit)); |
| 3643 | |
| 3644 | FoundByLookup = FoundVar; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3645 | break; |
| 3646 | } |
| 3647 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3648 | const ArrayType *FoundArray |
| 3649 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 3650 | const ArrayType *TArray |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3651 | = Importer.getToContext().getAsArrayType(D->getType()); |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3652 | if (FoundArray && TArray) { |
| 3653 | if (isa<IncompleteArrayType>(FoundArray) && |
| 3654 | isa<ConstantArrayType>(TArray)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3655 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3656 | if (auto TyOrErr = import(D->getType())) |
| 3657 | FoundVar->setType(*TyOrErr); |
| 3658 | else |
| 3659 | return TyOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3660 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3661 | FoundByLookup = FoundVar; |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3662 | break; |
| 3663 | } else if (isa<IncompleteArrayType>(TArray) && |
| 3664 | isa<ConstantArrayType>(FoundArray)) { |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3665 | FoundByLookup = FoundVar; |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3666 | break; |
Douglas Gregor | 2fbe558 | 2010-02-10 17:16:49 +0000 | [diff] [blame] | 3667 | } |
| 3668 | } |
| 3669 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3670 | Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3671 | << Name << D->getType() << FoundVar->getType(); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3672 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 3673 | << FoundVar->getType(); |
| 3674 | } |
| 3675 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3676 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3677 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3678 | } |
| 3679 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3680 | if (!ConflictingDecls.empty()) { |
| 3681 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3682 | ConflictingDecls.data(), |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3683 | ConflictingDecls.size()); |
| 3684 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3685 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3686 | } |
| 3687 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3688 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3689 | QualType ToType; |
| 3690 | TypeSourceInfo *ToTypeSourceInfo; |
| 3691 | SourceLocation ToInnerLocStart; |
| 3692 | NestedNameSpecifierLoc ToQualifierLoc; |
| 3693 | if (auto Imp = importSeq( |
| 3694 | D->getType(), D->getTypeSourceInfo(), D->getInnerLocStart(), |
| 3695 | D->getQualifierLoc())) |
| 3696 | std::tie(ToType, ToTypeSourceInfo, ToInnerLocStart, ToQualifierLoc) = *Imp; |
| 3697 | else |
| 3698 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3699 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3700 | // Create the imported variable. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3701 | VarDecl *ToVar; |
| 3702 | if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3703 | ToInnerLocStart, Loc, |
| 3704 | Name.getAsIdentifierInfo(), |
| 3705 | ToType, ToTypeSourceInfo, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3706 | D->getStorageClass())) |
| 3707 | return ToVar; |
| 3708 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3709 | ToVar->setQualifierInfo(ToQualifierLoc); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3710 | ToVar->setAccess(D->getAccess()); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3711 | ToVar->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3712 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3713 | if (FoundByLookup) { |
| 3714 | auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl()); |
| 3715 | ToVar->setPreviousDecl(Recent); |
| 3716 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3717 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3718 | if (Error Err = ImportInitializer(D, ToVar)) |
| 3719 | return std::move(Err); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3720 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3721 | if (D->isConstexpr()) |
| 3722 | ToVar->setConstexpr(true); |
| 3723 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3724 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 3725 | DC->addDeclInternal(ToVar); |
| 3726 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
| 3727 | LexicalDC->addDeclInternal(ToVar); |
| 3728 | |
| 3729 | // Import the rest of the chain. I.e. import all subsequent declarations. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3730 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3731 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3732 | if (!RedeclOrErr) |
| 3733 | return RedeclOrErr.takeError(); |
| 3734 | } |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3735 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3736 | return ToVar; |
| 3737 | } |
| 3738 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3739 | ExpectedDecl ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3740 | // Parameters are created in the translation unit's context, then moved |
| 3741 | // into the function declaration's context afterward. |
| 3742 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3743 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3744 | DeclarationName ToDeclName; |
| 3745 | SourceLocation ToLocation; |
| 3746 | QualType ToType; |
| 3747 | if (auto Imp = importSeq(D->getDeclName(), D->getLocation(), D->getType())) |
| 3748 | std::tie(ToDeclName, ToLocation, ToType) = *Imp; |
| 3749 | else |
| 3750 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3751 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3752 | // Create the imported parameter. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3753 | ImplicitParamDecl *ToParm = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3754 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
| 3755 | ToLocation, ToDeclName.getAsIdentifierInfo(), |
| 3756 | ToType, D->getParameterKind())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3757 | return ToParm; |
| 3758 | return ToParm; |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3759 | } |
| 3760 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3761 | ExpectedDecl ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3762 | // Parameters are created in the translation unit's context, then moved |
| 3763 | // into the function declaration's context afterward. |
| 3764 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3765 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3766 | DeclarationName ToDeclName; |
| 3767 | SourceLocation ToLocation, ToInnerLocStart; |
| 3768 | QualType ToType; |
| 3769 | TypeSourceInfo *ToTypeSourceInfo; |
| 3770 | if (auto Imp = importSeq( |
| 3771 | D->getDeclName(), D->getLocation(), D->getType(), D->getInnerLocStart(), |
| 3772 | D->getTypeSourceInfo())) |
| 3773 | std::tie( |
| 3774 | ToDeclName, ToLocation, ToType, ToInnerLocStart, |
| 3775 | ToTypeSourceInfo) = *Imp; |
| 3776 | else |
| 3777 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3778 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3779 | ParmVarDecl *ToParm; |
| 3780 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3781 | ToInnerLocStart, ToLocation, |
| 3782 | ToDeclName.getAsIdentifierInfo(), ToType, |
| 3783 | ToTypeSourceInfo, D->getStorageClass(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3784 | /*DefaultArg*/ nullptr)) |
| 3785 | return ToParm; |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3786 | |
| 3787 | // Set the default argument. |
John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 3788 | ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg()); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3789 | ToParm->setKNRPromoted(D->isKNRPromoted()); |
| 3790 | |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3791 | if (D->hasUninstantiatedDefaultArg()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3792 | if (auto ToDefArgOrErr = import(D->getUninstantiatedDefaultArg())) |
| 3793 | ToParm->setUninstantiatedDefaultArg(*ToDefArgOrErr); |
| 3794 | else |
| 3795 | return ToDefArgOrErr.takeError(); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3796 | } else if (D->hasUnparsedDefaultArg()) { |
| 3797 | ToParm->setUnparsedDefaultArg(); |
| 3798 | } else if (D->hasDefaultArg()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3799 | if (auto ToDefArgOrErr = import(D->getDefaultArg())) |
| 3800 | ToParm->setDefaultArg(*ToDefArgOrErr); |
| 3801 | else |
| 3802 | return ToDefArgOrErr.takeError(); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3803 | } |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3804 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3805 | if (D->isObjCMethodParameter()) { |
| 3806 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); |
| 3807 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); |
| 3808 | } else { |
| 3809 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), |
| 3810 | D->getFunctionScopeIndex()); |
| 3811 | } |
| 3812 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3813 | return ToParm; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3814 | } |
| 3815 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3816 | ExpectedDecl ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3817 | // Import the major distinguishing characteristics of a method. |
| 3818 | DeclContext *DC, *LexicalDC; |
| 3819 | DeclarationName Name; |
| 3820 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3821 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3822 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3823 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3824 | if (ToD) |
| 3825 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3826 | |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3827 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3828 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3829 | for (auto *FoundDecl : FoundDecls) { |
| 3830 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3831 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 3832 | continue; |
| 3833 | |
| 3834 | // Check return types. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3835 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 3836 | FoundMethod->getReturnType())) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3837 | Importer.ToDiag(Loc, diag::err_odr_objc_method_result_type_inconsistent) |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3838 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 3839 | << FoundMethod->getReturnType(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3840 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3841 | diag::note_odr_objc_method_here) |
| 3842 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3843 | |
| 3844 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3845 | } |
| 3846 | |
| 3847 | // Check the number of parameters. |
| 3848 | if (D->param_size() != FoundMethod->param_size()) { |
| 3849 | Importer.ToDiag(Loc, diag::err_odr_objc_method_num_params_inconsistent) |
| 3850 | << D->isInstanceMethod() << Name |
| 3851 | << D->param_size() << FoundMethod->param_size(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3852 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3853 | diag::note_odr_objc_method_here) |
| 3854 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3855 | |
| 3856 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3857 | } |
| 3858 | |
| 3859 | // Check parameter types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3860 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3861 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 3862 | P != PEnd; ++P, ++FoundP) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3863 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3864 | (*FoundP)->getType())) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3865 | Importer.FromDiag((*P)->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3866 | diag::err_odr_objc_method_param_type_inconsistent) |
| 3867 | << D->isInstanceMethod() << Name |
| 3868 | << (*P)->getType() << (*FoundP)->getType(); |
| 3869 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 3870 | << (*FoundP)->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3871 | |
| 3872 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3873 | } |
| 3874 | } |
| 3875 | |
| 3876 | // Check variadic/non-variadic. |
| 3877 | // Check the number of parameters. |
| 3878 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
| 3879 | Importer.ToDiag(Loc, diag::err_odr_objc_method_variadic_inconsistent) |
| 3880 | << D->isInstanceMethod() << Name; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3881 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3882 | diag::note_odr_objc_method_here) |
| 3883 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3884 | |
| 3885 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3886 | } |
| 3887 | |
| 3888 | // FIXME: Any other bits we need to merge? |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3889 | return Importer.MapImported(D, FoundMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3890 | } |
| 3891 | } |
| 3892 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3893 | SourceLocation ToEndLoc; |
| 3894 | QualType ToReturnType; |
| 3895 | TypeSourceInfo *ToReturnTypeSourceInfo; |
| 3896 | if (auto Imp = importSeq( |
| 3897 | D->getEndLoc(), D->getReturnType(), D->getReturnTypeSourceInfo())) |
| 3898 | std::tie(ToEndLoc, ToReturnType, ToReturnTypeSourceInfo) = *Imp; |
| 3899 | else |
| 3900 | return Imp.takeError(); |
Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 3901 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3902 | ObjCMethodDecl *ToMethod; |
| 3903 | if (GetImportedOrCreateDecl( |
| 3904 | ToMethod, D, Importer.getToContext(), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3905 | ToEndLoc, Name.getObjCSelector(), ToReturnType, |
| 3906 | ToReturnTypeSourceInfo, DC, D->isInstanceMethod(), D->isVariadic(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3907 | D->isPropertyAccessor(), D->isImplicit(), D->isDefined(), |
| 3908 | D->getImplementationControl(), D->hasRelatedResultType())) |
| 3909 | return ToMethod; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3910 | |
| 3911 | // FIXME: When we decide to merge method definitions, we'll need to |
| 3912 | // deal with implicit parameters. |
| 3913 | |
| 3914 | // Import the parameters |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3915 | SmallVector<ParmVarDecl *, 5> ToParams; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3916 | for (auto *FromP : D->parameters()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3917 | if (Expected<ParmVarDecl *> ToPOrErr = import(FromP)) |
| 3918 | ToParams.push_back(*ToPOrErr); |
| 3919 | else |
| 3920 | return ToPOrErr.takeError(); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3921 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3922 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3923 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3924 | for (auto *ToParam : ToParams) { |
| 3925 | ToParam->setOwningFunction(ToMethod); |
| 3926 | ToMethod->addDeclInternal(ToParam); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3927 | } |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3928 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3929 | SmallVector<SourceLocation, 12> FromSelLocs; |
| 3930 | D->getSelectorLocs(FromSelLocs); |
| 3931 | SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size()); |
| 3932 | if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs)) |
| 3933 | return std::move(Err); |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3934 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3935 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3936 | |
| 3937 | ToMethod->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3938 | LexicalDC->addDeclInternal(ToMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3939 | return ToMethod; |
| 3940 | } |
| 3941 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3942 | ExpectedDecl ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3943 | // Import the major distinguishing characteristics of a category. |
| 3944 | DeclContext *DC, *LexicalDC; |
| 3945 | DeclarationName Name; |
| 3946 | SourceLocation Loc; |
| 3947 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3948 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3949 | return std::move(Err); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3950 | if (ToD) |
| 3951 | return ToD; |
| 3952 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3953 | SourceLocation ToVarianceLoc, ToLocation, ToColonLoc; |
| 3954 | TypeSourceInfo *ToTypeSourceInfo; |
| 3955 | if (auto Imp = importSeq( |
| 3956 | D->getVarianceLoc(), D->getLocation(), D->getColonLoc(), |
| 3957 | D->getTypeSourceInfo())) |
| 3958 | std::tie(ToVarianceLoc, ToLocation, ToColonLoc, ToTypeSourceInfo) = *Imp; |
| 3959 | else |
| 3960 | return Imp.takeError(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3961 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3962 | ObjCTypeParamDecl *Result; |
| 3963 | if (GetImportedOrCreateDecl( |
| 3964 | Result, D, Importer.getToContext(), DC, D->getVariance(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3965 | ToVarianceLoc, D->getIndex(), |
| 3966 | ToLocation, Name.getAsIdentifierInfo(), |
| 3967 | ToColonLoc, ToTypeSourceInfo)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3968 | return Result; |
| 3969 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3970 | Result->setLexicalDeclContext(LexicalDC); |
| 3971 | return Result; |
| 3972 | } |
| 3973 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3974 | ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3975 | // Import the major distinguishing characteristics of a category. |
| 3976 | DeclContext *DC, *LexicalDC; |
| 3977 | DeclarationName Name; |
| 3978 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3979 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3980 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3981 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3982 | if (ToD) |
| 3983 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3984 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3985 | ObjCInterfaceDecl *ToInterface; |
| 3986 | if (Error Err = importInto(ToInterface, D->getClassInterface())) |
| 3987 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3988 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3989 | // Determine if we've already encountered this category. |
| 3990 | ObjCCategoryDecl *MergeWithCategory |
| 3991 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 3992 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 3993 | if (!ToCategory) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3994 | SourceLocation ToAtStartLoc, ToCategoryNameLoc; |
| 3995 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; |
| 3996 | if (auto Imp = importSeq( |
| 3997 | D->getAtStartLoc(), D->getCategoryNameLoc(), |
| 3998 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) |
| 3999 | std::tie( |
| 4000 | ToAtStartLoc, ToCategoryNameLoc, |
| 4001 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; |
| 4002 | else |
| 4003 | return Imp.takeError(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4004 | |
| 4005 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4006 | ToAtStartLoc, Loc, |
| 4007 | ToCategoryNameLoc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4008 | Name.getAsIdentifierInfo(), ToInterface, |
| 4009 | /*TypeParamList=*/nullptr, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4010 | ToIvarLBraceLoc, |
| 4011 | ToIvarRBraceLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4012 | return ToCategory; |
| 4013 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4014 | ToCategory->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4015 | LexicalDC->addDeclInternal(ToCategory); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4016 | // Import the type parameter list after MapImported, to avoid |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4017 | // loops when bringing in their DeclContext. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4018 | if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList())) |
| 4019 | ToCategory->setTypeParamList(*PListOrErr); |
| 4020 | else |
| 4021 | return PListOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4022 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4023 | // Import protocols |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4024 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4025 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4026 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 4027 | = D->protocol_loc_begin(); |
| 4028 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 4029 | FromProtoEnd = D->protocol_end(); |
| 4030 | FromProto != FromProtoEnd; |
| 4031 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4032 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4033 | Protocols.push_back(*ToProtoOrErr); |
| 4034 | else |
| 4035 | return ToProtoOrErr.takeError(); |
| 4036 | |
| 4037 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4038 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4039 | else |
| 4040 | return ToProtoLocOrErr.takeError(); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4041 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4042 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4043 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4044 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 4045 | ProtocolLocs.data(), Importer.getToContext()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4046 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4047 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4048 | Importer.MapImported(D, ToCategory); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4049 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4050 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4051 | // Import all of the members of this category. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4052 | if (Error Err = ImportDeclContext(D)) |
| 4053 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4054 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4055 | // If we have an implementation, import it as well. |
| 4056 | if (D->getImplementation()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4057 | if (Expected<ObjCCategoryImplDecl *> ToImplOrErr = |
| 4058 | import(D->getImplementation())) |
| 4059 | ToCategory->setImplementation(*ToImplOrErr); |
| 4060 | else |
| 4061 | return ToImplOrErr.takeError(); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4062 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4063 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4064 | return ToCategory; |
| 4065 | } |
| 4066 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4067 | Error ASTNodeImporter::ImportDefinition( |
| 4068 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4069 | if (To->getDefinition()) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4070 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4071 | if (Error Err = ImportDeclContext(From)) |
| 4072 | return Err; |
| 4073 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4074 | } |
| 4075 | |
| 4076 | // Start the protocol definition |
| 4077 | To->startDefinition(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4078 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4079 | // Import protocols |
| 4080 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4081 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4082 | ObjCProtocolDecl::protocol_loc_iterator FromProtoLoc = |
| 4083 | From->protocol_loc_begin(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4084 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4085 | FromProtoEnd = From->protocol_end(); |
| 4086 | FromProto != FromProtoEnd; |
| 4087 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4088 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4089 | Protocols.push_back(*ToProtoOrErr); |
| 4090 | else |
| 4091 | return ToProtoOrErr.takeError(); |
| 4092 | |
| 4093 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4094 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4095 | else |
| 4096 | return ToProtoLocOrErr.takeError(); |
| 4097 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4098 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4099 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4100 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4101 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4102 | ProtocolLocs.data(), Importer.getToContext()); |
| 4103 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4104 | if (shouldForceImportDeclContext(Kind)) { |
| 4105 | // Import all of the members of this protocol. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4106 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4107 | return Err; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4108 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4109 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4110 | } |
| 4111 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4112 | ExpectedDecl ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4113 | // 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] | 4114 | // from, but this particular declaration is not that definition, import the |
| 4115 | // definition and map to that. |
| 4116 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 4117 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4118 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4119 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4120 | else |
| 4121 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4122 | } |
| 4123 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4124 | // Import the major distinguishing characteristics of a protocol. |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4125 | DeclContext *DC, *LexicalDC; |
| 4126 | DeclarationName Name; |
| 4127 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4128 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4129 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4130 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4131 | if (ToD) |
| 4132 | return ToD; |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4133 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4134 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4135 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4136 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4137 | for (auto *FoundDecl : FoundDecls) { |
| 4138 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4139 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4140 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4141 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4142 | break; |
| 4143 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4144 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4145 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4146 | if (!ToProto) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4147 | auto ToAtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4148 | if (!ToAtBeginLocOrErr) |
| 4149 | return ToAtBeginLocOrErr.takeError(); |
| 4150 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4151 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, |
| 4152 | Name.getAsIdentifierInfo(), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4153 | *ToAtBeginLocOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4154 | /*PrevDecl=*/nullptr)) |
| 4155 | return ToProto; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4156 | ToProto->setLexicalDeclContext(LexicalDC); |
| 4157 | LexicalDC->addDeclInternal(ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4158 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4159 | |
| 4160 | Importer.MapImported(D, ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4161 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4162 | if (D->isThisDeclarationADefinition()) |
| 4163 | if (Error Err = ImportDefinition(D, ToProto)) |
| 4164 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4165 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4166 | return ToProto; |
| 4167 | } |
| 4168 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4169 | ExpectedDecl ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 4170 | DeclContext *DC, *LexicalDC; |
| 4171 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4172 | return std::move(Err); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4173 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4174 | ExpectedSLoc ExternLocOrErr = import(D->getExternLoc()); |
| 4175 | if (!ExternLocOrErr) |
| 4176 | return ExternLocOrErr.takeError(); |
| 4177 | |
| 4178 | ExpectedSLoc LangLocOrErr = import(D->getLocation()); |
| 4179 | if (!LangLocOrErr) |
| 4180 | return LangLocOrErr.takeError(); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4181 | |
| 4182 | bool HasBraces = D->hasBraces(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4183 | |
| 4184 | LinkageSpecDecl *ToLinkageSpec; |
| 4185 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4186 | *ExternLocOrErr, *LangLocOrErr, |
| 4187 | D->getLanguage(), HasBraces)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4188 | return ToLinkageSpec; |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4189 | |
| 4190 | if (HasBraces) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4191 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); |
| 4192 | if (!RBraceLocOrErr) |
| 4193 | return RBraceLocOrErr.takeError(); |
| 4194 | ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4195 | } |
| 4196 | |
| 4197 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 4198 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 4199 | |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4200 | return ToLinkageSpec; |
| 4201 | } |
| 4202 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4203 | ExpectedDecl ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4204 | DeclContext *DC, *LexicalDC; |
| 4205 | DeclarationName Name; |
| 4206 | SourceLocation Loc; |
| 4207 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4208 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4209 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4210 | if (ToD) |
| 4211 | return ToD; |
| 4212 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4213 | SourceLocation ToLoc, ToUsingLoc; |
| 4214 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4215 | if (auto Imp = importSeq( |
| 4216 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc())) |
| 4217 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc) = *Imp; |
| 4218 | else |
| 4219 | return Imp.takeError(); |
| 4220 | |
| 4221 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4222 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4223 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4224 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4225 | UsingDecl *ToUsing; |
| 4226 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4227 | ToUsingLoc, ToQualifierLoc, NameInfo, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4228 | D->hasTypename())) |
| 4229 | return ToUsing; |
| 4230 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4231 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4232 | LexicalDC->addDeclInternal(ToUsing); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4233 | |
| 4234 | if (NamedDecl *FromPattern = |
| 4235 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4236 | if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern)) |
| 4237 | Importer.getToContext().setInstantiatedFromUsingDecl( |
| 4238 | ToUsing, *ToPatternOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4239 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4240 | return ToPatternOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4241 | } |
| 4242 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4243 | for (UsingShadowDecl *FromShadow : D->shadows()) { |
| 4244 | if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow)) |
| 4245 | ToUsing->addShadowDecl(*ToShadowOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4246 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4247 | // FIXME: We return error here but the definition is already created |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4248 | // and available with lookups. How to fix this?.. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4249 | return ToShadowOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4250 | } |
| 4251 | return ToUsing; |
| 4252 | } |
| 4253 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4254 | ExpectedDecl ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4255 | DeclContext *DC, *LexicalDC; |
| 4256 | DeclarationName Name; |
| 4257 | SourceLocation Loc; |
| 4258 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4259 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4260 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4261 | if (ToD) |
| 4262 | return ToD; |
| 4263 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4264 | Expected<UsingDecl *> ToUsingOrErr = import(D->getUsingDecl()); |
| 4265 | if (!ToUsingOrErr) |
| 4266 | return ToUsingOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4267 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4268 | Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl()); |
| 4269 | if (!ToTargetOrErr) |
| 4270 | return ToTargetOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4271 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4272 | UsingShadowDecl *ToShadow; |
| 4273 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4274 | *ToUsingOrErr, *ToTargetOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4275 | return ToShadow; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4276 | |
| 4277 | ToShadow->setLexicalDeclContext(LexicalDC); |
| 4278 | ToShadow->setAccess(D->getAccess()); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4279 | |
| 4280 | if (UsingShadowDecl *FromPattern = |
| 4281 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4282 | if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern)) |
| 4283 | Importer.getToContext().setInstantiatedFromUsingShadowDecl( |
| 4284 | ToShadow, *ToPatternOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4285 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4286 | // FIXME: We return error here but the definition is already created |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4287 | // and available with lookups. How to fix this?.. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4288 | return ToPatternOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4289 | } |
| 4290 | |
| 4291 | LexicalDC->addDeclInternal(ToShadow); |
| 4292 | |
| 4293 | return ToShadow; |
| 4294 | } |
| 4295 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4296 | ExpectedDecl ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4297 | DeclContext *DC, *LexicalDC; |
| 4298 | DeclarationName Name; |
| 4299 | SourceLocation Loc; |
| 4300 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4301 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4302 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4303 | if (ToD) |
| 4304 | return ToD; |
| 4305 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4306 | auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor()); |
| 4307 | if (!ToComAncestorOrErr) |
| 4308 | return ToComAncestorOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4309 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4310 | NamespaceDecl *ToNominatedNamespace; |
| 4311 | SourceLocation ToUsingLoc, ToNamespaceKeyLocation, ToIdentLocation; |
| 4312 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4313 | if (auto Imp = importSeq( |
| 4314 | D->getNominatedNamespace(), D->getUsingLoc(), |
| 4315 | D->getNamespaceKeyLocation(), D->getQualifierLoc(), |
| 4316 | D->getIdentLocation())) |
| 4317 | std::tie( |
| 4318 | ToNominatedNamespace, ToUsingLoc, ToNamespaceKeyLocation, |
| 4319 | ToQualifierLoc, ToIdentLocation) = *Imp; |
| 4320 | else |
| 4321 | return Imp.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4322 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4323 | UsingDirectiveDecl *ToUsingDir; |
| 4324 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4325 | ToUsingLoc, |
| 4326 | ToNamespaceKeyLocation, |
| 4327 | ToQualifierLoc, |
| 4328 | ToIdentLocation, |
| 4329 | ToNominatedNamespace, *ToComAncestorOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4330 | return ToUsingDir; |
| 4331 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4332 | ToUsingDir->setLexicalDeclContext(LexicalDC); |
| 4333 | LexicalDC->addDeclInternal(ToUsingDir); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4334 | |
| 4335 | return ToUsingDir; |
| 4336 | } |
| 4337 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4338 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4339 | UnresolvedUsingValueDecl *D) { |
| 4340 | DeclContext *DC, *LexicalDC; |
| 4341 | DeclarationName Name; |
| 4342 | SourceLocation Loc; |
| 4343 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4344 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4345 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4346 | if (ToD) |
| 4347 | return ToD; |
| 4348 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4349 | SourceLocation ToLoc, ToUsingLoc, ToEllipsisLoc; |
| 4350 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4351 | if (auto Imp = importSeq( |
| 4352 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc(), |
| 4353 | D->getEllipsisLoc())) |
| 4354 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; |
| 4355 | else |
| 4356 | return Imp.takeError(); |
| 4357 | |
| 4358 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4359 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4360 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4361 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4362 | UnresolvedUsingValueDecl *ToUsingValue; |
| 4363 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4364 | ToUsingLoc, ToQualifierLoc, NameInfo, |
| 4365 | ToEllipsisLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4366 | return ToUsingValue; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4367 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4368 | ToUsingValue->setAccess(D->getAccess()); |
| 4369 | ToUsingValue->setLexicalDeclContext(LexicalDC); |
| 4370 | LexicalDC->addDeclInternal(ToUsingValue); |
| 4371 | |
| 4372 | return ToUsingValue; |
| 4373 | } |
| 4374 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4375 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4376 | UnresolvedUsingTypenameDecl *D) { |
| 4377 | DeclContext *DC, *LexicalDC; |
| 4378 | DeclarationName Name; |
| 4379 | SourceLocation Loc; |
| 4380 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4381 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4382 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4383 | if (ToD) |
| 4384 | return ToD; |
| 4385 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4386 | SourceLocation ToUsingLoc, ToTypenameLoc, ToEllipsisLoc; |
| 4387 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4388 | if (auto Imp = importSeq( |
| 4389 | D->getUsingLoc(), D->getTypenameLoc(), D->getQualifierLoc(), |
| 4390 | D->getEllipsisLoc())) |
| 4391 | std::tie(ToUsingLoc, ToTypenameLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; |
| 4392 | else |
| 4393 | return Imp.takeError(); |
| 4394 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4395 | UnresolvedUsingTypenameDecl *ToUsing; |
| 4396 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4397 | ToUsingLoc, ToTypenameLoc, |
| 4398 | ToQualifierLoc, Loc, Name, ToEllipsisLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4399 | return ToUsing; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4400 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4401 | ToUsing->setAccess(D->getAccess()); |
| 4402 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4403 | LexicalDC->addDeclInternal(ToUsing); |
| 4404 | |
| 4405 | return ToUsing; |
| 4406 | } |
| 4407 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4408 | |
| 4409 | Error ASTNodeImporter::ImportDefinition( |
| 4410 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4411 | if (To->getDefinition()) { |
| 4412 | // Check consistency of superclass. |
| 4413 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 4414 | if (FromSuper) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4415 | if (auto FromSuperOrErr = import(FromSuper)) |
| 4416 | FromSuper = *FromSuperOrErr; |
| 4417 | else |
| 4418 | return FromSuperOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4419 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4420 | |
| 4421 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4422 | if ((bool)FromSuper != (bool)ToSuper || |
| 4423 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4424 | Importer.ToDiag(To->getLocation(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4425 | diag::err_odr_objc_superclass_inconsistent) |
| 4426 | << To->getDeclName(); |
| 4427 | if (ToSuper) |
| 4428 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 4429 | << To->getSuperClass()->getDeclName(); |
| 4430 | else |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4431 | Importer.ToDiag(To->getLocation(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4432 | diag::note_odr_objc_missing_superclass); |
| 4433 | if (From->getSuperClass()) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4434 | Importer.FromDiag(From->getSuperClassLoc(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4435 | diag::note_odr_objc_superclass) |
| 4436 | << From->getSuperClass()->getDeclName(); |
| 4437 | else |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4438 | Importer.FromDiag(From->getLocation(), |
| 4439 | diag::note_odr_objc_missing_superclass); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4440 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4441 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4442 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4443 | if (Error Err = ImportDeclContext(From)) |
| 4444 | return Err; |
| 4445 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4446 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4447 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4448 | // Start the definition. |
| 4449 | To->startDefinition(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4450 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4451 | // If this class has a superclass, import it. |
| 4452 | if (From->getSuperClass()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4453 | if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo())) |
| 4454 | To->setSuperClass(*SuperTInfoOrErr); |
| 4455 | else |
| 4456 | return SuperTInfoOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4457 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4458 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4459 | // Import protocols |
| 4460 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4461 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4462 | ObjCInterfaceDecl::protocol_loc_iterator FromProtoLoc = |
| 4463 | From->protocol_loc_begin(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4464 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4465 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4466 | FromProtoEnd = From->protocol_end(); |
| 4467 | FromProto != FromProtoEnd; |
| 4468 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4469 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4470 | Protocols.push_back(*ToProtoOrErr); |
| 4471 | else |
| 4472 | return ToProtoOrErr.takeError(); |
| 4473 | |
| 4474 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4475 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4476 | else |
| 4477 | return ToProtoLocOrErr.takeError(); |
| 4478 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4479 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4480 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4481 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4482 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4483 | ProtocolLocs.data(), Importer.getToContext()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4484 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4485 | // Import categories. When the categories themselves are imported, they'll |
| 4486 | // hook themselves into this interface. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4487 | for (auto *Cat : From->known_categories()) { |
| 4488 | auto ToCatOrErr = import(Cat); |
| 4489 | if (!ToCatOrErr) |
| 4490 | return ToCatOrErr.takeError(); |
| 4491 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4492 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4493 | // If we have an @implementation, import it as well. |
| 4494 | if (From->getImplementation()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4495 | if (Expected<ObjCImplementationDecl *> ToImplOrErr = |
| 4496 | import(From->getImplementation())) |
| 4497 | To->setImplementation(*ToImplOrErr); |
| 4498 | else |
| 4499 | return ToImplOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4500 | } |
| 4501 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4502 | if (shouldForceImportDeclContext(Kind)) { |
| 4503 | // Import all of the members of this class. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4504 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4505 | return Err; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4506 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4507 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4508 | } |
| 4509 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4510 | Expected<ObjCTypeParamList *> |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4511 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 4512 | if (!list) |
| 4513 | return nullptr; |
| 4514 | |
| 4515 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4516 | for (auto *fromTypeParam : *list) { |
| 4517 | if (auto toTypeParamOrErr = import(fromTypeParam)) |
| 4518 | toTypeParams.push_back(*toTypeParamOrErr); |
| 4519 | else |
| 4520 | return toTypeParamOrErr.takeError(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4521 | } |
| 4522 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4523 | auto LAngleLocOrErr = import(list->getLAngleLoc()); |
| 4524 | if (!LAngleLocOrErr) |
| 4525 | return LAngleLocOrErr.takeError(); |
| 4526 | |
| 4527 | auto RAngleLocOrErr = import(list->getRAngleLoc()); |
| 4528 | if (!RAngleLocOrErr) |
| 4529 | return RAngleLocOrErr.takeError(); |
| 4530 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4531 | return ObjCTypeParamList::create(Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4532 | *LAngleLocOrErr, |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4533 | toTypeParams, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4534 | *RAngleLocOrErr); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4535 | } |
| 4536 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4537 | ExpectedDecl ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4538 | // If this class has a definition in the translation unit we're coming from, |
| 4539 | // but this particular declaration is not that definition, import the |
| 4540 | // definition and map to that. |
| 4541 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 4542 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4543 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4544 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4545 | else |
| 4546 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4547 | } |
| 4548 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4549 | // Import the major distinguishing characteristics of an @interface. |
| 4550 | DeclContext *DC, *LexicalDC; |
| 4551 | DeclarationName Name; |
| 4552 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4553 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4554 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4555 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4556 | if (ToD) |
| 4557 | return ToD; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4558 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4559 | // Look for an existing interface with the same name. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4560 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4561 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4562 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4563 | for (auto *FoundDecl : FoundDecls) { |
| 4564 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4565 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4566 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4567 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4568 | break; |
| 4569 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4570 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4571 | // Create an interface declaration, if one does not already exist. |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4572 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4573 | if (!ToIface) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4574 | ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4575 | if (!AtBeginLocOrErr) |
| 4576 | return AtBeginLocOrErr.takeError(); |
| 4577 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4578 | if (GetImportedOrCreateDecl( |
| 4579 | ToIface, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4580 | *AtBeginLocOrErr, Name.getAsIdentifierInfo(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4581 | /*TypeParamList=*/nullptr, |
| 4582 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) |
| 4583 | return ToIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4584 | ToIface->setLexicalDeclContext(LexicalDC); |
| 4585 | LexicalDC->addDeclInternal(ToIface); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4586 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4587 | Importer.MapImported(D, ToIface); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4588 | // Import the type parameter list after MapImported, to avoid |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4589 | // loops when bringing in their DeclContext. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4590 | if (auto ToPListOrErr = |
| 4591 | ImportObjCTypeParamList(D->getTypeParamListAsWritten())) |
| 4592 | ToIface->setTypeParamList(*ToPListOrErr); |
| 4593 | else |
| 4594 | return ToPListOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4595 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4596 | if (D->isThisDeclarationADefinition()) |
| 4597 | if (Error Err = ImportDefinition(D, ToIface)) |
| 4598 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4599 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4600 | return ToIface; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4601 | } |
| 4602 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4603 | ExpectedDecl |
| 4604 | ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 4605 | ObjCCategoryDecl *Category; |
| 4606 | if (Error Err = importInto(Category, D->getCategoryDecl())) |
| 4607 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4608 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4609 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 4610 | if (!ToImpl) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4611 | DeclContext *DC, *LexicalDC; |
| 4612 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4613 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4614 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4615 | SourceLocation ToLocation, ToAtStartLoc, ToCategoryNameLoc; |
| 4616 | if (auto Imp = importSeq( |
| 4617 | D->getLocation(), D->getAtStartLoc(), D->getCategoryNameLoc())) |
| 4618 | std::tie(ToLocation, ToAtStartLoc, ToCategoryNameLoc) = *Imp; |
| 4619 | else |
| 4620 | return Imp.takeError(); |
| 4621 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4622 | if (GetImportedOrCreateDecl( |
| 4623 | ToImpl, D, Importer.getToContext(), DC, |
| 4624 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4625 | ToLocation, ToAtStartLoc, ToCategoryNameLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4626 | return ToImpl; |
| 4627 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4628 | ToImpl->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4629 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4630 | Category->setImplementation(ToImpl); |
| 4631 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4632 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4633 | Importer.MapImported(D, ToImpl); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4634 | if (Error Err = ImportDeclContext(D)) |
| 4635 | return std::move(Err); |
| 4636 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4637 | return ToImpl; |
| 4638 | } |
| 4639 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4640 | ExpectedDecl |
| 4641 | ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4642 | // Find the corresponding interface. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4643 | ObjCInterfaceDecl *Iface; |
| 4644 | if (Error Err = importInto(Iface, D->getClassInterface())) |
| 4645 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4646 | |
| 4647 | // Import the superclass, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4648 | ObjCInterfaceDecl *Super; |
| 4649 | if (Error Err = importInto(Super, D->getSuperClass())) |
| 4650 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4651 | |
| 4652 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 4653 | if (!Impl) { |
| 4654 | // We haven't imported an implementation yet. Create a new @implementation |
| 4655 | // now. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4656 | DeclContext *DC, *LexicalDC; |
| 4657 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4658 | return std::move(Err); |
| 4659 | |
| 4660 | SourceLocation ToLocation, ToAtStartLoc, ToSuperClassLoc; |
| 4661 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; |
| 4662 | if (auto Imp = importSeq( |
| 4663 | D->getLocation(), D->getAtStartLoc(), D->getSuperClassLoc(), |
| 4664 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) |
| 4665 | std::tie( |
| 4666 | ToLocation, ToAtStartLoc, ToSuperClassLoc, |
| 4667 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; |
| 4668 | else |
| 4669 | return Imp.takeError(); |
| 4670 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4671 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4672 | DC, Iface, Super, |
| 4673 | ToLocation, |
| 4674 | ToAtStartLoc, |
| 4675 | ToSuperClassLoc, |
| 4676 | ToIvarLBraceLoc, |
| 4677 | ToIvarRBraceLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4678 | return Impl; |
| 4679 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4680 | Impl->setLexicalDeclContext(LexicalDC); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4681 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4682 | // Associate the implementation with the class it implements. |
| 4683 | Iface->setImplementation(Impl); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4684 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4685 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4686 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4687 | |
| 4688 | // Verify that the existing @implementation has the same superclass. |
| 4689 | if ((Super && !Impl->getSuperClass()) || |
| 4690 | (!Super && Impl->getSuperClass()) || |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4691 | (Super && Impl->getSuperClass() && |
| 4692 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 4693 | Impl->getSuperClass()))) { |
| 4694 | Importer.ToDiag(Impl->getLocation(), |
| 4695 | diag::err_odr_objc_superclass_inconsistent) |
| 4696 | << Iface->getDeclName(); |
| 4697 | // FIXME: It would be nice to have the location of the superclass |
| 4698 | // below. |
| 4699 | if (Impl->getSuperClass()) |
| 4700 | Importer.ToDiag(Impl->getLocation(), |
| 4701 | diag::note_odr_objc_superclass) |
| 4702 | << Impl->getSuperClass()->getDeclName(); |
| 4703 | else |
| 4704 | Importer.ToDiag(Impl->getLocation(), |
| 4705 | diag::note_odr_objc_missing_superclass); |
| 4706 | if (D->getSuperClass()) |
| 4707 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4708 | diag::note_odr_objc_superclass) |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4709 | << D->getSuperClass()->getDeclName(); |
| 4710 | else |
| 4711 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4712 | diag::note_odr_objc_missing_superclass); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4713 | |
| 4714 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4715 | } |
| 4716 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4717 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4718 | // Import all of the members of this @implementation. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4719 | if (Error Err = ImportDeclContext(D)) |
| 4720 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4721 | |
| 4722 | return Impl; |
| 4723 | } |
| 4724 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4725 | ExpectedDecl ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4726 | // Import the major distinguishing characteristics of an @property. |
| 4727 | DeclContext *DC, *LexicalDC; |
| 4728 | DeclarationName Name; |
| 4729 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4730 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4731 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4732 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4733 | if (ToD) |
| 4734 | return ToD; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4735 | |
| 4736 | // Check whether we have already imported this property. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4737 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4738 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4739 | for (auto *FoundDecl : FoundDecls) { |
| 4740 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4741 | // Check property types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4742 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4743 | FoundProp->getType())) { |
| 4744 | Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent) |
| 4745 | << Name << D->getType() << FoundProp->getType(); |
| 4746 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 4747 | << FoundProp->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4748 | |
| 4749 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4750 | } |
| 4751 | |
| 4752 | // FIXME: Check property attributes, getters, setters, etc.? |
| 4753 | |
| 4754 | // Consider these properties to be equivalent. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4755 | Importer.MapImported(D, FoundProp); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4756 | return FoundProp; |
| 4757 | } |
| 4758 | } |
| 4759 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4760 | QualType ToType; |
| 4761 | TypeSourceInfo *ToTypeSourceInfo; |
| 4762 | SourceLocation ToAtLoc, ToLParenLoc; |
| 4763 | if (auto Imp = importSeq( |
| 4764 | D->getType(), D->getTypeSourceInfo(), D->getAtLoc(), D->getLParenLoc())) |
| 4765 | std::tie(ToType, ToTypeSourceInfo, ToAtLoc, ToLParenLoc) = *Imp; |
| 4766 | else |
| 4767 | return Imp.takeError(); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4768 | |
| 4769 | // Create the new property. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4770 | ObjCPropertyDecl *ToProperty; |
| 4771 | if (GetImportedOrCreateDecl( |
| 4772 | ToProperty, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4773 | Name.getAsIdentifierInfo(), ToAtLoc, |
| 4774 | ToLParenLoc, ToType, |
| 4775 | ToTypeSourceInfo, D->getPropertyImplementation())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4776 | return ToProperty; |
| 4777 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4778 | Selector ToGetterName, ToSetterName; |
| 4779 | SourceLocation ToGetterNameLoc, ToSetterNameLoc; |
| 4780 | ObjCMethodDecl *ToGetterMethodDecl, *ToSetterMethodDecl; |
| 4781 | ObjCIvarDecl *ToPropertyIvarDecl; |
| 4782 | if (auto Imp = importSeq( |
| 4783 | D->getGetterName(), D->getSetterName(), |
| 4784 | D->getGetterNameLoc(), D->getSetterNameLoc(), |
| 4785 | D->getGetterMethodDecl(), D->getSetterMethodDecl(), |
| 4786 | D->getPropertyIvarDecl())) |
| 4787 | std::tie( |
| 4788 | ToGetterName, ToSetterName, |
| 4789 | ToGetterNameLoc, ToSetterNameLoc, |
| 4790 | ToGetterMethodDecl, ToSetterMethodDecl, |
| 4791 | ToPropertyIvarDecl) = *Imp; |
| 4792 | else |
| 4793 | return Imp.takeError(); |
| 4794 | |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4795 | ToProperty->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4796 | LexicalDC->addDeclInternal(ToProperty); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4797 | |
| 4798 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 4799 | ToProperty->setPropertyAttributesAsWritten( |
| 4800 | D->getPropertyAttributesAsWritten()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4801 | ToProperty->setGetterName(ToGetterName, ToGetterNameLoc); |
| 4802 | ToProperty->setSetterName(ToSetterName, ToSetterNameLoc); |
| 4803 | ToProperty->setGetterMethodDecl(ToGetterMethodDecl); |
| 4804 | ToProperty->setSetterMethodDecl(ToSetterMethodDecl); |
| 4805 | ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4806 | return ToProperty; |
| 4807 | } |
| 4808 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4809 | ExpectedDecl |
| 4810 | ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 4811 | ObjCPropertyDecl *Property; |
| 4812 | if (Error Err = importInto(Property, D->getPropertyDecl())) |
| 4813 | return std::move(Err); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4814 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4815 | DeclContext *DC, *LexicalDC; |
| 4816 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4817 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4818 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4819 | auto *InImpl = cast<ObjCImplDecl>(LexicalDC); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4820 | |
| 4821 | // Import the ivar (for an @synthesize). |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4822 | ObjCIvarDecl *Ivar = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4823 | if (Error Err = importInto(Ivar, D->getPropertyIvarDecl())) |
| 4824 | return std::move(Err); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4825 | |
| 4826 | ObjCPropertyImplDecl *ToImpl |
Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 4827 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 4828 | Property->getQueryKind()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4829 | if (!ToImpl) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4830 | SourceLocation ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc; |
| 4831 | if (auto Imp = importSeq( |
| 4832 | D->getBeginLoc(), D->getLocation(), D->getPropertyIvarDeclLoc())) |
| 4833 | std::tie(ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc) = *Imp; |
| 4834 | else |
| 4835 | return Imp.takeError(); |
| 4836 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4837 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4838 | ToBeginLoc, |
| 4839 | ToLocation, Property, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4840 | D->getPropertyImplementation(), Ivar, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4841 | ToPropertyIvarDeclLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4842 | return ToImpl; |
| 4843 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4844 | ToImpl->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4845 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4846 | } else { |
| 4847 | // Check that we have the same kind of property implementation (@synthesize |
| 4848 | // vs. @dynamic). |
| 4849 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4850 | Importer.ToDiag(ToImpl->getLocation(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4851 | diag::err_odr_objc_property_impl_kind_inconsistent) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4852 | << Property->getDeclName() |
| 4853 | << (ToImpl->getPropertyImplementation() |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4854 | == ObjCPropertyImplDecl::Dynamic); |
| 4855 | Importer.FromDiag(D->getLocation(), |
| 4856 | diag::note_odr_objc_property_impl_kind) |
| 4857 | << D->getPropertyDecl()->getDeclName() |
| 4858 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4859 | |
| 4860 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4861 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4862 | |
| 4863 | // For @synthesize, check that we have the same |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4864 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 4865 | Ivar != ToImpl->getPropertyIvarDecl()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4866 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4867 | diag::err_odr_objc_synthesize_ivar_inconsistent) |
| 4868 | << Property->getDeclName() |
| 4869 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 4870 | << Ivar->getDeclName(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4871 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4872 | diag::note_odr_objc_synthesize_ivar_here) |
| 4873 | << D->getPropertyIvarDecl()->getDeclName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4874 | |
| 4875 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4876 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4877 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4878 | // Merge the existing implementation with the new implementation. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4879 | Importer.MapImported(D, ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4880 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4881 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4882 | return ToImpl; |
| 4883 | } |
| 4884 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4885 | ExpectedDecl |
| 4886 | ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4887 | // For template arguments, we adopt the translation unit as our declaration |
| 4888 | // context. This context will be fixed when the actual template declaration |
| 4889 | // is created. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4890 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4891 | // FIXME: Import default argument. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4892 | |
| 4893 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 4894 | if (!BeginLocOrErr) |
| 4895 | return BeginLocOrErr.takeError(); |
| 4896 | |
| 4897 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 4898 | if (!LocationOrErr) |
| 4899 | return LocationOrErr.takeError(); |
| 4900 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4901 | TemplateTypeParmDecl *ToD = nullptr; |
| 4902 | (void)GetImportedOrCreateDecl( |
| 4903 | ToD, D, Importer.getToContext(), |
| 4904 | Importer.getToContext().getTranslationUnitDecl(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4905 | *BeginLocOrErr, *LocationOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4906 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), |
| 4907 | D->wasDeclaredWithTypename(), D->isParameterPack()); |
| 4908 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4909 | } |
| 4910 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4911 | ExpectedDecl |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4912 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4913 | DeclarationName ToDeclName; |
| 4914 | SourceLocation ToLocation, ToInnerLocStart; |
| 4915 | QualType ToType; |
| 4916 | TypeSourceInfo *ToTypeSourceInfo; |
| 4917 | if (auto Imp = importSeq( |
| 4918 | D->getDeclName(), D->getLocation(), D->getType(), D->getTypeSourceInfo(), |
| 4919 | D->getInnerLocStart())) |
| 4920 | std::tie( |
| 4921 | ToDeclName, ToLocation, ToType, ToTypeSourceInfo, |
| 4922 | ToInnerLocStart) = *Imp; |
| 4923 | else |
| 4924 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4925 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4926 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4927 | |
| 4928 | NonTypeTemplateParmDecl *ToD = nullptr; |
| 4929 | (void)GetImportedOrCreateDecl( |
| 4930 | ToD, D, Importer.getToContext(), |
| 4931 | Importer.getToContext().getTranslationUnitDecl(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4932 | ToInnerLocStart, ToLocation, D->getDepth(), |
| 4933 | D->getPosition(), ToDeclName.getAsIdentifierInfo(), ToType, |
| 4934 | D->isParameterPack(), ToTypeSourceInfo); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4935 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4936 | } |
| 4937 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4938 | ExpectedDecl |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4939 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 4940 | // Import the name of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4941 | auto NameOrErr = import(D->getDeclName()); |
| 4942 | if (!NameOrErr) |
| 4943 | return NameOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4944 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4945 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4946 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 4947 | if (!LocationOrErr) |
| 4948 | return LocationOrErr.takeError(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4949 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4950 | // Import template parameters. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4951 | auto TemplateParamsOrErr = ImportTemplateParameterList( |
| 4952 | D->getTemplateParameters()); |
| 4953 | if (!TemplateParamsOrErr) |
| 4954 | return TemplateParamsOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4955 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4956 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4957 | |
| 4958 | TemplateTemplateParmDecl *ToD = nullptr; |
| 4959 | (void)GetImportedOrCreateDecl( |
| 4960 | ToD, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4961 | Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr, |
| 4962 | D->getDepth(), D->getPosition(), D->isParameterPack(), |
| 4963 | (*NameOrErr).getAsIdentifierInfo(), |
| 4964 | *TemplateParamsOrErr); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4965 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4966 | } |
| 4967 | |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4968 | // Returns the definition for a (forward) declaration of a ClassTemplateDecl, if |
| 4969 | // it has any definition in the redecl chain. |
| 4970 | static ClassTemplateDecl *getDefinition(ClassTemplateDecl *D) { |
| 4971 | CXXRecordDecl *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); |
| 4972 | if (!ToTemplatedDef) |
| 4973 | return nullptr; |
| 4974 | ClassTemplateDecl *TemplateWithDef = |
| 4975 | ToTemplatedDef->getDescribedClassTemplate(); |
| 4976 | return TemplateWithDef; |
| 4977 | } |
| 4978 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4979 | ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4980 | bool IsFriend = D->getFriendObjectKind() != Decl::FOK_None; |
| 4981 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4982 | // If this record has a definition in the translation unit we're coming from, |
| 4983 | // but this particular declaration is not that definition, import the |
| 4984 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4985 | auto *Definition = |
| 4986 | cast_or_null<CXXRecordDecl>(D->getTemplatedDecl()->getDefinition()); |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4987 | if (Definition && Definition != D->getTemplatedDecl() && !IsFriend) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4988 | if (ExpectedDecl ImportedDefOrErr = import( |
| 4989 | Definition->getDescribedClassTemplate())) |
| 4990 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4991 | else |
| 4992 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4993 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4994 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4995 | // Import the major distinguishing characteristics of this class template. |
| 4996 | DeclContext *DC, *LexicalDC; |
| 4997 | DeclarationName Name; |
| 4998 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4999 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5000 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5001 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5002 | if (ToD) |
| 5003 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5004 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5005 | // We may already have a template of the same name; try to find and match it. |
| 5006 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5007 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 5008 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 5009 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5010 | for (auto *FoundDecl : FoundDecls) { |
| 5011 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5012 | continue; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5013 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5014 | Decl *Found = FoundDecl; |
| 5015 | if (auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found)) { |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5016 | |
| 5017 | // The class to be imported is a definition. |
| 5018 | if (D->isThisDeclarationADefinition()) { |
| 5019 | // Lookup will find the fwd decl only if that is more recent than the |
| 5020 | // definition. So, try to get the definition if that is available in |
| 5021 | // the redecl chain. |
| 5022 | ClassTemplateDecl *TemplateWithDef = getDefinition(FoundTemplate); |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5023 | if (TemplateWithDef) |
| 5024 | FoundTemplate = TemplateWithDef; |
| 5025 | else |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5026 | continue; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5027 | } |
| 5028 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5029 | if (IsStructuralMatch(D, FoundTemplate)) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5030 | if (!IsFriend) { |
| 5031 | Importer.MapImported(D->getTemplatedDecl(), |
| 5032 | FoundTemplate->getTemplatedDecl()); |
| 5033 | return Importer.MapImported(D, FoundTemplate); |
| 5034 | } |
Aleksei Sidorin | 761c224 | 2018-05-15 11:09:07 +0000 | [diff] [blame] | 5035 | |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5036 | continue; |
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 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5039 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5040 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5041 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5042 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5043 | if (!ConflictingDecls.empty()) { |
| 5044 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5045 | ConflictingDecls.data(), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5046 | ConflictingDecls.size()); |
| 5047 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5048 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5049 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5050 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5051 | } |
| 5052 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5053 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); |
| 5054 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5055 | // Create the declaration that is being templated. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5056 | CXXRecordDecl *ToTemplated; |
| 5057 | if (Error Err = importInto(ToTemplated, FromTemplated)) |
| 5058 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5059 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5060 | // Create the class template declaration itself. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5061 | auto TemplateParamsOrErr = ImportTemplateParameterList( |
| 5062 | D->getTemplateParameters()); |
| 5063 | if (!TemplateParamsOrErr) |
| 5064 | return TemplateParamsOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5065 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5066 | ClassTemplateDecl *D2; |
| 5067 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5068 | *TemplateParamsOrErr, ToTemplated)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5069 | return D2; |
| 5070 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5071 | ToTemplated->setDescribedClassTemplate(D2); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5072 | |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5073 | if (ToTemplated->getPreviousDecl()) { |
| 5074 | assert( |
| 5075 | ToTemplated->getPreviousDecl()->getDescribedClassTemplate() && |
| 5076 | "Missing described template"); |
| 5077 | D2->setPreviousDecl( |
| 5078 | ToTemplated->getPreviousDecl()->getDescribedClassTemplate()); |
| 5079 | } |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5080 | D2->setAccess(D->getAccess()); |
| 5081 | D2->setLexicalDeclContext(LexicalDC); |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5082 | if (!IsFriend) |
| 5083 | LexicalDC->addDeclInternal(D2); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5084 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5085 | if (FromTemplated->isCompleteDefinition() && |
| 5086 | !ToTemplated->isCompleteDefinition()) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5087 | // FIXME: Import definition! |
| 5088 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5089 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5090 | return D2; |
| 5091 | } |
| 5092 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5093 | ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5094 | ClassTemplateSpecializationDecl *D) { |
| 5095 | // If this record has a definition in the translation unit we're coming from, |
| 5096 | // but this particular declaration is not that definition, import the |
| 5097 | // definition and map to that. |
| 5098 | TagDecl *Definition = D->getDefinition(); |
| 5099 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5100 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 5101 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5102 | else |
| 5103 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5104 | } |
| 5105 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5106 | ClassTemplateDecl *ClassTemplate; |
| 5107 | if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate())) |
| 5108 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5109 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5110 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5111 | DeclContext *DC, *LexicalDC; |
| 5112 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5113 | return std::move(Err); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5114 | |
| 5115 | // Import template arguments. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5116 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5117 | if (Error Err = ImportTemplateArguments( |
| 5118 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5119 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5120 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5121 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5122 | void *InsertPos = nullptr; |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5123 | ClassTemplateSpecializationDecl *D2 = nullptr; |
| 5124 | ClassTemplatePartialSpecializationDecl *PartialSpec = |
| 5125 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D); |
| 5126 | if (PartialSpec) |
| 5127 | D2 = ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos); |
| 5128 | else |
| 5129 | D2 = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
| 5130 | ClassTemplateSpecializationDecl * const PrevDecl = D2; |
| 5131 | RecordDecl *FoundDef = D2 ? D2->getDefinition() : nullptr; |
| 5132 | if (FoundDef) { |
| 5133 | if (!D->isCompleteDefinition()) { |
| 5134 | // The "From" translation unit only had a forward declaration; call it |
| 5135 | // the same declaration. |
| 5136 | // TODO Handle the redecl chain properly! |
| 5137 | return Importer.MapImported(D, FoundDef); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5138 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5139 | |
| 5140 | if (IsStructuralMatch(D, FoundDef)) { |
| 5141 | |
| 5142 | Importer.MapImported(D, FoundDef); |
| 5143 | |
| 5144 | // Import those those default field initializers which have been |
| 5145 | // instantiated in the "From" context, but not in the "To" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5146 | for (auto *FromField : D->fields()) { |
| 5147 | auto ToOrErr = import(FromField); |
| 5148 | if (!ToOrErr) |
| 5149 | // FIXME: return the error? |
| 5150 | consumeError(ToOrErr.takeError()); |
| 5151 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5152 | |
| 5153 | // Import those methods which have been instantiated in the |
| 5154 | // "From" context, but not in the "To" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5155 | for (CXXMethodDecl *FromM : D->methods()) { |
| 5156 | auto ToOrErr = import(FromM); |
| 5157 | if (!ToOrErr) |
| 5158 | // FIXME: return the error? |
| 5159 | consumeError(ToOrErr.takeError()); |
| 5160 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5161 | |
| 5162 | // TODO Import instantiated default arguments. |
| 5163 | // TODO Import instantiated exception specifications. |
| 5164 | // |
| 5165 | // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint what |
| 5166 | // else could be fused during an AST merge. |
| 5167 | |
| 5168 | return FoundDef; |
| 5169 | } |
| 5170 | } else { // We either couldn't find any previous specialization in the "To" |
| 5171 | // context, or we found one but without definition. Let's create a |
| 5172 | // new specialization and register that at the class template. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5173 | |
| 5174 | // Import the location of this declaration. |
| 5175 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5176 | if (!BeginLocOrErr) |
| 5177 | return BeginLocOrErr.takeError(); |
| 5178 | ExpectedSLoc IdLocOrErr = import(D->getLocation()); |
| 5179 | if (!IdLocOrErr) |
| 5180 | return IdLocOrErr.takeError(); |
| 5181 | |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5182 | if (PartialSpec) { |
| 5183 | // Import TemplateArgumentListInfo. |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5184 | TemplateArgumentListInfo ToTAInfo; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5185 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5186 | if (Error Err = ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) |
| 5187 | return std::move(Err); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5188 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5189 | QualType CanonInjType; |
| 5190 | if (Error Err = importInto( |
| 5191 | CanonInjType, PartialSpec->getInjectedSpecializationType())) |
| 5192 | return std::move(Err); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5193 | CanonInjType = CanonInjType.getCanonicalType(); |
| 5194 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5195 | auto ToTPListOrErr = ImportTemplateParameterList( |
| 5196 | PartialSpec->getTemplateParameters()); |
| 5197 | if (!ToTPListOrErr) |
| 5198 | return ToTPListOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5199 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5200 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5201 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| 5202 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, ClassTemplate, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5203 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5204 | ToTAInfo, CanonInjType, |
| 5205 | cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl))) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5206 | return D2; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5207 | |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5208 | // Update InsertPos, because preceding import calls may have invalidated |
| 5209 | // it by adding new specializations. |
| 5210 | if (!ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos)) |
| 5211 | // Add this partial specialization to the class template. |
| 5212 | ClassTemplate->AddPartialSpecialization( |
| 5213 | cast<ClassTemplatePartialSpecializationDecl>(D2), InsertPos); |
| 5214 | |
| 5215 | } else { // Not a partial specialization. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5216 | if (GetImportedOrCreateDecl( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5217 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| 5218 | *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs, |
| 5219 | PrevDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5220 | return D2; |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5221 | |
| 5222 | // Update InsertPos, because preceding import calls may have invalidated |
| 5223 | // it by adding new specializations. |
| 5224 | if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos)) |
| 5225 | // Add this specialization to the class template. |
| 5226 | ClassTemplate->AddSpecialization(D2, InsertPos); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5227 | } |
| 5228 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5229 | D2->setSpecializationKind(D->getSpecializationKind()); |
| 5230 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5231 | // Import the qualifier, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5232 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5233 | D2->setQualifierInfo(*LocOrErr); |
| 5234 | else |
| 5235 | return LocOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5236 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5237 | if (auto *TSI = D->getTypeAsWritten()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5238 | if (auto TInfoOrErr = import(TSI)) |
| 5239 | D2->setTypeAsWritten(*TInfoOrErr); |
| 5240 | else |
| 5241 | return TInfoOrErr.takeError(); |
| 5242 | |
| 5243 | if (auto LocOrErr = import(D->getTemplateKeywordLoc())) |
| 5244 | D2->setTemplateKeywordLoc(*LocOrErr); |
| 5245 | else |
| 5246 | return LocOrErr.takeError(); |
| 5247 | |
| 5248 | if (auto LocOrErr = import(D->getExternLoc())) |
| 5249 | D2->setExternLoc(*LocOrErr); |
| 5250 | else |
| 5251 | return LocOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5252 | } |
| 5253 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5254 | if (D->getPointOfInstantiation().isValid()) { |
| 5255 | if (auto POIOrErr = import(D->getPointOfInstantiation())) |
| 5256 | D2->setPointOfInstantiation(*POIOrErr); |
| 5257 | else |
| 5258 | return POIOrErr.takeError(); |
| 5259 | } |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5260 | |
| 5261 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 5262 | |
Gabor Marton | b14056b | 2018-05-25 11:21:24 +0000 | [diff] [blame] | 5263 | // Set the context of this specialization/instantiation. |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5264 | D2->setLexicalDeclContext(LexicalDC); |
Gabor Marton | b14056b | 2018-05-25 11:21:24 +0000 | [diff] [blame] | 5265 | |
| 5266 | // Add to the DC only if it was an explicit specialization/instantiation. |
| 5267 | if (D2->isExplicitInstantiationOrSpecialization()) { |
| 5268 | LexicalDC->addDeclInternal(D2); |
| 5269 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5270 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5271 | if (D->isCompleteDefinition()) |
| 5272 | if (Error Err = ImportDefinition(D, D2)) |
| 5273 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5274 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5275 | return D2; |
| 5276 | } |
| 5277 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5278 | ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5279 | // If this variable has a definition in the translation unit we're coming |
| 5280 | // from, |
| 5281 | // but this particular declaration is not that definition, import the |
| 5282 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5283 | auto *Definition = |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5284 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); |
| 5285 | if (Definition && Definition != D->getTemplatedDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5286 | if (ExpectedDecl ImportedDefOrErr = import( |
| 5287 | Definition->getDescribedVarTemplate())) |
| 5288 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5289 | else |
| 5290 | return ImportedDefOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5291 | } |
| 5292 | |
| 5293 | // Import the major distinguishing characteristics of this variable template. |
| 5294 | DeclContext *DC, *LexicalDC; |
| 5295 | DeclarationName Name; |
| 5296 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5297 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5298 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5299 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5300 | if (ToD) |
| 5301 | return ToD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5302 | |
| 5303 | // We may already have a template of the same name; try to find and match it. |
| 5304 | assert(!DC->isFunctionOrMethod() && |
| 5305 | "Variable templates cannot be declared at function scope"); |
| 5306 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 5307 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 5308 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5309 | for (auto *FoundDecl : FoundDecls) { |
| 5310 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5311 | continue; |
| 5312 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5313 | Decl *Found = FoundDecl; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5314 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5315 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 5316 | // The variable templates structurally match; call it the same template. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5317 | Importer.MapImported(D->getTemplatedDecl(), |
| 5318 | FoundTemplate->getTemplatedDecl()); |
| 5319 | return Importer.MapImported(D, FoundTemplate); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5320 | } |
| 5321 | } |
| 5322 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5323 | ConflictingDecls.push_back(FoundDecl); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5324 | } |
| 5325 | |
| 5326 | if (!ConflictingDecls.empty()) { |
| 5327 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 5328 | ConflictingDecls.data(), |
| 5329 | ConflictingDecls.size()); |
| 5330 | } |
| 5331 | |
| 5332 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5333 | // FIXME: Is it possible to get other error than name conflict? |
| 5334 | // (Put this `if` into the previous `if`?) |
| 5335 | return make_error<ImportError>(ImportError::NameConflict); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5336 | |
| 5337 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 5338 | |
| 5339 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5340 | // FIXME: Value not used? |
| 5341 | ExpectedType TypeOrErr = import(DTemplated->getType()); |
| 5342 | if (!TypeOrErr) |
| 5343 | return TypeOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5344 | |
| 5345 | // Create the declaration that is being templated. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5346 | VarDecl *ToTemplated; |
| 5347 | if (Error Err = importInto(ToTemplated, DTemplated)) |
| 5348 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5349 | |
| 5350 | // Create the variable template declaration itself. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5351 | auto TemplateParamsOrErr = ImportTemplateParameterList( |
| 5352 | D->getTemplateParameters()); |
| 5353 | if (!TemplateParamsOrErr) |
| 5354 | return TemplateParamsOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5355 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5356 | VarTemplateDecl *ToVarTD; |
| 5357 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5358 | Name, *TemplateParamsOrErr, ToTemplated)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5359 | return ToVarTD; |
| 5360 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5361 | ToTemplated->setDescribedVarTemplate(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5362 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5363 | ToVarTD->setAccess(D->getAccess()); |
| 5364 | ToVarTD->setLexicalDeclContext(LexicalDC); |
| 5365 | LexicalDC->addDeclInternal(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5366 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5367 | if (DTemplated->isThisDeclarationADefinition() && |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5368 | !ToTemplated->isThisDeclarationADefinition()) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5369 | // FIXME: Import definition! |
| 5370 | } |
| 5371 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5372 | return ToVarTD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5373 | } |
| 5374 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5375 | ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5376 | VarTemplateSpecializationDecl *D) { |
| 5377 | // If this record has a definition in the translation unit we're coming from, |
| 5378 | // but this particular declaration is not that definition, import the |
| 5379 | // definition and map to that. |
| 5380 | VarDecl *Definition = D->getDefinition(); |
| 5381 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5382 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 5383 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5384 | else |
| 5385 | return ImportedDefOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5386 | } |
| 5387 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5388 | VarTemplateDecl *VarTemplate; |
| 5389 | if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate())) |
| 5390 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5391 | |
| 5392 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5393 | DeclContext *DC, *LexicalDC; |
| 5394 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5395 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5396 | |
| 5397 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5398 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5399 | if (!BeginLocOrErr) |
| 5400 | return BeginLocOrErr.takeError(); |
| 5401 | |
| 5402 | auto IdLocOrErr = import(D->getLocation()); |
| 5403 | if (!IdLocOrErr) |
| 5404 | return IdLocOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5405 | |
| 5406 | // Import template arguments. |
| 5407 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5408 | if (Error Err = ImportTemplateArguments( |
| 5409 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5410 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5411 | |
| 5412 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5413 | void *InsertPos = nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5414 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 5415 | TemplateArgs, InsertPos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5416 | if (D2) { |
| 5417 | // We already have a variable template specialization with these template |
| 5418 | // arguments. |
| 5419 | |
| 5420 | // FIXME: Check for specialization vs. instantiation errors. |
| 5421 | |
| 5422 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 5423 | if (!D->isThisDeclarationADefinition() || |
| 5424 | IsStructuralMatch(D, FoundDef)) { |
| 5425 | // The record types structurally match, or the "from" translation |
| 5426 | // unit only had a forward declaration anyway; call it the same |
| 5427 | // variable. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5428 | return Importer.MapImported(D, FoundDef); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5429 | } |
| 5430 | } |
| 5431 | } else { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5432 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5433 | QualType T; |
| 5434 | if (Error Err = importInto(T, D->getType())) |
| 5435 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5436 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5437 | auto TInfoOrErr = import(D->getTypeSourceInfo()); |
| 5438 | if (!TInfoOrErr) |
| 5439 | return TInfoOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5440 | |
| 5441 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5442 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5443 | D->getTemplateArgsInfo(), ToTAInfo)) |
| 5444 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5445 | |
| 5446 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5447 | // Create a new specialization. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5448 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { |
| 5449 | // Import TemplateArgumentListInfo |
| 5450 | TemplateArgumentListInfo ArgInfos; |
| 5451 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); |
| 5452 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5453 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5454 | *FromTAArgsAsWritten, ArgInfos)) |
| 5455 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5456 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5457 | auto ToTPListOrErr = ImportTemplateParameterList( |
| 5458 | FromPartial->getTemplateParameters()); |
| 5459 | if (!ToTPListOrErr) |
| 5460 | return ToTPListOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5461 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5462 | PartVarSpecDecl *ToPartial; |
| 5463 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5464 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, |
| 5465 | VarTemplate, T, *TInfoOrErr, |
| 5466 | D->getStorageClass(), TemplateArgs, ArgInfos)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5467 | return ToPartial; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5468 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5469 | if (Expected<PartVarSpecDecl *> ToInstOrErr = import( |
| 5470 | FromPartial->getInstantiatedFromMember())) |
| 5471 | ToPartial->setInstantiatedFromMember(*ToInstOrErr); |
| 5472 | else |
| 5473 | return ToInstOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5474 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5475 | if (FromPartial->isMemberSpecialization()) |
| 5476 | ToPartial->setMemberSpecialization(); |
| 5477 | |
| 5478 | D2 = ToPartial; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5479 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5480 | } else { // Full specialization |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5481 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, |
| 5482 | *BeginLocOrErr, *IdLocOrErr, VarTemplate, |
| 5483 | T, *TInfoOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5484 | D->getStorageClass(), TemplateArgs)) |
| 5485 | return D2; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5486 | } |
| 5487 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5488 | if (D->getPointOfInstantiation().isValid()) { |
| 5489 | if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation())) |
| 5490 | D2->setPointOfInstantiation(*POIOrErr); |
| 5491 | else |
| 5492 | return POIOrErr.takeError(); |
| 5493 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5494 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5495 | D2->setSpecializationKind(D->getSpecializationKind()); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5496 | D2->setTemplateArgsInfo(ToTAInfo); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5497 | |
| 5498 | // Add this specialization to the class template. |
| 5499 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 5500 | |
| 5501 | // Import the qualifier, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5502 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5503 | D2->setQualifierInfo(*LocOrErr); |
| 5504 | else |
| 5505 | return LocOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5506 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5507 | if (D->isConstexpr()) |
| 5508 | D2->setConstexpr(true); |
| 5509 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5510 | // Add the specialization to this context. |
| 5511 | D2->setLexicalDeclContext(LexicalDC); |
| 5512 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5513 | |
| 5514 | D2->setAccess(D->getAccess()); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5515 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5516 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5517 | if (Error Err = ImportInitializer(D, D2)) |
| 5518 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5519 | |
| 5520 | return D2; |
| 5521 | } |
| 5522 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5523 | ExpectedDecl |
| 5524 | ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5525 | DeclContext *DC, *LexicalDC; |
| 5526 | DeclarationName Name; |
| 5527 | SourceLocation Loc; |
| 5528 | NamedDecl *ToD; |
| 5529 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5530 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5531 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5532 | |
| 5533 | if (ToD) |
| 5534 | return ToD; |
| 5535 | |
| 5536 | // Try to find a function in our own ("to") context with the same name, same |
| 5537 | // type, and in the same context as the function we're importing. |
| 5538 | if (!LexicalDC->isFunctionOrMethod()) { |
| 5539 | unsigned IDNS = Decl::IDNS_Ordinary; |
| 5540 | SmallVector<NamedDecl *, 2> FoundDecls; |
| 5541 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5542 | for (auto *FoundDecl : FoundDecls) { |
| 5543 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5544 | continue; |
| 5545 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5546 | if (auto *FoundFunction = |
| 5547 | dyn_cast<FunctionTemplateDecl>(FoundDecl)) { |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5548 | if (FoundFunction->hasExternalFormalLinkage() && |
| 5549 | D->hasExternalFormalLinkage()) { |
| 5550 | if (IsStructuralMatch(D, FoundFunction)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5551 | Importer.MapImported(D, FoundFunction); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5552 | // FIXME: Actually try to merge the body and other attributes. |
| 5553 | return FoundFunction; |
| 5554 | } |
| 5555 | } |
| 5556 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5557 | // TODO: handle conflicting names |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5558 | } |
| 5559 | } |
| 5560 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5561 | auto ParamsOrErr = ImportTemplateParameterList( |
| 5562 | D->getTemplateParameters()); |
| 5563 | if (!ParamsOrErr) |
| 5564 | return ParamsOrErr.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5565 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5566 | FunctionDecl *TemplatedFD; |
| 5567 | if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl())) |
| 5568 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5569 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5570 | FunctionTemplateDecl *ToFunc; |
| 5571 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5572 | *ParamsOrErr, TemplatedFD)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5573 | return ToFunc; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5574 | |
| 5575 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); |
| 5576 | ToFunc->setAccess(D->getAccess()); |
| 5577 | ToFunc->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5578 | |
| 5579 | LexicalDC->addDeclInternal(ToFunc); |
| 5580 | return ToFunc; |
| 5581 | } |
| 5582 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5583 | //---------------------------------------------------------------------------- |
| 5584 | // Import Statements |
| 5585 | //---------------------------------------------------------------------------- |
| 5586 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5587 | ExpectedStmt ASTNodeImporter::VisitStmt(Stmt *S) { |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5588 | Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node) |
| 5589 | << S->getStmtClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5590 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5591 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5592 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5593 | |
| 5594 | ExpectedStmt ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5595 | SmallVector<IdentifierInfo *, 4> Names; |
| 5596 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 5597 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5598 | // ToII is nullptr when no symbolic name is given for output operand |
| 5599 | // see ParseStmtAsm::ParseAsmOperandsOpt |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5600 | Names.push_back(ToII); |
| 5601 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5602 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5603 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 5604 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5605 | // ToII is nullptr when no symbolic name is given for input operand |
| 5606 | // see ParseStmtAsm::ParseAsmOperandsOpt |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5607 | Names.push_back(ToII); |
| 5608 | } |
| 5609 | |
| 5610 | SmallVector<StringLiteral *, 4> Clobbers; |
| 5611 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5612 | if (auto ClobberOrErr = import(S->getClobberStringLiteral(I))) |
| 5613 | Clobbers.push_back(*ClobberOrErr); |
| 5614 | else |
| 5615 | return ClobberOrErr.takeError(); |
| 5616 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5617 | } |
| 5618 | |
| 5619 | SmallVector<StringLiteral *, 4> Constraints; |
| 5620 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5621 | if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I))) |
| 5622 | Constraints.push_back(*OutputOrErr); |
| 5623 | else |
| 5624 | return OutputOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5625 | } |
| 5626 | |
| 5627 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5628 | if (auto InputOrErr = import(S->getInputConstraintLiteral(I))) |
| 5629 | Constraints.push_back(*InputOrErr); |
| 5630 | else |
| 5631 | return InputOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5632 | } |
| 5633 | |
| 5634 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5635 | if (Error Err = ImportContainerChecked(S->outputs(), Exprs)) |
| 5636 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5637 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5638 | if (Error Err = ImportArrayChecked( |
| 5639 | S->inputs(), Exprs.begin() + S->getNumOutputs())) |
| 5640 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5641 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5642 | ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc()); |
| 5643 | if (!AsmLocOrErr) |
| 5644 | return AsmLocOrErr.takeError(); |
| 5645 | auto AsmStrOrErr = import(S->getAsmString()); |
| 5646 | if (!AsmStrOrErr) |
| 5647 | return AsmStrOrErr.takeError(); |
| 5648 | ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc()); |
| 5649 | if (!RParenLocOrErr) |
| 5650 | return RParenLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5651 | |
| 5652 | return new (Importer.getToContext()) GCCAsmStmt( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5653 | Importer.getToContext(), |
| 5654 | *AsmLocOrErr, |
| 5655 | S->isSimple(), |
| 5656 | S->isVolatile(), |
| 5657 | S->getNumOutputs(), |
| 5658 | S->getNumInputs(), |
| 5659 | Names.data(), |
| 5660 | Constraints.data(), |
| 5661 | Exprs.data(), |
| 5662 | *AsmStrOrErr, |
| 5663 | S->getNumClobbers(), |
| 5664 | Clobbers.data(), |
| 5665 | *RParenLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5666 | } |
| 5667 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5668 | ExpectedStmt ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| 5669 | auto Imp = importSeq(S->getDeclGroup(), S->getBeginLoc(), S->getEndLoc()); |
| 5670 | if (!Imp) |
| 5671 | return Imp.takeError(); |
| 5672 | |
| 5673 | DeclGroupRef ToDG; |
| 5674 | SourceLocation ToBeginLoc, ToEndLoc; |
| 5675 | std::tie(ToDG, ToBeginLoc, ToEndLoc) = *Imp; |
| 5676 | |
| 5677 | return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5678 | } |
| 5679 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5680 | ExpectedStmt ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 5681 | ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc()); |
| 5682 | if (!ToSemiLocOrErr) |
| 5683 | return ToSemiLocOrErr.takeError(); |
| 5684 | return new (Importer.getToContext()) NullStmt( |
| 5685 | *ToSemiLocOrErr, S->hasLeadingEmptyMacro()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5686 | } |
| 5687 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5688 | ExpectedStmt ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5689 | SmallVector<Stmt *, 8> ToStmts(S->size()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5690 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5691 | if (Error Err = ImportContainerChecked(S->body(), ToStmts)) |
| 5692 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5693 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5694 | ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc()); |
| 5695 | if (!ToLBracLocOrErr) |
| 5696 | return ToLBracLocOrErr.takeError(); |
| 5697 | |
| 5698 | ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc()); |
| 5699 | if (!ToRBracLocOrErr) |
| 5700 | return ToRBracLocOrErr.takeError(); |
| 5701 | |
| 5702 | return CompoundStmt::Create( |
| 5703 | Importer.getToContext(), ToStmts, |
| 5704 | *ToLBracLocOrErr, *ToRBracLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5705 | } |
| 5706 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5707 | ExpectedStmt ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| 5708 | auto Imp = importSeq( |
| 5709 | S->getLHS(), S->getRHS(), S->getSubStmt(), S->getCaseLoc(), |
| 5710 | S->getEllipsisLoc(), S->getColonLoc()); |
| 5711 | if (!Imp) |
| 5712 | return Imp.takeError(); |
| 5713 | |
| 5714 | Expr *ToLHS, *ToRHS; |
| 5715 | Stmt *ToSubStmt; |
| 5716 | SourceLocation ToCaseLoc, ToEllipsisLoc, ToColonLoc; |
| 5717 | std::tie(ToLHS, ToRHS, ToSubStmt, ToCaseLoc, ToEllipsisLoc, ToColonLoc) = |
| 5718 | *Imp; |
| 5719 | |
Bruno Ricci | 5b3057175 | 2018-10-28 12:30:53 +0000 | [diff] [blame] | 5720 | auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS, |
| 5721 | ToCaseLoc, ToEllipsisLoc, ToColonLoc); |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5722 | ToStmt->setSubStmt(ToSubStmt); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5723 | |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5724 | return ToStmt; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5725 | } |
| 5726 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5727 | ExpectedStmt ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| 5728 | auto Imp = importSeq(S->getDefaultLoc(), S->getColonLoc(), S->getSubStmt()); |
| 5729 | if (!Imp) |
| 5730 | return Imp.takeError(); |
| 5731 | |
| 5732 | SourceLocation ToDefaultLoc, ToColonLoc; |
| 5733 | Stmt *ToSubStmt; |
| 5734 | std::tie(ToDefaultLoc, ToColonLoc, ToSubStmt) = *Imp; |
| 5735 | |
| 5736 | return new (Importer.getToContext()) DefaultStmt( |
| 5737 | ToDefaultLoc, ToColonLoc, ToSubStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5738 | } |
| 5739 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5740 | ExpectedStmt ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| 5741 | auto Imp = importSeq(S->getIdentLoc(), S->getDecl(), S->getSubStmt()); |
| 5742 | if (!Imp) |
| 5743 | return Imp.takeError(); |
| 5744 | |
| 5745 | SourceLocation ToIdentLoc; |
| 5746 | LabelDecl *ToLabelDecl; |
| 5747 | Stmt *ToSubStmt; |
| 5748 | std::tie(ToIdentLoc, ToLabelDecl, ToSubStmt) = *Imp; |
| 5749 | |
| 5750 | return new (Importer.getToContext()) LabelStmt( |
| 5751 | ToIdentLoc, ToLabelDecl, ToSubStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5752 | } |
| 5753 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5754 | ExpectedStmt ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { |
| 5755 | ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc()); |
| 5756 | if (!ToAttrLocOrErr) |
| 5757 | return ToAttrLocOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5758 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 5759 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5760 | if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs)) |
| 5761 | return std::move(Err); |
| 5762 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 5763 | if (!ToSubStmtOrErr) |
| 5764 | return ToSubStmtOrErr.takeError(); |
| 5765 | |
| 5766 | return AttributedStmt::Create( |
| 5767 | Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5768 | } |
| 5769 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5770 | ExpectedStmt ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| 5771 | auto Imp = importSeq( |
| 5772 | S->getIfLoc(), S->getInit(), S->getConditionVariable(), S->getCond(), |
| 5773 | S->getThen(), S->getElseLoc(), S->getElse()); |
| 5774 | if (!Imp) |
| 5775 | return Imp.takeError(); |
| 5776 | |
| 5777 | SourceLocation ToIfLoc, ToElseLoc; |
| 5778 | Stmt *ToInit, *ToThen, *ToElse; |
| 5779 | VarDecl *ToConditionVariable; |
| 5780 | Expr *ToCond; |
| 5781 | std::tie( |
| 5782 | ToIfLoc, ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, ToElse) = |
| 5783 | *Imp; |
| 5784 | |
Bruno Ricci | b1cc94b | 2018-10-27 21:12:20 +0000 | [diff] [blame] | 5785 | return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->isConstexpr(), |
| 5786 | ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, |
| 5787 | ToElse); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5788 | } |
| 5789 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5790 | ExpectedStmt ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
| 5791 | auto Imp = importSeq( |
| 5792 | S->getInit(), S->getConditionVariable(), S->getCond(), |
| 5793 | S->getBody(), S->getSwitchLoc()); |
| 5794 | if (!Imp) |
| 5795 | return Imp.takeError(); |
| 5796 | |
| 5797 | Stmt *ToInit, *ToBody; |
| 5798 | VarDecl *ToConditionVariable; |
| 5799 | Expr *ToCond; |
| 5800 | SourceLocation ToSwitchLoc; |
| 5801 | std::tie(ToInit, ToConditionVariable, ToCond, ToBody, ToSwitchLoc) = *Imp; |
| 5802 | |
Bruno Ricci | e2806f8 | 2018-10-29 16:12:37 +0000 | [diff] [blame] | 5803 | auto *ToStmt = SwitchStmt::Create(Importer.getToContext(), ToInit, |
| 5804 | ToConditionVariable, ToCond); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5805 | ToStmt->setBody(ToBody); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5806 | ToStmt->setSwitchLoc(ToSwitchLoc); |
| 5807 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5808 | // Now we have to re-chain the cases. |
| 5809 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 5810 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 5811 | SC = SC->getNextSwitchCase()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5812 | Expected<SwitchCase *> ToSCOrErr = import(SC); |
| 5813 | if (!ToSCOrErr) |
| 5814 | return ToSCOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5815 | if (LastChainedSwitchCase) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5816 | LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5817 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5818 | ToStmt->setSwitchCaseList(*ToSCOrErr); |
| 5819 | LastChainedSwitchCase = *ToSCOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5820 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5821 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5822 | return ToStmt; |
| 5823 | } |
| 5824 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5825 | ExpectedStmt ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| 5826 | auto Imp = importSeq( |
| 5827 | S->getConditionVariable(), S->getCond(), S->getBody(), S->getWhileLoc()); |
| 5828 | if (!Imp) |
| 5829 | return Imp.takeError(); |
| 5830 | |
| 5831 | VarDecl *ToConditionVariable; |
| 5832 | Expr *ToCond; |
| 5833 | Stmt *ToBody; |
| 5834 | SourceLocation ToWhileLoc; |
| 5835 | std::tie(ToConditionVariable, ToCond, ToBody, ToWhileLoc) = *Imp; |
| 5836 | |
Bruno Ricci | bacf751 | 2018-10-30 13:42:41 +0000 | [diff] [blame] | 5837 | return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond, |
| 5838 | ToBody, ToWhileLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5839 | } |
| 5840 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5841 | ExpectedStmt ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| 5842 | auto Imp = importSeq( |
| 5843 | S->getBody(), S->getCond(), S->getDoLoc(), S->getWhileLoc(), |
| 5844 | S->getRParenLoc()); |
| 5845 | if (!Imp) |
| 5846 | return Imp.takeError(); |
| 5847 | |
| 5848 | Stmt *ToBody; |
| 5849 | Expr *ToCond; |
| 5850 | SourceLocation ToDoLoc, ToWhileLoc, ToRParenLoc; |
| 5851 | std::tie(ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc) = *Imp; |
| 5852 | |
| 5853 | return new (Importer.getToContext()) DoStmt( |
| 5854 | ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5855 | } |
| 5856 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5857 | ExpectedStmt ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| 5858 | auto Imp = importSeq( |
| 5859 | S->getInit(), S->getCond(), S->getConditionVariable(), S->getInc(), |
| 5860 | S->getBody(), S->getForLoc(), S->getLParenLoc(), S->getRParenLoc()); |
| 5861 | if (!Imp) |
| 5862 | return Imp.takeError(); |
| 5863 | |
| 5864 | Stmt *ToInit; |
| 5865 | Expr *ToCond, *ToInc; |
| 5866 | VarDecl *ToConditionVariable; |
| 5867 | Stmt *ToBody; |
| 5868 | SourceLocation ToForLoc, ToLParenLoc, ToRParenLoc; |
| 5869 | std::tie( |
| 5870 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, |
| 5871 | ToLParenLoc, ToRParenLoc) = *Imp; |
| 5872 | |
| 5873 | return new (Importer.getToContext()) ForStmt( |
| 5874 | Importer.getToContext(), |
| 5875 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc, |
| 5876 | ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5877 | } |
| 5878 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5879 | ExpectedStmt ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| 5880 | auto Imp = importSeq(S->getLabel(), S->getGotoLoc(), S->getLabelLoc()); |
| 5881 | if (!Imp) |
| 5882 | return Imp.takeError(); |
| 5883 | |
| 5884 | LabelDecl *ToLabel; |
| 5885 | SourceLocation ToGotoLoc, ToLabelLoc; |
| 5886 | std::tie(ToLabel, ToGotoLoc, ToLabelLoc) = *Imp; |
| 5887 | |
| 5888 | return new (Importer.getToContext()) GotoStmt( |
| 5889 | ToLabel, ToGotoLoc, ToLabelLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5890 | } |
| 5891 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5892 | ExpectedStmt ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 5893 | auto Imp = importSeq(S->getGotoLoc(), S->getStarLoc(), S->getTarget()); |
| 5894 | if (!Imp) |
| 5895 | return Imp.takeError(); |
| 5896 | |
| 5897 | SourceLocation ToGotoLoc, ToStarLoc; |
| 5898 | Expr *ToTarget; |
| 5899 | std::tie(ToGotoLoc, ToStarLoc, ToTarget) = *Imp; |
| 5900 | |
| 5901 | return new (Importer.getToContext()) IndirectGotoStmt( |
| 5902 | ToGotoLoc, ToStarLoc, ToTarget); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5903 | } |
| 5904 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5905 | ExpectedStmt ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 5906 | ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc()); |
| 5907 | if (!ToContinueLocOrErr) |
| 5908 | return ToContinueLocOrErr.takeError(); |
| 5909 | return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5910 | } |
| 5911 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5912 | ExpectedStmt ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 5913 | auto ToBreakLocOrErr = import(S->getBreakLoc()); |
| 5914 | if (!ToBreakLocOrErr) |
| 5915 | return ToBreakLocOrErr.takeError(); |
| 5916 | return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5917 | } |
| 5918 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5919 | ExpectedStmt ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| 5920 | auto Imp = importSeq( |
| 5921 | S->getReturnLoc(), S->getRetValue(), S->getNRVOCandidate()); |
| 5922 | if (!Imp) |
| 5923 | return Imp.takeError(); |
| 5924 | |
| 5925 | SourceLocation ToReturnLoc; |
| 5926 | Expr *ToRetValue; |
| 5927 | const VarDecl *ToNRVOCandidate; |
| 5928 | std::tie(ToReturnLoc, ToRetValue, ToNRVOCandidate) = *Imp; |
| 5929 | |
Bruno Ricci | 023b1d1 | 2018-10-30 14:40:49 +0000 | [diff] [blame] | 5930 | return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue, |
| 5931 | ToNRVOCandidate); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5932 | } |
| 5933 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5934 | ExpectedStmt ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| 5935 | auto Imp = importSeq( |
| 5936 | S->getCatchLoc(), S->getExceptionDecl(), S->getHandlerBlock()); |
| 5937 | if (!Imp) |
| 5938 | return Imp.takeError(); |
| 5939 | |
| 5940 | SourceLocation ToCatchLoc; |
| 5941 | VarDecl *ToExceptionDecl; |
| 5942 | Stmt *ToHandlerBlock; |
| 5943 | std::tie(ToCatchLoc, ToExceptionDecl, ToHandlerBlock) = *Imp; |
| 5944 | |
| 5945 | return new (Importer.getToContext()) CXXCatchStmt ( |
| 5946 | ToCatchLoc, ToExceptionDecl, ToHandlerBlock); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5947 | } |
| 5948 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5949 | ExpectedStmt ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 5950 | ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc()); |
| 5951 | if (!ToTryLocOrErr) |
| 5952 | return ToTryLocOrErr.takeError(); |
| 5953 | |
| 5954 | ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock()); |
| 5955 | if (!ToTryBlockOrErr) |
| 5956 | return ToTryBlockOrErr.takeError(); |
| 5957 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5958 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 5959 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 5960 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5961 | if (auto ToHandlerOrErr = import(FromHandler)) |
| 5962 | ToHandlers[HI] = *ToHandlerOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5963 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5964 | return ToHandlerOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5965 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5966 | |
| 5967 | return CXXTryStmt::Create( |
| 5968 | Importer.getToContext(), *ToTryLocOrErr,*ToTryBlockOrErr, ToHandlers); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5969 | } |
| 5970 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5971 | ExpectedStmt ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
| 5972 | auto Imp1 = importSeq( |
| 5973 | S->getInit(), S->getRangeStmt(), S->getBeginStmt(), S->getEndStmt(), |
| 5974 | S->getCond(), S->getInc(), S->getLoopVarStmt(), S->getBody()); |
| 5975 | if (!Imp1) |
| 5976 | return Imp1.takeError(); |
| 5977 | auto Imp2 = importSeq( |
| 5978 | S->getForLoc(), S->getCoawaitLoc(), S->getColonLoc(), S->getRParenLoc()); |
| 5979 | if (!Imp2) |
| 5980 | return Imp2.takeError(); |
| 5981 | |
| 5982 | DeclStmt *ToRangeStmt, *ToBeginStmt, *ToEndStmt, *ToLoopVarStmt; |
| 5983 | Expr *ToCond, *ToInc; |
| 5984 | Stmt *ToInit, *ToBody; |
| 5985 | std::tie( |
| 5986 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 5987 | ToBody) = *Imp1; |
| 5988 | SourceLocation ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc; |
| 5989 | std::tie(ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc) = *Imp2; |
| 5990 | |
| 5991 | return new (Importer.getToContext()) CXXForRangeStmt( |
| 5992 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 5993 | ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5994 | } |
| 5995 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5996 | ExpectedStmt |
| 5997 | ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 5998 | auto Imp = importSeq( |
| 5999 | S->getElement(), S->getCollection(), S->getBody(), |
| 6000 | S->getForLoc(), S->getRParenLoc()); |
| 6001 | if (!Imp) |
| 6002 | return Imp.takeError(); |
| 6003 | |
| 6004 | Stmt *ToElement, *ToBody; |
| 6005 | Expr *ToCollection; |
| 6006 | SourceLocation ToForLoc, ToRParenLoc; |
| 6007 | std::tie(ToElement, ToCollection, ToBody, ToForLoc, ToRParenLoc) = *Imp; |
| 6008 | |
| 6009 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement, |
| 6010 | ToCollection, |
| 6011 | ToBody, |
| 6012 | ToForLoc, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6013 | ToRParenLoc); |
| 6014 | } |
| 6015 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6016 | ExpectedStmt ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 6017 | auto Imp = importSeq( |
| 6018 | S->getAtCatchLoc(), S->getRParenLoc(), S->getCatchParamDecl(), |
| 6019 | S->getCatchBody()); |
| 6020 | if (!Imp) |
| 6021 | return Imp.takeError(); |
| 6022 | |
| 6023 | SourceLocation ToAtCatchLoc, ToRParenLoc; |
| 6024 | VarDecl *ToCatchParamDecl; |
| 6025 | Stmt *ToCatchBody; |
| 6026 | std::tie(ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody) = *Imp; |
| 6027 | |
| 6028 | return new (Importer.getToContext()) ObjCAtCatchStmt ( |
| 6029 | ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6030 | } |
| 6031 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6032 | ExpectedStmt ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 6033 | ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc()); |
| 6034 | if (!ToAtFinallyLocOrErr) |
| 6035 | return ToAtFinallyLocOrErr.takeError(); |
| 6036 | ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody()); |
| 6037 | if (!ToAtFinallyStmtOrErr) |
| 6038 | return ToAtFinallyStmtOrErr.takeError(); |
| 6039 | return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr, |
| 6040 | *ToAtFinallyStmtOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6041 | } |
| 6042 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6043 | ExpectedStmt ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 6044 | auto Imp = importSeq( |
| 6045 | S->getAtTryLoc(), S->getTryBody(), S->getFinallyStmt()); |
| 6046 | if (!Imp) |
| 6047 | return Imp.takeError(); |
| 6048 | |
| 6049 | SourceLocation ToAtTryLoc; |
| 6050 | Stmt *ToTryBody, *ToFinallyStmt; |
| 6051 | std::tie(ToAtTryLoc, ToTryBody, ToFinallyStmt) = *Imp; |
| 6052 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6053 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 6054 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 6055 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6056 | if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt)) |
| 6057 | ToCatchStmts[CI] = *ToCatchStmtOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6058 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6059 | return ToCatchStmtOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6060 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6061 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6062 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6063 | ToAtTryLoc, ToTryBody, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6064 | ToCatchStmts.begin(), ToCatchStmts.size(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6065 | ToFinallyStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6066 | } |
| 6067 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6068 | ExpectedStmt ASTNodeImporter::VisitObjCAtSynchronizedStmt |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6069 | (ObjCAtSynchronizedStmt *S) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6070 | auto Imp = importSeq( |
| 6071 | S->getAtSynchronizedLoc(), S->getSynchExpr(), S->getSynchBody()); |
| 6072 | if (!Imp) |
| 6073 | return Imp.takeError(); |
| 6074 | |
| 6075 | SourceLocation ToAtSynchronizedLoc; |
| 6076 | Expr *ToSynchExpr; |
| 6077 | Stmt *ToSynchBody; |
| 6078 | std::tie(ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody) = *Imp; |
| 6079 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6080 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 6081 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 6082 | } |
| 6083 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6084 | ExpectedStmt ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 6085 | ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc()); |
| 6086 | if (!ToThrowLocOrErr) |
| 6087 | return ToThrowLocOrErr.takeError(); |
| 6088 | ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr()); |
| 6089 | if (!ToThrowExprOrErr) |
| 6090 | return ToThrowExprOrErr.takeError(); |
| 6091 | return new (Importer.getToContext()) ObjCAtThrowStmt( |
| 6092 | *ToThrowLocOrErr, *ToThrowExprOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6093 | } |
| 6094 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6095 | ExpectedStmt ASTNodeImporter::VisitObjCAutoreleasePoolStmt( |
| 6096 | ObjCAutoreleasePoolStmt *S) { |
| 6097 | ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc()); |
| 6098 | if (!ToAtLocOrErr) |
| 6099 | return ToAtLocOrErr.takeError(); |
| 6100 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 6101 | if (!ToSubStmtOrErr) |
| 6102 | return ToSubStmtOrErr.takeError(); |
| 6103 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr, |
| 6104 | *ToSubStmtOrErr); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6105 | } |
| 6106 | |
| 6107 | //---------------------------------------------------------------------------- |
| 6108 | // Import Expressions |
| 6109 | //---------------------------------------------------------------------------- |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6110 | ExpectedStmt ASTNodeImporter::VisitExpr(Expr *E) { |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6111 | Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node) |
| 6112 | << E->getStmtClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6113 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6114 | } |
| 6115 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6116 | ExpectedStmt ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| 6117 | auto Imp = importSeq( |
| 6118 | E->getBuiltinLoc(), E->getSubExpr(), E->getWrittenTypeInfo(), |
| 6119 | E->getRParenLoc(), E->getType()); |
| 6120 | if (!Imp) |
| 6121 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6122 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6123 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6124 | Expr *ToSubExpr; |
| 6125 | TypeSourceInfo *ToWrittenTypeInfo; |
| 6126 | QualType ToType; |
| 6127 | std::tie(ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType) = |
| 6128 | *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6129 | |
| 6130 | return new (Importer.getToContext()) VAArgExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6131 | ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType, |
| 6132 | E->isMicrosoftABI()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6133 | } |
| 6134 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6135 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6136 | ExpectedStmt ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 6137 | ExpectedType TypeOrErr = import(E->getType()); |
| 6138 | if (!TypeOrErr) |
| 6139 | return TypeOrErr.takeError(); |
| 6140 | |
| 6141 | ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc()); |
| 6142 | if (!BeginLocOrErr) |
| 6143 | return BeginLocOrErr.takeError(); |
| 6144 | |
| 6145 | return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6146 | } |
| 6147 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6148 | ExpectedStmt ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { |
| 6149 | auto Imp = importSeq( |
| 6150 | E->getBeginLoc(), E->getType(), E->getFunctionName()); |
| 6151 | if (!Imp) |
| 6152 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6153 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6154 | SourceLocation ToBeginLoc; |
| 6155 | QualType ToType; |
| 6156 | StringLiteral *ToFunctionName; |
| 6157 | std::tie(ToBeginLoc, ToType, ToFunctionName) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6158 | |
Bruno Ricci | 17ff026 | 2018-10-27 19:21:19 +0000 | [diff] [blame] | 6159 | return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType, |
| 6160 | E->getIdentKind(), ToFunctionName); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6161 | } |
| 6162 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6163 | ExpectedStmt ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
| 6164 | auto Imp = importSeq( |
| 6165 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDecl(), |
| 6166 | E->getLocation(), E->getType()); |
| 6167 | if (!Imp) |
| 6168 | return Imp.takeError(); |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6169 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6170 | NestedNameSpecifierLoc ToQualifierLoc; |
| 6171 | SourceLocation ToTemplateKeywordLoc, ToLocation; |
| 6172 | ValueDecl *ToDecl; |
| 6173 | QualType ToType; |
| 6174 | std::tie(ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, ToLocation, ToType) = |
| 6175 | *Imp; |
| 6176 | |
| 6177 | NamedDecl *ToFoundD = nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6178 | if (E->getDecl() != E->getFoundDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6179 | auto FoundDOrErr = import(E->getFoundDecl()); |
| 6180 | if (!FoundDOrErr) |
| 6181 | return FoundDOrErr.takeError(); |
| 6182 | ToFoundD = *FoundDOrErr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6183 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6184 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6185 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6186 | TemplateArgumentListInfo *ToResInfo = nullptr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6187 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6188 | if (Error Err = |
| 6189 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 6190 | return std::move(Err); |
| 6191 | ToResInfo = &ToTAInfo; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6192 | } |
| 6193 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6194 | auto *ToE = DeclRefExpr::Create( |
| 6195 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, |
| 6196 | E->refersToEnclosingVariableOrCapture(), ToLocation, ToType, |
| 6197 | E->getValueKind(), ToFoundD, ToResInfo); |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 6198 | if (E->hadMultipleCandidates()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6199 | ToE->setHadMultipleCandidates(true); |
| 6200 | return ToE; |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 6201 | } |
| 6202 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6203 | ExpectedStmt ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 6204 | ExpectedType TypeOrErr = import(E->getType()); |
| 6205 | if (!TypeOrErr) |
| 6206 | return TypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6207 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6208 | return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6209 | } |
| 6210 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6211 | ExpectedStmt ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { |
| 6212 | ExpectedExpr ToInitOrErr = import(E->getInit()); |
| 6213 | if (!ToInitOrErr) |
| 6214 | return ToInitOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6215 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6216 | ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc()); |
| 6217 | if (!ToEqualOrColonLocOrErr) |
| 6218 | return ToEqualOrColonLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6219 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6220 | SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6221 | // List elements from the second, the first is Init itself |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6222 | for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) { |
| 6223 | if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I))) |
| 6224 | ToIndexExprs[I - 1] = *ToArgOrErr; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6225 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6226 | return ToArgOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6227 | } |
| 6228 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6229 | SmallVector<Designator, 4> ToDesignators(E->size()); |
| 6230 | if (Error Err = ImportContainerChecked(E->designators(), ToDesignators)) |
| 6231 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6232 | |
| 6233 | return DesignatedInitExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6234 | Importer.getToContext(), ToDesignators, |
| 6235 | ToIndexExprs, *ToEqualOrColonLocOrErr, |
| 6236 | E->usesGNUSyntax(), *ToInitOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6237 | } |
| 6238 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6239 | ExpectedStmt |
| 6240 | ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 6241 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6242 | if (!ToTypeOrErr) |
| 6243 | return ToTypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6244 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6245 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6246 | if (!ToLocationOrErr) |
| 6247 | return ToLocationOrErr.takeError(); |
| 6248 | |
| 6249 | return new (Importer.getToContext()) CXXNullPtrLiteralExpr( |
| 6250 | *ToTypeOrErr, *ToLocationOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6251 | } |
| 6252 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6253 | ExpectedStmt ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 6254 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6255 | if (!ToTypeOrErr) |
| 6256 | return ToTypeOrErr.takeError(); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6257 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6258 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6259 | if (!ToLocationOrErr) |
| 6260 | return ToLocationOrErr.takeError(); |
| 6261 | |
| 6262 | return IntegerLiteral::Create( |
| 6263 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6264 | } |
| 6265 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6266 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6267 | ExpectedStmt ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 6268 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6269 | if (!ToTypeOrErr) |
| 6270 | return ToTypeOrErr.takeError(); |
| 6271 | |
| 6272 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6273 | if (!ToLocationOrErr) |
| 6274 | return ToLocationOrErr.takeError(); |
| 6275 | |
| 6276 | return FloatingLiteral::Create( |
| 6277 | Importer.getToContext(), E->getValue(), E->isExact(), |
| 6278 | *ToTypeOrErr, *ToLocationOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6279 | } |
| 6280 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6281 | ExpectedStmt ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) { |
| 6282 | auto ToTypeOrErr = import(E->getType()); |
| 6283 | if (!ToTypeOrErr) |
| 6284 | return ToTypeOrErr.takeError(); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6285 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6286 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6287 | if (!ToSubExprOrErr) |
| 6288 | return ToSubExprOrErr.takeError(); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6289 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6290 | return new (Importer.getToContext()) ImaginaryLiteral( |
| 6291 | *ToSubExprOrErr, *ToTypeOrErr); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6292 | } |
| 6293 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6294 | ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 6295 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6296 | if (!ToTypeOrErr) |
| 6297 | return ToTypeOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6298 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6299 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6300 | if (!ToLocationOrErr) |
| 6301 | return ToLocationOrErr.takeError(); |
| 6302 | |
| 6303 | return new (Importer.getToContext()) CharacterLiteral( |
| 6304 | E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr); |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 6305 | } |
| 6306 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6307 | ExpectedStmt ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 6308 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6309 | if (!ToTypeOrErr) |
| 6310 | return ToTypeOrErr.takeError(); |
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 | SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated()); |
| 6313 | if (Error Err = ImportArrayChecked( |
| 6314 | E->tokloc_begin(), E->tokloc_end(), ToLocations.begin())) |
| 6315 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6316 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6317 | return StringLiteral::Create( |
| 6318 | Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(), |
| 6319 | *ToTypeOrErr, ToLocations.data(), ToLocations.size()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6320 | } |
| 6321 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6322 | ExpectedStmt ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 6323 | auto Imp = importSeq( |
| 6324 | E->getLParenLoc(), E->getTypeSourceInfo(), E->getType(), |
| 6325 | E->getInitializer()); |
| 6326 | if (!Imp) |
| 6327 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6328 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6329 | SourceLocation ToLParenLoc; |
| 6330 | TypeSourceInfo *ToTypeSourceInfo; |
| 6331 | QualType ToType; |
| 6332 | Expr *ToInitializer; |
| 6333 | std::tie(ToLParenLoc, ToTypeSourceInfo, ToType, ToInitializer) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6334 | |
| 6335 | return new (Importer.getToContext()) CompoundLiteralExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6336 | ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(), |
| 6337 | ToInitializer, E->isFileScope()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6338 | } |
| 6339 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6340 | ExpectedStmt ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { |
| 6341 | auto Imp = importSeq( |
| 6342 | E->getBuiltinLoc(), E->getType(), E->getRParenLoc()); |
| 6343 | if (!Imp) |
| 6344 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6345 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6346 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6347 | QualType ToType; |
| 6348 | std::tie(ToBuiltinLoc, ToType, ToRParenLoc) = *Imp; |
| 6349 | |
| 6350 | SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs()); |
| 6351 | if (Error Err = ImportArrayChecked( |
| 6352 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 6353 | ToExprs.begin())) |
| 6354 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6355 | |
| 6356 | return new (Importer.getToContext()) AtomicExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6357 | ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6358 | } |
| 6359 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6360 | ExpectedStmt ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 6361 | auto Imp = importSeq( |
| 6362 | E->getAmpAmpLoc(), E->getLabelLoc(), E->getLabel(), E->getType()); |
| 6363 | if (!Imp) |
| 6364 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6365 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6366 | SourceLocation ToAmpAmpLoc, ToLabelLoc; |
| 6367 | LabelDecl *ToLabel; |
| 6368 | QualType ToType; |
| 6369 | std::tie(ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6370 | |
| 6371 | return new (Importer.getToContext()) AddrLabelExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6372 | ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6373 | } |
| 6374 | |
Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6375 | ExpectedStmt ASTNodeImporter::VisitConstantExpr(ConstantExpr *E) { |
| 6376 | auto Imp = importSeq(E->getSubExpr()); |
| 6377 | if (!Imp) |
| 6378 | return Imp.takeError(); |
| 6379 | |
| 6380 | Expr *ToSubExpr; |
| 6381 | std::tie(ToSubExpr) = *Imp; |
| 6382 | |
Nico Weber | 9f0246d | 2018-11-21 12:47:43 +0000 | [diff] [blame] | 6383 | return new (Importer.getToContext()) ConstantExpr(ToSubExpr); |
Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6384 | } |
| 6385 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6386 | ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| 6387 | auto Imp = importSeq(E->getLParen(), E->getRParen(), E->getSubExpr()); |
| 6388 | if (!Imp) |
| 6389 | return Imp.takeError(); |
| 6390 | |
| 6391 | SourceLocation ToLParen, ToRParen; |
| 6392 | Expr *ToSubExpr; |
| 6393 | std::tie(ToLParen, ToRParen, ToSubExpr) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6394 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6395 | return new (Importer.getToContext()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6396 | ParenExpr(ToLParen, ToRParen, ToSubExpr); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6397 | } |
| 6398 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6399 | ExpectedStmt ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 6400 | SmallVector<Expr *, 4> ToExprs(E->getNumExprs()); |
| 6401 | if (Error Err = ImportContainerChecked(E->exprs(), ToExprs)) |
| 6402 | return std::move(Err); |
| 6403 | |
| 6404 | ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc()); |
| 6405 | if (!ToLParenLocOrErr) |
| 6406 | return ToLParenLocOrErr.takeError(); |
| 6407 | |
| 6408 | ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc()); |
| 6409 | if (!ToRParenLocOrErr) |
| 6410 | return ToRParenLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6411 | |
Bruno Ricci | f49e1ca | 2018-11-20 16:20:40 +0000 | [diff] [blame] | 6412 | return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr, |
| 6413 | ToExprs, *ToRParenLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6414 | } |
| 6415 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6416 | ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| 6417 | auto Imp = importSeq( |
| 6418 | E->getSubStmt(), E->getType(), E->getLParenLoc(), E->getRParenLoc()); |
| 6419 | if (!Imp) |
| 6420 | return Imp.takeError(); |
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 | CompoundStmt *ToSubStmt; |
| 6423 | QualType ToType; |
| 6424 | SourceLocation ToLParenLoc, ToRParenLoc; |
| 6425 | std::tie(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6426 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6427 | return new (Importer.getToContext()) StmtExpr( |
| 6428 | ToSubStmt, ToType, ToLParenLoc, ToRParenLoc); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6429 | } |
| 6430 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6431 | ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| 6432 | auto Imp = importSeq( |
| 6433 | E->getSubExpr(), E->getType(), E->getOperatorLoc()); |
| 6434 | if (!Imp) |
| 6435 | return Imp.takeError(); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6436 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6437 | Expr *ToSubExpr; |
| 6438 | QualType ToType; |
| 6439 | SourceLocation ToOperatorLoc; |
| 6440 | std::tie(ToSubExpr, ToType, ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6441 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6442 | return new (Importer.getToContext()) UnaryOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6443 | ToSubExpr, E->getOpcode(), ToType, E->getValueKind(), E->getObjectKind(), |
| 6444 | ToOperatorLoc, E->canOverflow()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6445 | } |
| 6446 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6447 | ExpectedStmt |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6448 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6449 | auto Imp = importSeq(E->getType(), E->getOperatorLoc(), E->getRParenLoc()); |
| 6450 | if (!Imp) |
| 6451 | return Imp.takeError(); |
| 6452 | |
| 6453 | QualType ToType; |
| 6454 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 6455 | std::tie(ToType, ToOperatorLoc, ToRParenLoc) = *Imp; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6456 | |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6457 | if (E->isArgumentType()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6458 | Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr = |
| 6459 | import(E->getArgumentTypeInfo()); |
| 6460 | if (!ToArgumentTypeInfoOrErr) |
| 6461 | return ToArgumentTypeInfoOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6462 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6463 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6464 | E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc, |
| 6465 | ToRParenLoc); |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6466 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6467 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6468 | ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr()); |
| 6469 | if (!ToArgumentExprOrErr) |
| 6470 | return ToArgumentExprOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6471 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6472 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6473 | E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc); |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6474 | } |
| 6475 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6476 | ExpectedStmt ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| 6477 | auto Imp = importSeq( |
| 6478 | E->getLHS(), E->getRHS(), E->getType(), E->getOperatorLoc()); |
| 6479 | if (!Imp) |
| 6480 | return Imp.takeError(); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6481 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6482 | Expr *ToLHS, *ToRHS; |
| 6483 | QualType ToType; |
| 6484 | SourceLocation ToOperatorLoc; |
| 6485 | std::tie(ToLHS, ToRHS, ToType, ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6486 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6487 | return new (Importer.getToContext()) BinaryOperator( |
| 6488 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6489 | E->getObjectKind(), ToOperatorLoc, E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6490 | } |
| 6491 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6492 | ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| 6493 | auto Imp = importSeq( |
| 6494 | E->getCond(), E->getQuestionLoc(), E->getLHS(), E->getColonLoc(), |
| 6495 | E->getRHS(), E->getType()); |
| 6496 | if (!Imp) |
| 6497 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6498 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6499 | Expr *ToCond, *ToLHS, *ToRHS; |
| 6500 | SourceLocation ToQuestionLoc, ToColonLoc; |
| 6501 | QualType ToType; |
| 6502 | std::tie(ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6503 | |
| 6504 | return new (Importer.getToContext()) ConditionalOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6505 | ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType, |
| 6506 | E->getValueKind(), E->getObjectKind()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6507 | } |
| 6508 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6509 | ExpectedStmt ASTNodeImporter::VisitBinaryConditionalOperator( |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6510 | BinaryConditionalOperator *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6511 | auto Imp = importSeq( |
| 6512 | E->getCommon(), E->getOpaqueValue(), E->getCond(), E->getTrueExpr(), |
| 6513 | E->getFalseExpr(), E->getQuestionLoc(), E->getColonLoc(), E->getType()); |
| 6514 | if (!Imp) |
| 6515 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6516 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6517 | Expr *ToCommon, *ToCond, *ToTrueExpr, *ToFalseExpr; |
| 6518 | OpaqueValueExpr *ToOpaqueValue; |
| 6519 | SourceLocation ToQuestionLoc, ToColonLoc; |
| 6520 | QualType ToType; |
| 6521 | std::tie( |
| 6522 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, ToQuestionLoc, |
| 6523 | ToColonLoc, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6524 | |
| 6525 | return new (Importer.getToContext()) BinaryConditionalOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6526 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, |
| 6527 | ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(), |
| 6528 | E->getObjectKind()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6529 | } |
| 6530 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6531 | ExpectedStmt ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 6532 | auto Imp = importSeq( |
| 6533 | E->getBeginLoc(), E->getQueriedTypeSourceInfo(), |
| 6534 | E->getDimensionExpression(), E->getEndLoc(), E->getType()); |
| 6535 | if (!Imp) |
| 6536 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6537 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6538 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6539 | TypeSourceInfo *ToQueriedTypeSourceInfo; |
| 6540 | Expr *ToDimensionExpression; |
| 6541 | QualType ToType; |
| 6542 | std::tie( |
| 6543 | ToBeginLoc, ToQueriedTypeSourceInfo, ToDimensionExpression, ToEndLoc, |
| 6544 | ToType) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6545 | |
| 6546 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6547 | ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(), |
| 6548 | ToDimensionExpression, ToEndLoc, ToType); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6549 | } |
| 6550 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6551 | ExpectedStmt ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 6552 | auto Imp = importSeq( |
| 6553 | E->getBeginLoc(), E->getQueriedExpression(), E->getEndLoc(), E->getType()); |
| 6554 | if (!Imp) |
| 6555 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6556 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6557 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6558 | Expr *ToQueriedExpression; |
| 6559 | QualType ToType; |
| 6560 | std::tie(ToBeginLoc, ToQueriedExpression, ToEndLoc, ToType) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6561 | |
| 6562 | return new (Importer.getToContext()) ExpressionTraitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6563 | ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(), |
| 6564 | ToEndLoc, ToType); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6565 | } |
| 6566 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6567 | ExpectedStmt ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| 6568 | auto Imp = importSeq( |
| 6569 | E->getLocation(), E->getType(), E->getSourceExpr()); |
| 6570 | if (!Imp) |
| 6571 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6572 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6573 | SourceLocation ToLocation; |
| 6574 | QualType ToType; |
| 6575 | Expr *ToSourceExpr; |
| 6576 | std::tie(ToLocation, ToType, ToSourceExpr) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6577 | |
| 6578 | return new (Importer.getToContext()) OpaqueValueExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6579 | ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6580 | } |
| 6581 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6582 | ExpectedStmt ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 6583 | auto Imp = importSeq( |
| 6584 | E->getLHS(), E->getRHS(), E->getType(), E->getRBracketLoc()); |
| 6585 | if (!Imp) |
| 6586 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6587 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6588 | Expr *ToLHS, *ToRHS; |
| 6589 | SourceLocation ToRBracketLoc; |
| 6590 | QualType ToType; |
| 6591 | std::tie(ToLHS, ToRHS, ToType, ToRBracketLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6592 | |
| 6593 | return new (Importer.getToContext()) ArraySubscriptExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6594 | ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(), |
| 6595 | ToRBracketLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6596 | } |
| 6597 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6598 | ExpectedStmt |
| 6599 | ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 6600 | auto Imp = importSeq( |
| 6601 | E->getLHS(), E->getRHS(), E->getType(), E->getComputationLHSType(), |
| 6602 | E->getComputationResultType(), E->getOperatorLoc()); |
| 6603 | if (!Imp) |
| 6604 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6605 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6606 | Expr *ToLHS, *ToRHS; |
| 6607 | QualType ToType, ToComputationLHSType, ToComputationResultType; |
| 6608 | SourceLocation ToOperatorLoc; |
| 6609 | std::tie(ToLHS, ToRHS, ToType, ToComputationLHSType, ToComputationResultType, |
| 6610 | ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6611 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6612 | return new (Importer.getToContext()) CompoundAssignOperator( |
| 6613 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6614 | E->getObjectKind(), ToComputationLHSType, ToComputationResultType, |
| 6615 | ToOperatorLoc, E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6616 | } |
| 6617 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6618 | Expected<CXXCastPath> |
| 6619 | ASTNodeImporter::ImportCastPath(CastExpr *CE) { |
| 6620 | CXXCastPath Path; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6621 | 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] | 6622 | if (auto SpecOrErr = import(*I)) |
| 6623 | Path.push_back(*SpecOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6624 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6625 | return SpecOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6626 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6627 | return Path; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6628 | } |
| 6629 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6630 | ExpectedStmt ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 6631 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6632 | if (!ToTypeOrErr) |
| 6633 | return ToTypeOrErr.takeError(); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6634 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6635 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6636 | if (!ToSubExprOrErr) |
| 6637 | return ToSubExprOrErr.takeError(); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6638 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6639 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6640 | if (!ToBasePathOrErr) |
| 6641 | return ToBasePathOrErr.takeError(); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6642 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6643 | return ImplicitCastExpr::Create( |
| 6644 | Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr, |
| 6645 | &(*ToBasePathOrErr), E->getValueKind()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6646 | } |
| 6647 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6648 | ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
| 6649 | auto Imp1 = importSeq( |
| 6650 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten()); |
| 6651 | if (!Imp1) |
| 6652 | return Imp1.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6653 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6654 | QualType ToType; |
| 6655 | Expr *ToSubExpr; |
| 6656 | TypeSourceInfo *ToTypeInfoAsWritten; |
| 6657 | std::tie(ToType, ToSubExpr, ToTypeInfoAsWritten) = *Imp1; |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6658 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6659 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6660 | if (!ToBasePathOrErr) |
| 6661 | return ToBasePathOrErr.takeError(); |
| 6662 | CXXCastPath *ToBasePath = &(*ToBasePathOrErr); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6663 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6664 | switch (E->getStmtClass()) { |
| 6665 | case Stmt::CStyleCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6666 | auto *CCE = cast<CStyleCastExpr>(E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6667 | ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc()); |
| 6668 | if (!ToLParenLocOrErr) |
| 6669 | return ToLParenLocOrErr.takeError(); |
| 6670 | ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc()); |
| 6671 | if (!ToRParenLocOrErr) |
| 6672 | return ToRParenLocOrErr.takeError(); |
| 6673 | return CStyleCastExpr::Create( |
| 6674 | Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(), |
| 6675 | ToSubExpr, ToBasePath, ToTypeInfoAsWritten, *ToLParenLocOrErr, |
| 6676 | *ToRParenLocOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6677 | } |
| 6678 | |
| 6679 | case Stmt::CXXFunctionalCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6680 | auto *FCE = cast<CXXFunctionalCastExpr>(E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6681 | ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc()); |
| 6682 | if (!ToLParenLocOrErr) |
| 6683 | return ToLParenLocOrErr.takeError(); |
| 6684 | ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc()); |
| 6685 | if (!ToRParenLocOrErr) |
| 6686 | return ToRParenLocOrErr.takeError(); |
| 6687 | return CXXFunctionalCastExpr::Create( |
| 6688 | Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten, |
| 6689 | E->getCastKind(), ToSubExpr, ToBasePath, *ToLParenLocOrErr, |
| 6690 | *ToRParenLocOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6691 | } |
| 6692 | |
| 6693 | case Stmt::ObjCBridgedCastExprClass: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6694 | auto *OCE = cast<ObjCBridgedCastExpr>(E); |
| 6695 | ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc()); |
| 6696 | if (!ToLParenLocOrErr) |
| 6697 | return ToLParenLocOrErr.takeError(); |
| 6698 | ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc()); |
| 6699 | if (!ToBridgeKeywordLocOrErr) |
| 6700 | return ToBridgeKeywordLocOrErr.takeError(); |
| 6701 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 6702 | *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), |
| 6703 | *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6704 | } |
| 6705 | default: |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6706 | llvm_unreachable("Cast expression of unsupported type!"); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6707 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6708 | } |
| 6709 | } |
| 6710 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6711 | ExpectedStmt ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *E) { |
| 6712 | SmallVector<OffsetOfNode, 4> ToNodes; |
| 6713 | for (int I = 0, N = E->getNumComponents(); I < N; ++I) { |
| 6714 | const OffsetOfNode &FromNode = E->getComponent(I); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6715 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6716 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6717 | if (FromNode.getKind() != OffsetOfNode::Base) { |
| 6718 | auto Imp = importSeq(FromNode.getBeginLoc(), FromNode.getEndLoc()); |
| 6719 | if (!Imp) |
| 6720 | return Imp.takeError(); |
| 6721 | std::tie(ToBeginLoc, ToEndLoc) = *Imp; |
| 6722 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6723 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6724 | switch (FromNode.getKind()) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6725 | case OffsetOfNode::Array: |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6726 | ToNodes.push_back( |
| 6727 | OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6728 | break; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6729 | case OffsetOfNode::Base: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6730 | auto ToBSOrErr = import(FromNode.getBase()); |
| 6731 | if (!ToBSOrErr) |
| 6732 | return ToBSOrErr.takeError(); |
| 6733 | ToNodes.push_back(OffsetOfNode(*ToBSOrErr)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6734 | break; |
| 6735 | } |
| 6736 | case OffsetOfNode::Field: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6737 | auto ToFieldOrErr = import(FromNode.getField()); |
| 6738 | if (!ToFieldOrErr) |
| 6739 | return ToFieldOrErr.takeError(); |
| 6740 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6741 | break; |
| 6742 | } |
| 6743 | case OffsetOfNode::Identifier: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6744 | IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName()); |
| 6745 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6746 | break; |
| 6747 | } |
| 6748 | } |
| 6749 | } |
| 6750 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6751 | SmallVector<Expr *, 4> ToExprs(E->getNumExpressions()); |
| 6752 | for (int I = 0, N = E->getNumExpressions(); I < N; ++I) { |
| 6753 | ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I)); |
| 6754 | if (!ToIndexExprOrErr) |
| 6755 | return ToIndexExprOrErr.takeError(); |
| 6756 | ToExprs[I] = *ToIndexExprOrErr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6757 | } |
| 6758 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6759 | auto Imp = importSeq( |
| 6760 | E->getType(), E->getTypeSourceInfo(), E->getOperatorLoc(), |
| 6761 | E->getRParenLoc()); |
| 6762 | if (!Imp) |
| 6763 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6764 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6765 | QualType ToType; |
| 6766 | TypeSourceInfo *ToTypeSourceInfo; |
| 6767 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 6768 | std::tie(ToType, ToTypeSourceInfo, ToOperatorLoc, ToRParenLoc) = *Imp; |
| 6769 | |
| 6770 | return OffsetOfExpr::Create( |
| 6771 | Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes, |
| 6772 | ToExprs, ToRParenLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6773 | } |
| 6774 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6775 | ExpectedStmt ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 6776 | auto Imp = importSeq( |
| 6777 | E->getType(), E->getOperand(), E->getBeginLoc(), E->getEndLoc()); |
| 6778 | if (!Imp) |
| 6779 | return Imp.takeError(); |
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 | QualType ToType; |
| 6782 | Expr *ToOperand; |
| 6783 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6784 | std::tie(ToType, ToOperand, ToBeginLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6785 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6786 | CanThrowResult ToCanThrow; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6787 | if (E->isValueDependent()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6788 | ToCanThrow = CT_Dependent; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6789 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6790 | ToCanThrow = E->getValue() ? CT_Can : CT_Cannot; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6791 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6792 | return new (Importer.getToContext()) CXXNoexceptExpr( |
| 6793 | ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6794 | } |
| 6795 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6796 | ExpectedStmt ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| 6797 | auto Imp = importSeq(E->getSubExpr(), E->getType(), E->getThrowLoc()); |
| 6798 | if (!Imp) |
| 6799 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6800 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6801 | Expr *ToSubExpr; |
| 6802 | QualType ToType; |
| 6803 | SourceLocation ToThrowLoc; |
| 6804 | std::tie(ToSubExpr, ToType, ToThrowLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6805 | |
| 6806 | return new (Importer.getToContext()) CXXThrowExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6807 | ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6808 | } |
| 6809 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6810 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| 6811 | ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation()); |
| 6812 | if (!ToUsedLocOrErr) |
| 6813 | return ToUsedLocOrErr.takeError(); |
| 6814 | |
| 6815 | auto ToParamOrErr = import(E->getParam()); |
| 6816 | if (!ToParamOrErr) |
| 6817 | return ToParamOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6818 | |
| 6819 | return CXXDefaultArgExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6820 | Importer.getToContext(), *ToUsedLocOrErr, *ToParamOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6821 | } |
| 6822 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6823 | ExpectedStmt |
| 6824 | ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| 6825 | auto Imp = importSeq( |
| 6826 | E->getType(), E->getTypeSourceInfo(), E->getRParenLoc()); |
| 6827 | if (!Imp) |
| 6828 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6829 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6830 | QualType ToType; |
| 6831 | TypeSourceInfo *ToTypeSourceInfo; |
| 6832 | SourceLocation ToRParenLoc; |
| 6833 | std::tie(ToType, ToTypeSourceInfo, ToRParenLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6834 | |
| 6835 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6836 | ToType, ToTypeSourceInfo, ToRParenLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6837 | } |
| 6838 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6839 | ExpectedStmt |
| 6840 | ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 6841 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6842 | if (!ToSubExprOrErr) |
| 6843 | return ToSubExprOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6844 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6845 | auto ToDtorOrErr = import(E->getTemporary()->getDestructor()); |
| 6846 | if (!ToDtorOrErr) |
| 6847 | return ToDtorOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6848 | |
| 6849 | ASTContext &ToCtx = Importer.getToContext(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6850 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr); |
| 6851 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6852 | } |
| 6853 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6854 | ExpectedStmt |
| 6855 | ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { |
| 6856 | auto Imp = importSeq( |
| 6857 | E->getConstructor(), E->getType(), E->getTypeSourceInfo(), |
| 6858 | E->getParenOrBraceRange()); |
| 6859 | if (!Imp) |
| 6860 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6861 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6862 | CXXConstructorDecl *ToConstructor; |
| 6863 | QualType ToType; |
| 6864 | TypeSourceInfo *ToTypeSourceInfo; |
| 6865 | SourceRange ToParenOrBraceRange; |
| 6866 | std::tie(ToConstructor, ToType, ToTypeSourceInfo, ToParenOrBraceRange) = *Imp; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6867 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6868 | SmallVector<Expr *, 8> ToArgs(E->getNumArgs()); |
| 6869 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 6870 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6871 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6872 | return new (Importer.getToContext()) CXXTemporaryObjectExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6873 | Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs, |
| 6874 | ToParenOrBraceRange, E->hadMultipleCandidates(), |
| 6875 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 6876 | E->requiresZeroInitialization()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6877 | } |
| 6878 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6879 | ExpectedStmt |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6880 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6881 | auto Imp = importSeq( |
| 6882 | E->getType(), E->GetTemporaryExpr(), E->getExtendingDecl()); |
| 6883 | if (!Imp) |
| 6884 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6885 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6886 | QualType ToType; |
| 6887 | Expr *ToTemporaryExpr; |
| 6888 | const ValueDecl *ToExtendingDecl; |
| 6889 | std::tie(ToType, ToTemporaryExpr, ToExtendingDecl) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6890 | |
| 6891 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6892 | ToType, ToTemporaryExpr, E->isBoundToLvalueReference()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6893 | |
| 6894 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6895 | ToMTE->setExtendingDecl(ToExtendingDecl, E->getManglingNumber()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6896 | return ToMTE; |
| 6897 | } |
| 6898 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6899 | ExpectedStmt ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { |
| 6900 | auto Imp = importSeq( |
| 6901 | E->getType(), E->getPattern(), E->getEllipsisLoc()); |
| 6902 | if (!Imp) |
| 6903 | return Imp.takeError(); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6904 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6905 | QualType ToType; |
| 6906 | Expr *ToPattern; |
| 6907 | SourceLocation ToEllipsisLoc; |
| 6908 | std::tie(ToType, ToPattern, ToEllipsisLoc) = *Imp; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6909 | |
| 6910 | return new (Importer.getToContext()) PackExpansionExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6911 | ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions()); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6912 | } |
| 6913 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6914 | ExpectedStmt ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { |
| 6915 | auto Imp = importSeq( |
| 6916 | E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc()); |
| 6917 | if (!Imp) |
| 6918 | return Imp.takeError(); |
| 6919 | |
| 6920 | SourceLocation ToOperatorLoc, ToPackLoc, ToRParenLoc; |
| 6921 | NamedDecl *ToPack; |
| 6922 | std::tie(ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc) = *Imp; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6923 | |
| 6924 | Optional<unsigned> Length; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6925 | if (!E->isValueDependent()) |
| 6926 | Length = E->getPackLength(); |
| 6927 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6928 | SmallVector<TemplateArgument, 8> ToPartialArguments; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6929 | if (E->isPartiallySubstituted()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6930 | if (Error Err = ImportTemplateArguments( |
| 6931 | E->getPartialArguments().data(), |
| 6932 | E->getPartialArguments().size(), |
| 6933 | ToPartialArguments)) |
| 6934 | return std::move(Err); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6935 | } |
| 6936 | |
| 6937 | return SizeOfPackExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6938 | Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc, |
| 6939 | Length, ToPartialArguments); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6940 | } |
| 6941 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6942 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6943 | ExpectedStmt ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) { |
| 6944 | auto Imp = importSeq( |
| 6945 | E->getOperatorNew(), E->getOperatorDelete(), E->getTypeIdParens(), |
| 6946 | E->getArraySize(), E->getInitializer(), E->getType(), |
| 6947 | E->getAllocatedTypeSourceInfo(), E->getSourceRange(), |
| 6948 | E->getDirectInitRange()); |
| 6949 | if (!Imp) |
| 6950 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6951 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6952 | FunctionDecl *ToOperatorNew, *ToOperatorDelete; |
| 6953 | SourceRange ToTypeIdParens, ToSourceRange, ToDirectInitRange; |
| 6954 | Expr *ToArraySize, *ToInitializer; |
| 6955 | QualType ToType; |
| 6956 | TypeSourceInfo *ToAllocatedTypeSourceInfo; |
| 6957 | std::tie( |
| 6958 | ToOperatorNew, ToOperatorDelete, ToTypeIdParens, ToArraySize, ToInitializer, |
| 6959 | ToType, ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6960 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6961 | SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs()); |
| 6962 | if (Error Err = |
| 6963 | ImportContainerChecked(E->placement_arguments(), ToPlacementArgs)) |
| 6964 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6965 | |
| 6966 | return new (Importer.getToContext()) CXXNewExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6967 | Importer.getToContext(), E->isGlobalNew(), ToOperatorNew, |
| 6968 | ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(), |
| 6969 | ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(), |
| 6970 | ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange, |
| 6971 | ToDirectInitRange); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6972 | } |
| 6973 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6974 | ExpectedStmt ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 6975 | auto Imp = importSeq( |
| 6976 | E->getType(), E->getOperatorDelete(), E->getArgument(), E->getBeginLoc()); |
| 6977 | if (!Imp) |
| 6978 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6979 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6980 | QualType ToType; |
| 6981 | FunctionDecl *ToOperatorDelete; |
| 6982 | Expr *ToArgument; |
| 6983 | SourceLocation ToBeginLoc; |
| 6984 | std::tie(ToType, ToOperatorDelete, ToArgument, ToBeginLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6985 | |
| 6986 | return new (Importer.getToContext()) CXXDeleteExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6987 | ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(), |
| 6988 | E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument, |
| 6989 | ToBeginLoc); |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6990 | } |
| 6991 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6992 | ExpectedStmt ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| 6993 | auto Imp = importSeq( |
| 6994 | E->getType(), E->getLocation(), E->getConstructor(), |
| 6995 | E->getParenOrBraceRange()); |
| 6996 | if (!Imp) |
| 6997 | return Imp.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6998 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6999 | QualType ToType; |
| 7000 | SourceLocation ToLocation; |
| 7001 | CXXConstructorDecl *ToConstructor; |
| 7002 | SourceRange ToParenOrBraceRange; |
| 7003 | std::tie(ToType, ToLocation, ToConstructor, ToParenOrBraceRange) = *Imp; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7004 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7005 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7006 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7007 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7008 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7009 | return CXXConstructExpr::Create( |
| 7010 | Importer.getToContext(), ToType, ToLocation, ToConstructor, |
| 7011 | E->isElidable(), ToArgs, E->hadMultipleCandidates(), |
| 7012 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 7013 | E->requiresZeroInitialization(), E->getConstructionKind(), |
| 7014 | ToParenOrBraceRange); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7015 | } |
| 7016 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7017 | ExpectedStmt ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *E) { |
| 7018 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7019 | if (!ToSubExprOrErr) |
| 7020 | return ToSubExprOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7021 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7022 | SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects()); |
| 7023 | if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects)) |
| 7024 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7025 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7026 | return ExprWithCleanups::Create( |
| 7027 | Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(), |
| 7028 | ToObjects); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7029 | } |
| 7030 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7031 | ExpectedStmt ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 7032 | auto Imp = importSeq( |
| 7033 | E->getCallee(), E->getType(), E->getRParenLoc()); |
| 7034 | if (!Imp) |
| 7035 | return Imp.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7036 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7037 | Expr *ToCallee; |
| 7038 | QualType ToType; |
| 7039 | SourceLocation ToRParenLoc; |
| 7040 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7041 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7042 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7043 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7044 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7045 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7046 | return new (Importer.getToContext()) CXXMemberCallExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7047 | Importer.getToContext(), ToCallee, ToArgs, ToType, E->getValueKind(), |
| 7048 | ToRParenLoc); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7049 | } |
| 7050 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7051 | ExpectedStmt ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 7052 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7053 | if (!ToTypeOrErr) |
| 7054 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7055 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7056 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7057 | if (!ToLocationOrErr) |
| 7058 | return ToLocationOrErr.takeError(); |
| 7059 | |
| 7060 | return new (Importer.getToContext()) CXXThisExpr( |
| 7061 | *ToLocationOrErr, *ToTypeOrErr, E->isImplicit()); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7062 | } |
| 7063 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7064 | ExpectedStmt ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 7065 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7066 | if (!ToTypeOrErr) |
| 7067 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7068 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7069 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7070 | if (!ToLocationOrErr) |
| 7071 | return ToLocationOrErr.takeError(); |
| 7072 | |
| 7073 | return new (Importer.getToContext()) CXXBoolLiteralExpr( |
| 7074 | E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7075 | } |
| 7076 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7077 | ExpectedStmt ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| 7078 | auto Imp1 = importSeq( |
| 7079 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7080 | E->getTemplateKeywordLoc(), E->getMemberDecl(), E->getType()); |
| 7081 | if (!Imp1) |
| 7082 | return Imp1.takeError(); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7083 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7084 | Expr *ToBase; |
| 7085 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7086 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7087 | ValueDecl *ToMemberDecl; |
| 7088 | QualType ToType; |
| 7089 | std::tie( |
| 7090 | ToBase, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, |
| 7091 | ToType) = *Imp1; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7092 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7093 | auto Imp2 = importSeq( |
| 7094 | E->getFoundDecl().getDecl(), E->getMemberNameInfo().getName(), |
| 7095 | E->getMemberNameInfo().getLoc(), E->getLAngleLoc(), E->getRAngleLoc()); |
| 7096 | if (!Imp2) |
| 7097 | return Imp2.takeError(); |
| 7098 | NamedDecl *ToDecl; |
| 7099 | DeclarationName ToName; |
| 7100 | SourceLocation ToLoc, ToLAngleLoc, ToRAngleLoc; |
| 7101 | std::tie(ToDecl, ToName, ToLoc, ToLAngleLoc, ToRAngleLoc) = *Imp2; |
Peter Szecsi | ef97252 | 2018-05-02 11:52:54 +0000 | [diff] [blame] | 7102 | |
| 7103 | DeclAccessPair ToFoundDecl = |
| 7104 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7105 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7106 | DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7107 | |
| 7108 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7109 | // FIXME: handle template arguments |
| 7110 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7111 | } |
| 7112 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7113 | return MemberExpr::Create( |
| 7114 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, |
| 7115 | ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, ToFoundDecl, |
| 7116 | ToMemberNameInfo, nullptr, ToType, E->getValueKind(), E->getObjectKind()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7117 | } |
| 7118 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7119 | ExpectedStmt |
| 7120 | ASTNodeImporter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { |
| 7121 | auto Imp = importSeq( |
| 7122 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7123 | E->getScopeTypeInfo(), E->getColonColonLoc(), E->getTildeLoc()); |
| 7124 | if (!Imp) |
| 7125 | return Imp.takeError(); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7126 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7127 | Expr *ToBase; |
| 7128 | SourceLocation ToOperatorLoc, ToColonColonLoc, ToTildeLoc; |
| 7129 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7130 | TypeSourceInfo *ToScopeTypeInfo; |
| 7131 | std::tie( |
| 7132 | ToBase, ToOperatorLoc, ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, |
| 7133 | ToTildeLoc) = *Imp; |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7134 | |
| 7135 | PseudoDestructorTypeStorage Storage; |
| 7136 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { |
| 7137 | IdentifierInfo *ToII = Importer.Import(FromII); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7138 | ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc()); |
| 7139 | if (!ToDestroyedTypeLocOrErr) |
| 7140 | return ToDestroyedTypeLocOrErr.takeError(); |
| 7141 | Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7142 | } else { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7143 | if (auto ToTIOrErr = import(E->getDestroyedTypeInfo())) |
| 7144 | Storage = PseudoDestructorTypeStorage(*ToTIOrErr); |
| 7145 | else |
| 7146 | return ToTIOrErr.takeError(); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7147 | } |
| 7148 | |
| 7149 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7150 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, |
| 7151 | ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7152 | } |
| 7153 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7154 | ExpectedStmt ASTNodeImporter::VisitCXXDependentScopeMemberExpr( |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7155 | CXXDependentScopeMemberExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7156 | auto Imp = importSeq( |
| 7157 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7158 | E->getTemplateKeywordLoc(), E->getFirstQualifierFoundInScope()); |
| 7159 | if (!Imp) |
| 7160 | return Imp.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7161 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7162 | QualType ToType; |
| 7163 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7164 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7165 | NamedDecl *ToFirstQualifierFoundInScope; |
| 7166 | std::tie( |
| 7167 | ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7168 | ToFirstQualifierFoundInScope) = *Imp; |
| 7169 | |
| 7170 | Expr *ToBase = nullptr; |
| 7171 | if (!E->isImplicitAccess()) { |
| 7172 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7173 | ToBase = *ToBaseOrErr; |
| 7174 | else |
| 7175 | return ToBaseOrErr.takeError(); |
| 7176 | } |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7177 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7178 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7179 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7180 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7181 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7182 | ToTAInfo)) |
| 7183 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7184 | ResInfo = &ToTAInfo; |
| 7185 | } |
| 7186 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7187 | auto ToMemberNameInfoOrErr = importSeq(E->getMember(), E->getMemberLoc()); |
| 7188 | if (!ToMemberNameInfoOrErr) |
| 7189 | return ToMemberNameInfoOrErr.takeError(); |
| 7190 | DeclarationNameInfo ToMemberNameInfo( |
| 7191 | std::get<0>(*ToMemberNameInfoOrErr), std::get<1>(*ToMemberNameInfoOrErr)); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7192 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7193 | if (Error Err = ImportDeclarationNameLoc( |
| 7194 | E->getMemberNameInfo(), ToMemberNameInfo)) |
| 7195 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7196 | |
| 7197 | return CXXDependentScopeMemberExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7198 | Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc, |
| 7199 | ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope, |
| 7200 | ToMemberNameInfo, ResInfo); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7201 | } |
| 7202 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7203 | ExpectedStmt |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7204 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7205 | auto Imp = importSeq( |
| 7206 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDeclName(), |
| 7207 | E->getExprLoc(), E->getLAngleLoc(), E->getRAngleLoc()); |
| 7208 | if (!Imp) |
| 7209 | return Imp.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7210 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7211 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7212 | SourceLocation ToTemplateKeywordLoc, ToExprLoc, ToLAngleLoc, ToRAngleLoc; |
| 7213 | DeclarationName ToDeclName; |
| 7214 | std::tie( |
| 7215 | ToQualifierLoc, ToTemplateKeywordLoc, ToDeclName, ToExprLoc, |
| 7216 | ToLAngleLoc, ToRAngleLoc) = *Imp; |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7217 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7218 | DeclarationNameInfo ToNameInfo(ToDeclName, ToExprLoc); |
| 7219 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7220 | return std::move(Err); |
| 7221 | |
| 7222 | TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7223 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7224 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7225 | if (Error Err = |
| 7226 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 7227 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7228 | ResInfo = &ToTAInfo; |
| 7229 | } |
| 7230 | |
| 7231 | return DependentScopeDeclRefExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7232 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, |
| 7233 | ToNameInfo, ResInfo); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7234 | } |
| 7235 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7236 | ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr( |
| 7237 | CXXUnresolvedConstructExpr *E) { |
| 7238 | auto Imp = importSeq( |
| 7239 | E->getLParenLoc(), E->getRParenLoc(), E->getTypeSourceInfo()); |
| 7240 | if (!Imp) |
| 7241 | return Imp.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7242 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7243 | SourceLocation ToLParenLoc, ToRParenLoc; |
| 7244 | TypeSourceInfo *ToTypeSourceInfo; |
| 7245 | std::tie(ToLParenLoc, ToRParenLoc, ToTypeSourceInfo) = *Imp; |
| 7246 | |
| 7247 | SmallVector<Expr *, 8> ToArgs(E->arg_size()); |
| 7248 | if (Error Err = |
| 7249 | ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin())) |
| 7250 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7251 | |
| 7252 | return CXXUnresolvedConstructExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7253 | Importer.getToContext(), ToTypeSourceInfo, ToLParenLoc, |
| 7254 | llvm::makeArrayRef(ToArgs), ToRParenLoc); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7255 | } |
| 7256 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7257 | ExpectedStmt |
| 7258 | ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { |
| 7259 | Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass()); |
| 7260 | if (!ToNamingClassOrErr) |
| 7261 | return ToNamingClassOrErr.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7262 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7263 | auto ToQualifierLocOrErr = import(E->getQualifierLoc()); |
| 7264 | if (!ToQualifierLocOrErr) |
| 7265 | return ToQualifierLocOrErr.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7266 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7267 | auto ToNameInfoOrErr = importSeq(E->getName(), E->getNameLoc()); |
| 7268 | if (!ToNameInfoOrErr) |
| 7269 | return ToNameInfoOrErr.takeError(); |
| 7270 | DeclarationNameInfo ToNameInfo( |
| 7271 | std::get<0>(*ToNameInfoOrErr), std::get<1>(*ToNameInfoOrErr)); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7272 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7273 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7274 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7275 | |
| 7276 | UnresolvedSet<8> ToDecls; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7277 | for (auto *D : E->decls()) |
| 7278 | if (auto ToDOrErr = import(D)) |
| 7279 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7280 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7281 | return ToDOrErr.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7282 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7283 | if (E->hasExplicitTemplateArgs() && E->getTemplateKeywordLoc().isValid()) { |
| 7284 | TemplateArgumentListInfo ToTAInfo; |
| 7285 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7286 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7287 | ToTAInfo)) |
| 7288 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7289 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7290 | ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc()); |
| 7291 | if (!ToTemplateKeywordLocOrErr) |
| 7292 | return ToTemplateKeywordLocOrErr.takeError(); |
| 7293 | |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7294 | return UnresolvedLookupExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7295 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7296 | *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo, |
| 7297 | ToDecls.begin(), ToDecls.end()); |
| 7298 | } |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7299 | |
| 7300 | return UnresolvedLookupExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7301 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7302 | ToNameInfo, E->requiresADL(), E->isOverloaded(), ToDecls.begin(), |
| 7303 | ToDecls.end()); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7304 | } |
| 7305 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7306 | ExpectedStmt |
| 7307 | ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { |
| 7308 | auto Imp1 = importSeq( |
| 7309 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7310 | E->getTemplateKeywordLoc()); |
| 7311 | if (!Imp1) |
| 7312 | return Imp1.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7313 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7314 | QualType ToType; |
| 7315 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7316 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7317 | std::tie(ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc) = *Imp1; |
| 7318 | |
| 7319 | auto Imp2 = importSeq(E->getName(), E->getNameLoc()); |
| 7320 | if (!Imp2) |
| 7321 | return Imp2.takeError(); |
| 7322 | DeclarationNameInfo ToNameInfo(std::get<0>(*Imp2), std::get<1>(*Imp2)); |
| 7323 | // Import additional name location/type info. |
| 7324 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7325 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7326 | |
| 7327 | UnresolvedSet<8> ToDecls; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7328 | for (Decl *D : E->decls()) |
| 7329 | if (auto ToDOrErr = import(D)) |
| 7330 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7331 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7332 | return ToDOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7333 | |
| 7334 | TemplateArgumentListInfo ToTAInfo; |
| 7335 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7336 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7337 | if (Error Err = |
| 7338 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 7339 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7340 | ResInfo = &ToTAInfo; |
| 7341 | } |
| 7342 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7343 | Expr *ToBase = nullptr; |
| 7344 | if (!E->isImplicitAccess()) { |
| 7345 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7346 | ToBase = *ToBaseOrErr; |
| 7347 | else |
| 7348 | return ToBaseOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7349 | } |
| 7350 | |
| 7351 | return UnresolvedMemberExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7352 | Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType, |
| 7353 | E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7354 | ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end()); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7355 | } |
| 7356 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7357 | ExpectedStmt ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| 7358 | auto Imp = importSeq(E->getCallee(), E->getType(), E->getRParenLoc()); |
| 7359 | if (!Imp) |
| 7360 | return Imp.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7361 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7362 | Expr *ToCallee; |
| 7363 | QualType ToType; |
| 7364 | SourceLocation ToRParenLoc; |
| 7365 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7366 | |
| 7367 | unsigned NumArgs = E->getNumArgs(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7368 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); |
| 7369 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7370 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7371 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7372 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { |
| 7373 | return new (Importer.getToContext()) CXXOperatorCallExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7374 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType, |
| 7375 | OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures()); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7376 | } |
| 7377 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7378 | return new (Importer.getToContext()) CallExpr( |
| 7379 | Importer.getToContext(), ToCallee, ToArgs, ToType, E->getValueKind(), |
| 7380 | ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7381 | } |
| 7382 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7383 | ExpectedStmt ASTNodeImporter::VisitLambdaExpr(LambdaExpr *E) { |
| 7384 | CXXRecordDecl *FromClass = E->getLambdaClass(); |
| 7385 | auto ToClassOrErr = import(FromClass); |
| 7386 | if (!ToClassOrErr) |
| 7387 | return ToClassOrErr.takeError(); |
| 7388 | CXXRecordDecl *ToClass = *ToClassOrErr; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7389 | |
| 7390 | // NOTE: lambda classes are created with BeingDefined flag set up. |
| 7391 | // It means that ImportDefinition doesn't work for them and we should fill it |
| 7392 | // manually. |
| 7393 | if (ToClass->isBeingDefined()) { |
| 7394 | for (auto FromField : FromClass->fields()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7395 | auto ToFieldOrErr = import(FromField); |
| 7396 | if (!ToFieldOrErr) |
| 7397 | return ToFieldOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7398 | } |
| 7399 | } |
| 7400 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7401 | auto ToCallOpOrErr = import(E->getCallOperator()); |
| 7402 | if (!ToCallOpOrErr) |
| 7403 | return ToCallOpOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7404 | |
| 7405 | ToClass->completeDefinition(); |
| 7406 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7407 | SmallVector<LambdaCapture, 8> ToCaptures; |
| 7408 | ToCaptures.reserve(E->capture_size()); |
| 7409 | for (const auto &FromCapture : E->captures()) { |
| 7410 | if (auto ToCaptureOrErr = import(FromCapture)) |
| 7411 | ToCaptures.push_back(*ToCaptureOrErr); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7412 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7413 | return ToCaptureOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7414 | } |
| 7415 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7416 | SmallVector<Expr *, 8> ToCaptureInits(E->capture_size()); |
| 7417 | if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits)) |
| 7418 | return std::move(Err); |
| 7419 | |
| 7420 | auto Imp = importSeq( |
| 7421 | E->getIntroducerRange(), E->getCaptureDefaultLoc(), E->getEndLoc()); |
| 7422 | if (!Imp) |
| 7423 | return Imp.takeError(); |
| 7424 | |
| 7425 | SourceRange ToIntroducerRange; |
| 7426 | SourceLocation ToCaptureDefaultLoc, ToEndLoc; |
| 7427 | std::tie(ToIntroducerRange, ToCaptureDefaultLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7428 | |
Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 7429 | return LambdaExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7430 | Importer.getToContext(), ToClass, ToIntroducerRange, |
| 7431 | E->getCaptureDefault(), ToCaptureDefaultLoc, ToCaptures, |
| 7432 | E->hasExplicitParameters(), E->hasExplicitResultType(), ToCaptureInits, |
| 7433 | ToEndLoc, E->containsUnexpandedParameterPack()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7434 | } |
| 7435 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7436 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7437 | ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) { |
| 7438 | auto Imp = importSeq(E->getLBraceLoc(), E->getRBraceLoc(), E->getType()); |
| 7439 | if (!Imp) |
| 7440 | return Imp.takeError(); |
| 7441 | |
| 7442 | SourceLocation ToLBraceLoc, ToRBraceLoc; |
| 7443 | QualType ToType; |
| 7444 | std::tie(ToLBraceLoc, ToRBraceLoc, ToType) = *Imp; |
| 7445 | |
| 7446 | SmallVector<Expr *, 4> ToExprs(E->getNumInits()); |
| 7447 | if (Error Err = ImportContainerChecked(E->inits(), ToExprs)) |
| 7448 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7449 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7450 | ASTContext &ToCtx = Importer.getToContext(); |
| 7451 | InitListExpr *To = new (ToCtx) InitListExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7452 | ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc); |
| 7453 | To->setType(ToType); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7454 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7455 | if (E->hasArrayFiller()) { |
| 7456 | if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller())) |
| 7457 | To->setArrayFiller(*ToFillerOrErr); |
| 7458 | else |
| 7459 | return ToFillerOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7460 | } |
| 7461 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7462 | if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) { |
| 7463 | if (auto ToFDOrErr = import(FromFD)) |
| 7464 | To->setInitializedFieldInUnion(*ToFDOrErr); |
| 7465 | else |
| 7466 | return ToFDOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7467 | } |
| 7468 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7469 | if (InitListExpr *SyntForm = E->getSyntacticForm()) { |
| 7470 | if (auto ToSyntFormOrErr = import(SyntForm)) |
| 7471 | To->setSyntacticForm(*ToSyntFormOrErr); |
| 7472 | else |
| 7473 | return ToSyntFormOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7474 | } |
| 7475 | |
Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7476 | // Copy InitListExprBitfields, which are not handled in the ctor of |
| 7477 | // InitListExpr. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7478 | To->sawArrayRangeDesignator(E->hadArrayRangeDesignator()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7479 | |
| 7480 | return To; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7481 | } |
| 7482 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7483 | ExpectedStmt ASTNodeImporter::VisitCXXStdInitializerListExpr( |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7484 | CXXStdInitializerListExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7485 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7486 | if (!ToTypeOrErr) |
| 7487 | return ToTypeOrErr.takeError(); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7488 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7489 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7490 | if (!ToSubExprOrErr) |
| 7491 | return ToSubExprOrErr.takeError(); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7492 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7493 | return new (Importer.getToContext()) CXXStdInitializerListExpr( |
| 7494 | *ToTypeOrErr, *ToSubExprOrErr); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7495 | } |
| 7496 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7497 | ExpectedStmt ASTNodeImporter::VisitCXXInheritedCtorInitExpr( |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7498 | CXXInheritedCtorInitExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7499 | auto Imp = importSeq(E->getLocation(), E->getType(), E->getConstructor()); |
| 7500 | if (!Imp) |
| 7501 | return Imp.takeError(); |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7502 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7503 | SourceLocation ToLocation; |
| 7504 | QualType ToType; |
| 7505 | CXXConstructorDecl *ToConstructor; |
| 7506 | std::tie(ToLocation, ToType, ToConstructor) = *Imp; |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7507 | |
| 7508 | return new (Importer.getToContext()) CXXInheritedCtorInitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7509 | ToLocation, ToType, ToConstructor, E->constructsVBase(), |
| 7510 | E->inheritedFromVBase()); |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7511 | } |
| 7512 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7513 | ExpectedStmt ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 7514 | auto Imp = importSeq(E->getType(), E->getCommonExpr(), E->getSubExpr()); |
| 7515 | if (!Imp) |
| 7516 | return Imp.takeError(); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7517 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7518 | QualType ToType; |
| 7519 | Expr *ToCommonExpr, *ToSubExpr; |
| 7520 | std::tie(ToType, ToCommonExpr, ToSubExpr) = *Imp; |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7521 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7522 | return new (Importer.getToContext()) ArrayInitLoopExpr( |
| 7523 | ToType, ToCommonExpr, ToSubExpr); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7524 | } |
| 7525 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7526 | ExpectedStmt ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 7527 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7528 | if (!ToTypeOrErr) |
| 7529 | return ToTypeOrErr.takeError(); |
| 7530 | return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7531 | } |
| 7532 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7533 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 7534 | ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc()); |
| 7535 | if (!ToBeginLocOrErr) |
| 7536 | return ToBeginLocOrErr.takeError(); |
| 7537 | |
| 7538 | auto ToFieldOrErr = import(E->getField()); |
| 7539 | if (!ToFieldOrErr) |
| 7540 | return ToFieldOrErr.takeError(); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7541 | |
| 7542 | return CXXDefaultInitExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7543 | Importer.getToContext(), *ToBeginLocOrErr, *ToFieldOrErr); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7544 | } |
| 7545 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7546 | ExpectedStmt ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 7547 | auto Imp = importSeq( |
| 7548 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten(), |
| 7549 | E->getOperatorLoc(), E->getRParenLoc(), E->getAngleBrackets()); |
| 7550 | if (!Imp) |
| 7551 | return Imp.takeError(); |
| 7552 | |
| 7553 | QualType ToType; |
| 7554 | Expr *ToSubExpr; |
| 7555 | TypeSourceInfo *ToTypeInfoAsWritten; |
| 7556 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 7557 | SourceRange ToAngleBrackets; |
| 7558 | std::tie( |
| 7559 | ToType, ToSubExpr, ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, |
| 7560 | ToAngleBrackets) = *Imp; |
| 7561 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7562 | ExprValueKind VK = E->getValueKind(); |
| 7563 | CastKind CK = E->getCastKind(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7564 | auto ToBasePathOrErr = ImportCastPath(E); |
| 7565 | if (!ToBasePathOrErr) |
| 7566 | return ToBasePathOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7567 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7568 | if (isa<CXXStaticCastExpr>(E)) { |
| 7569 | return CXXStaticCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7570 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7571 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7572 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 7573 | return CXXDynamicCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7574 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7575 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7576 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 7577 | return CXXReinterpretCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7578 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7579 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Raphael Isemann | c705bb8 | 2018-08-20 16:20:01 +0000 | [diff] [blame] | 7580 | } else if (isa<CXXConstCastExpr>(E)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7581 | return CXXConstCastExpr::Create( |
| 7582 | Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten, |
| 7583 | ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7584 | } else { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7585 | llvm_unreachable("Unknown cast type"); |
| 7586 | return make_error<ImportError>(); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7587 | } |
| 7588 | } |
| 7589 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7590 | ExpectedStmt ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7591 | SubstNonTypeTemplateParmExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7592 | auto Imp = importSeq( |
| 7593 | E->getType(), E->getExprLoc(), E->getParameter(), E->getReplacement()); |
| 7594 | if (!Imp) |
| 7595 | return Imp.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7596 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7597 | QualType ToType; |
| 7598 | SourceLocation ToExprLoc; |
| 7599 | NonTypeTemplateParmDecl *ToParameter; |
| 7600 | Expr *ToReplacement; |
| 7601 | std::tie(ToType, ToExprLoc, ToParameter, ToReplacement) = *Imp; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7602 | |
| 7603 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7604 | ToType, E->getValueKind(), ToExprLoc, ToParameter, ToReplacement); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7605 | } |
| 7606 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7607 | ExpectedStmt ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { |
| 7608 | auto Imp = importSeq( |
| 7609 | E->getType(), E->getBeginLoc(), E->getEndLoc()); |
| 7610 | if (!Imp) |
| 7611 | return Imp.takeError(); |
| 7612 | |
| 7613 | QualType ToType; |
| 7614 | SourceLocation ToBeginLoc, ToEndLoc; |
| 7615 | std::tie(ToType, ToBeginLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7616 | |
| 7617 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7618 | if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs)) |
| 7619 | return std::move(Err); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7620 | |
| 7621 | // According to Sema::BuildTypeTrait(), if E is value-dependent, |
| 7622 | // Value is always false. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7623 | bool ToValue = (E->isValueDependent() ? false : E->getValue()); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7624 | |
| 7625 | return TypeTraitExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7626 | Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs, |
| 7627 | ToEndLoc, ToValue); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7628 | } |
| 7629 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7630 | ExpectedStmt ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { |
| 7631 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7632 | if (!ToTypeOrErr) |
| 7633 | return ToTypeOrErr.takeError(); |
| 7634 | |
| 7635 | auto ToSourceRangeOrErr = import(E->getSourceRange()); |
| 7636 | if (!ToSourceRangeOrErr) |
| 7637 | return ToSourceRangeOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7638 | |
| 7639 | if (E->isTypeOperand()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7640 | if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo())) |
| 7641 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7642 | *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr); |
| 7643 | else |
| 7644 | return ToTSIOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7645 | } |
| 7646 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7647 | ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand()); |
| 7648 | if (!ToExprOperandOrErr) |
| 7649 | return ToExprOperandOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7650 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7651 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7652 | *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7653 | } |
| 7654 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7655 | void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod, |
| 7656 | CXXMethodDecl *FromMethod) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7657 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) { |
| 7658 | if (auto ImportedOrErr = import(FromOverriddenMethod)) |
| 7659 | ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>( |
| 7660 | (*ImportedOrErr)->getCanonicalDecl())); |
| 7661 | else |
| 7662 | consumeError(ImportedOrErr.takeError()); |
| 7663 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7664 | } |
| 7665 | |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7666 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7667 | ASTContext &FromContext, FileManager &FromFileManager, |
| 7668 | bool MinimalImport) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7669 | : ToContext(ToContext), FromContext(FromContext), |
| 7670 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
| 7671 | Minimal(MinimalImport) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7672 | ImportedDecls[FromContext.getTranslationUnitDecl()] |
| 7673 | = ToContext.getTranslationUnitDecl(); |
| 7674 | } |
| 7675 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7676 | ASTImporter::~ASTImporter() = default; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7677 | |
| 7678 | QualType ASTImporter::Import(QualType FromT) { |
| 7679 | if (FromT.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7680 | return {}; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7681 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7682 | const Type *FromTy = FromT.getTypePtr(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7683 | |
| 7684 | // Check whether we've already imported this type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7685 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7686 | = ImportedTypes.find(FromTy); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7687 | if (Pos != ImportedTypes.end()) |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7688 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7689 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7690 | // Import the type |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7691 | ASTNodeImporter Importer(*this); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7692 | ExpectedType ToTOrErr = Importer.Visit(FromTy); |
| 7693 | if (!ToTOrErr) { |
| 7694 | llvm::consumeError(ToTOrErr.takeError()); |
| 7695 | return {}; |
| 7696 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7697 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7698 | // Record the imported type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7699 | ImportedTypes[FromTy] = (*ToTOrErr).getTypePtr(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7700 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7701 | return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7702 | } |
| 7703 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7704 | TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) { |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7705 | if (!FromTSI) |
| 7706 | return FromTSI; |
| 7707 | |
| 7708 | // FIXME: For now we just create a "trivial" type source info based |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 7709 | // 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] | 7710 | QualType T = Import(FromTSI->getType()); |
| 7711 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7712 | return nullptr; |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7713 | |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7714 | return ToContext.getTrivialTypeSourceInfo( |
| 7715 | T, Import(FromTSI->getTypeLoc().getBeginLoc())); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7716 | } |
| 7717 | |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 7718 | Attr *ASTImporter::Import(const Attr *FromAttr) { |
| 7719 | Attr *ToAttr = FromAttr->clone(ToContext); |
| 7720 | ToAttr->setRange(Import(FromAttr->getRange())); |
| 7721 | return ToAttr; |
| 7722 | } |
| 7723 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7724 | Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) { |
| 7725 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD); |
| 7726 | if (Pos != ImportedDecls.end()) { |
| 7727 | Decl *ToD = Pos->second; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7728 | // FIXME: move this call to ImportDeclParts(). |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7729 | if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(FromD, ToD)) |
| 7730 | llvm::consumeError(std::move(Err)); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7731 | return ToD; |
| 7732 | } else { |
| 7733 | return nullptr; |
| 7734 | } |
| 7735 | } |
| 7736 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7737 | Decl *ASTImporter::Import(Decl *FromD) { |
| 7738 | if (!FromD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7739 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7740 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7741 | ASTNodeImporter Importer(*this); |
| 7742 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7743 | // Check whether we've already imported this declaration. |
| 7744 | Decl *ToD = GetAlreadyImportedOrNull(FromD); |
| 7745 | if (ToD) { |
| 7746 | // If FromD has some updated flags after last import, apply it |
| 7747 | updateFlags(FromD, ToD); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7748 | return ToD; |
| 7749 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7750 | |
| 7751 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7752 | ExpectedDecl ToDOrErr = Importer.Visit(FromD); |
| 7753 | if (!ToDOrErr) { |
| 7754 | llvm::consumeError(ToDOrErr.takeError()); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7755 | return nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7756 | } |
| 7757 | ToD = *ToDOrErr; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7758 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7759 | // Notify subclasses. |
| 7760 | Imported(FromD, ToD); |
| 7761 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 7762 | updateFlags(FromD, ToD); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7763 | return ToD; |
| 7764 | } |
| 7765 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7766 | Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7767 | if (!FromDC) |
| 7768 | return FromDC; |
| 7769 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7770 | auto *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC))); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7771 | if (!ToDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7772 | return nullptr; |
| 7773 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7774 | // 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] | 7775 | // need it to have a definition. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7776 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
| 7777 | auto *FromRecord = cast<RecordDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7778 | if (ToRecord->isCompleteDefinition()) { |
| 7779 | // Do nothing. |
| 7780 | } else if (FromRecord->isCompleteDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7781 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7782 | FromRecord, ToRecord, ASTNodeImporter::IDK_Basic)) |
| 7783 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7784 | } else { |
| 7785 | CompleteDecl(ToRecord); |
| 7786 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7787 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 7788 | auto *FromEnum = cast<EnumDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7789 | if (ToEnum->isCompleteDefinition()) { |
| 7790 | // Do nothing. |
| 7791 | } else if (FromEnum->isCompleteDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7792 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7793 | FromEnum, ToEnum, ASTNodeImporter::IDK_Basic)) |
| 7794 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7795 | } else { |
| 7796 | CompleteDecl(ToEnum); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7797 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7798 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 7799 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7800 | if (ToClass->getDefinition()) { |
| 7801 | // Do nothing. |
| 7802 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7803 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7804 | FromDef, ToClass, ASTNodeImporter::IDK_Basic)) |
| 7805 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7806 | } else { |
| 7807 | CompleteDecl(ToClass); |
| 7808 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7809 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 7810 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7811 | if (ToProto->getDefinition()) { |
| 7812 | // Do nothing. |
| 7813 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7814 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7815 | FromDef, ToProto, ASTNodeImporter::IDK_Basic)) |
| 7816 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7817 | } else { |
| 7818 | CompleteDecl(ToProto); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7819 | } |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7820 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7821 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7822 | return ToDC; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7823 | } |
| 7824 | |
| 7825 | Expr *ASTImporter::Import(Expr *FromE) { |
| 7826 | if (!FromE) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7827 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7828 | |
| 7829 | return cast_or_null<Expr>(Import(cast<Stmt>(FromE))); |
| 7830 | } |
| 7831 | |
| 7832 | Stmt *ASTImporter::Import(Stmt *FromS) { |
| 7833 | if (!FromS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7834 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7835 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7836 | // Check whether we've already imported this declaration. |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7837 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 7838 | if (Pos != ImportedStmts.end()) |
| 7839 | return Pos->second; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7840 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7841 | // Import the statement. |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7842 | ASTNodeImporter Importer(*this); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7843 | ExpectedStmt ToSOrErr = Importer.Visit(FromS); |
| 7844 | if (!ToSOrErr) { |
| 7845 | llvm::consumeError(ToSOrErr.takeError()); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7846 | return nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7847 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7848 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7849 | if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) { |
Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7850 | auto *FromE = cast<Expr>(FromS); |
| 7851 | // Copy ExprBitfields, which may not be handled in Expr subclasses |
| 7852 | // constructors. |
| 7853 | ToE->setValueKind(FromE->getValueKind()); |
| 7854 | ToE->setObjectKind(FromE->getObjectKind()); |
| 7855 | ToE->setTypeDependent(FromE->isTypeDependent()); |
| 7856 | ToE->setValueDependent(FromE->isValueDependent()); |
| 7857 | ToE->setInstantiationDependent(FromE->isInstantiationDependent()); |
| 7858 | ToE->setContainsUnexpandedParameterPack( |
| 7859 | FromE->containsUnexpandedParameterPack()); |
| 7860 | } |
| 7861 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7862 | // Record the imported declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7863 | ImportedStmts[FromS] = *ToSOrErr; |
| 7864 | return *ToSOrErr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7865 | } |
| 7866 | |
| 7867 | NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) { |
| 7868 | if (!FromNNS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7869 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7870 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7871 | NestedNameSpecifier *prefix = Import(FromNNS->getPrefix()); |
| 7872 | |
| 7873 | switch (FromNNS->getKind()) { |
| 7874 | case NestedNameSpecifier::Identifier: |
| 7875 | if (IdentifierInfo *II = Import(FromNNS->getAsIdentifier())) { |
| 7876 | return NestedNameSpecifier::Create(ToContext, prefix, II); |
| 7877 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7878 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7879 | |
| 7880 | case NestedNameSpecifier::Namespace: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7881 | if (auto *NS = |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7882 | cast_or_null<NamespaceDecl>(Import(FromNNS->getAsNamespace()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7883 | return NestedNameSpecifier::Create(ToContext, prefix, NS); |
| 7884 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7885 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7886 | |
| 7887 | case NestedNameSpecifier::NamespaceAlias: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7888 | if (auto *NSAD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7889 | cast_or_null<NamespaceAliasDecl>(Import(FromNNS->getAsNamespaceAlias()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7890 | return NestedNameSpecifier::Create(ToContext, prefix, NSAD); |
| 7891 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7892 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7893 | |
| 7894 | case NestedNameSpecifier::Global: |
| 7895 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 7896 | |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7897 | case NestedNameSpecifier::Super: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7898 | if (auto *RD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7899 | cast_or_null<CXXRecordDecl>(Import(FromNNS->getAsRecordDecl()))) { |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7900 | return NestedNameSpecifier::SuperSpecifier(ToContext, RD); |
| 7901 | } |
| 7902 | return nullptr; |
| 7903 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7904 | case NestedNameSpecifier::TypeSpec: |
| 7905 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 7906 | QualType T = Import(QualType(FromNNS->getAsType(), 0u)); |
| 7907 | if (!T.isNull()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7908 | bool bTemplate = FromNNS->getKind() == |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7909 | NestedNameSpecifier::TypeSpecWithTemplate; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7910 | return NestedNameSpecifier::Create(ToContext, prefix, |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7911 | bTemplate, T.getTypePtr()); |
| 7912 | } |
| 7913 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7914 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7915 | } |
| 7916 | |
| 7917 | llvm_unreachable("Invalid nested name specifier kind"); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7918 | } |
| 7919 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 7920 | NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7921 | // Copied from NestedNameSpecifier mostly. |
| 7922 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 7923 | NestedNameSpecifierLoc NNS = FromNNS; |
| 7924 | |
| 7925 | // Push each of the nested-name-specifiers's onto a stack for |
| 7926 | // serialization in reverse order. |
| 7927 | while (NNS) { |
| 7928 | NestedNames.push_back(NNS); |
| 7929 | NNS = NNS.getPrefix(); |
| 7930 | } |
| 7931 | |
| 7932 | NestedNameSpecifierLocBuilder Builder; |
| 7933 | |
| 7934 | while (!NestedNames.empty()) { |
| 7935 | NNS = NestedNames.pop_back_val(); |
| 7936 | NestedNameSpecifier *Spec = Import(NNS.getNestedNameSpecifier()); |
| 7937 | if (!Spec) |
| 7938 | return NestedNameSpecifierLoc(); |
| 7939 | |
| 7940 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
| 7941 | switch (Kind) { |
| 7942 | case NestedNameSpecifier::Identifier: |
| 7943 | Builder.Extend(getToContext(), |
| 7944 | Spec->getAsIdentifier(), |
| 7945 | Import(NNS.getLocalBeginLoc()), |
| 7946 | Import(NNS.getLocalEndLoc())); |
| 7947 | break; |
| 7948 | |
| 7949 | case NestedNameSpecifier::Namespace: |
| 7950 | Builder.Extend(getToContext(), |
| 7951 | Spec->getAsNamespace(), |
| 7952 | Import(NNS.getLocalBeginLoc()), |
| 7953 | Import(NNS.getLocalEndLoc())); |
| 7954 | break; |
| 7955 | |
| 7956 | case NestedNameSpecifier::NamespaceAlias: |
| 7957 | Builder.Extend(getToContext(), |
| 7958 | Spec->getAsNamespaceAlias(), |
| 7959 | Import(NNS.getLocalBeginLoc()), |
| 7960 | Import(NNS.getLocalEndLoc())); |
| 7961 | break; |
| 7962 | |
| 7963 | case NestedNameSpecifier::TypeSpec: |
| 7964 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 7965 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
| 7966 | QualType(Spec->getAsType(), 0)); |
| 7967 | Builder.Extend(getToContext(), |
| 7968 | Import(NNS.getLocalBeginLoc()), |
| 7969 | TSI->getTypeLoc(), |
| 7970 | Import(NNS.getLocalEndLoc())); |
| 7971 | break; |
| 7972 | } |
| 7973 | |
| 7974 | case NestedNameSpecifier::Global: |
| 7975 | Builder.MakeGlobal(getToContext(), Import(NNS.getLocalBeginLoc())); |
| 7976 | break; |
| 7977 | |
| 7978 | case NestedNameSpecifier::Super: { |
| 7979 | SourceRange ToRange = Import(NNS.getSourceRange()); |
| 7980 | Builder.MakeSuper(getToContext(), |
| 7981 | Spec->getAsRecordDecl(), |
| 7982 | ToRange.getBegin(), |
| 7983 | ToRange.getEnd()); |
| 7984 | } |
| 7985 | } |
| 7986 | } |
| 7987 | |
| 7988 | return Builder.getWithLocInContext(getToContext()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 7989 | } |
| 7990 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7991 | TemplateName ASTImporter::Import(TemplateName From) { |
| 7992 | switch (From.getKind()) { |
| 7993 | case TemplateName::Template: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7994 | if (auto *ToTemplate = |
| 7995 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7996 | return TemplateName(ToTemplate); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7997 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7998 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7999 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8000 | case TemplateName::OverloadedTemplate: { |
| 8001 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 8002 | UnresolvedSet<2> ToTemplates; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8003 | for (auto *I : *FromStorage) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8004 | if (auto *To = cast_or_null<NamedDecl>(Import(I))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8005 | ToTemplates.addDecl(To); |
| 8006 | else |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8007 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8008 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8009 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8010 | ToTemplates.end()); |
| 8011 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8012 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8013 | case TemplateName::QualifiedTemplate: { |
| 8014 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
| 8015 | NestedNameSpecifier *Qualifier = Import(QTN->getQualifier()); |
| 8016 | if (!Qualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8017 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8018 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8019 | if (auto *ToTemplate = |
| 8020 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8021 | return ToContext.getQualifiedTemplateName(Qualifier, |
| 8022 | QTN->hasTemplateKeyword(), |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8023 | ToTemplate); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8024 | |
| 8025 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8026 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8027 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8028 | case TemplateName::DependentTemplate: { |
| 8029 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
| 8030 | NestedNameSpecifier *Qualifier = Import(DTN->getQualifier()); |
| 8031 | if (!Qualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8032 | return {}; |
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 | if (DTN->isIdentifier()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8035 | return ToContext.getDependentTemplateName(Qualifier, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8036 | Import(DTN->getIdentifier())); |
| 8037 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8038 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8039 | return ToContext.getDependentTemplateName(Qualifier, DTN->getOperator()); |
| 8040 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8041 | |
| 8042 | case TemplateName::SubstTemplateTemplateParm: { |
| 8043 | SubstTemplateTemplateParmStorage *subst |
| 8044 | = From.getAsSubstTemplateTemplateParm(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8045 | auto *param = |
| 8046 | cast_or_null<TemplateTemplateParmDecl>(Import(subst->getParameter())); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8047 | if (!param) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8048 | return {}; |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8049 | |
| 8050 | TemplateName replacement = Import(subst->getReplacement()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8051 | if (replacement.isNull()) |
| 8052 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8053 | |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8054 | return ToContext.getSubstTemplateTemplateParm(param, replacement); |
| 8055 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8056 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8057 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 8058 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 8059 | = From.getAsSubstTemplateTemplateParmPack(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8060 | auto *Param = |
| 8061 | cast_or_null<TemplateTemplateParmDecl>( |
| 8062 | Import(SubstPack->getParameterPack())); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8063 | if (!Param) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8064 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8065 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8066 | ASTNodeImporter Importer(*this); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8067 | Expected<TemplateArgument> ArgPack |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8068 | = Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8069 | if (!ArgPack) { |
| 8070 | llvm::consumeError(ArgPack.takeError()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8071 | return {}; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8072 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8073 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8074 | return ToContext.getSubstTemplateTemplateParmPack(Param, *ArgPack); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8075 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8076 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8077 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8078 | llvm_unreachable("Invalid template name kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8079 | } |
| 8080 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8081 | SourceLocation ASTImporter::Import(SourceLocation FromLoc) { |
| 8082 | if (FromLoc.isInvalid()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8083 | return {}; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8084 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8085 | SourceManager &FromSM = FromContext.getSourceManager(); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8086 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8087 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
Sean Callanan | 238d897 | 2014-12-10 01:26:39 +0000 | [diff] [blame] | 8088 | FileID ToFileID = Import(Decomposed.first); |
| 8089 | if (ToFileID.isInvalid()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8090 | return {}; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8091 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 8092 | return ToSM.getComposedLoc(ToFileID, Decomposed.second); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8093 | } |
| 8094 | |
| 8095 | SourceRange ASTImporter::Import(SourceRange FromRange) { |
| 8096 | return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd())); |
| 8097 | } |
| 8098 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8099 | FileID ASTImporter::Import(FileID FromID) { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8100 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8101 | if (Pos != ImportedFileIDs.end()) |
| 8102 | return Pos->second; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8103 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8104 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 8105 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 8106 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8107 | |
| 8108 | // Map the FromID to the "to" source manager. |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8109 | FileID ToID; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8110 | if (FromSLoc.isExpansion()) { |
| 8111 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); |
| 8112 | SourceLocation ToSpLoc = Import(FromEx.getSpellingLoc()); |
| 8113 | SourceLocation ToExLocS = Import(FromEx.getExpansionLocStart()); |
| 8114 | unsigned TokenLen = FromSM.getFileIDSize(FromID); |
| 8115 | SourceLocation MLoc; |
| 8116 | if (FromEx.isMacroArgExpansion()) { |
| 8117 | MLoc = ToSM.createMacroArgExpansionLoc(ToSpLoc, ToExLocS, TokenLen); |
| 8118 | } else { |
| 8119 | SourceLocation ToExLocE = Import(FromEx.getExpansionLocEnd()); |
| 8120 | MLoc = ToSM.createExpansionLoc(ToSpLoc, ToExLocS, ToExLocE, TokenLen, |
| 8121 | FromEx.isExpansionTokenRange()); |
| 8122 | } |
| 8123 | ToID = ToSM.getFileID(MLoc); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8124 | } else { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8125 | // Include location of this file. |
| 8126 | SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); |
| 8127 | |
| 8128 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
| 8129 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
| 8130 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 8131 | // disk again |
| 8132 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 8133 | // than mmap the files several times. |
| 8134 | const FileEntry *Entry = |
| 8135 | ToFileManager.getFile(Cache->OrigEntry->getName()); |
| 8136 | if (!Entry) |
| 8137 | return {}; |
| 8138 | ToID = ToSM.createFileID(Entry, ToIncludeLoc, |
| 8139 | FromSLoc.getFile().getFileCharacteristic()); |
| 8140 | } else { |
| 8141 | // FIXME: We want to re-use the existing MemoryBuffer! |
| 8142 | const llvm::MemoryBuffer *FromBuf = |
| 8143 | Cache->getBuffer(FromContext.getDiagnostics(), FromSM); |
| 8144 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = |
| 8145 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
| 8146 | FromBuf->getBufferIdentifier()); |
| 8147 | ToID = ToSM.createFileID(std::move(ToBuf), |
| 8148 | FromSLoc.getFile().getFileCharacteristic()); |
| 8149 | } |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8150 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8151 | |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 8152 | ImportedFileIDs[FromID] = ToID; |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8153 | return ToID; |
| 8154 | } |
| 8155 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8156 | CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) { |
| 8157 | Expr *ToExpr = Import(From->getInit()); |
| 8158 | if (!ToExpr && From->getInit()) |
| 8159 | return nullptr; |
| 8160 | |
| 8161 | if (From->isBaseInitializer()) { |
| 8162 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 8163 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 8164 | return nullptr; |
| 8165 | |
| 8166 | return new (ToContext) CXXCtorInitializer( |
| 8167 | ToContext, ToTInfo, From->isBaseVirtual(), Import(From->getLParenLoc()), |
| 8168 | ToExpr, Import(From->getRParenLoc()), |
| 8169 | From->isPackExpansion() ? Import(From->getEllipsisLoc()) |
| 8170 | : SourceLocation()); |
| 8171 | } else if (From->isMemberInitializer()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8172 | auto *ToField = cast_or_null<FieldDecl>(Import(From->getMember())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8173 | if (!ToField && From->getMember()) |
| 8174 | return nullptr; |
| 8175 | |
| 8176 | return new (ToContext) CXXCtorInitializer( |
| 8177 | ToContext, ToField, Import(From->getMemberLocation()), |
| 8178 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 8179 | } else if (From->isIndirectMemberInitializer()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8180 | auto *ToIField = cast_or_null<IndirectFieldDecl>( |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8181 | Import(From->getIndirectMember())); |
| 8182 | if (!ToIField && From->getIndirectMember()) |
| 8183 | return nullptr; |
| 8184 | |
| 8185 | return new (ToContext) CXXCtorInitializer( |
| 8186 | ToContext, ToIField, Import(From->getMemberLocation()), |
| 8187 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 8188 | } else if (From->isDelegatingInitializer()) { |
| 8189 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 8190 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 8191 | return nullptr; |
| 8192 | |
| 8193 | return new (ToContext) |
| 8194 | CXXCtorInitializer(ToContext, ToTInfo, Import(From->getLParenLoc()), |
| 8195 | ToExpr, Import(From->getRParenLoc())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8196 | } else { |
| 8197 | return nullptr; |
| 8198 | } |
| 8199 | } |
| 8200 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8201 | CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { |
| 8202 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 8203 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 8204 | return Pos->second; |
| 8205 | |
| 8206 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
| 8207 | Import(BaseSpec->getSourceRange()), |
| 8208 | BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 8209 | BaseSpec->getAccessSpecifierAsWritten(), |
| 8210 | Import(BaseSpec->getTypeSourceInfo()), |
| 8211 | Import(BaseSpec->getEllipsisLoc())); |
| 8212 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 8213 | return Imported; |
| 8214 | } |
| 8215 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8216 | Error ASTImporter::ImportDefinition_New(Decl *From) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8217 | Decl *To = Import(From); |
| 8218 | if (!To) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8219 | return llvm::make_error<ImportError>(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8220 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8221 | if (auto *FromDC = cast<DeclContext>(From)) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8222 | ASTNodeImporter Importer(*this); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8223 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8224 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 8225 | if (!ToRecord->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8226 | return Importer.ImportDefinition( |
| 8227 | cast<RecordDecl>(FromDC), ToRecord, |
| 8228 | ASTNodeImporter::IDK_Everything); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8229 | } |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 8230 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8231 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8232 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8233 | if (!ToEnum->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8234 | return Importer.ImportDefinition( |
| 8235 | cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8236 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8237 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8238 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8239 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 8240 | if (!ToIFace->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8241 | return Importer.ImportDefinition( |
| 8242 | cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
| 8243 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 8244 | } |
| 8245 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8246 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8247 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 8248 | if (!ToProto->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8249 | return Importer.ImportDefinition( |
| 8250 | cast<ObjCProtocolDecl>(FromDC), ToProto, |
| 8251 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 8252 | } |
| 8253 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8254 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8255 | return Importer.ImportDeclContext(FromDC, true); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8256 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8257 | |
| 8258 | return Error::success(); |
| 8259 | } |
| 8260 | |
| 8261 | void ASTImporter::ImportDefinition(Decl *From) { |
| 8262 | Error Err = ImportDefinition_New(From); |
| 8263 | llvm::consumeError(std::move(Err)); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8264 | } |
| 8265 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8266 | DeclarationName ASTImporter::Import(DeclarationName FromName) { |
| 8267 | if (!FromName) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8268 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8269 | |
| 8270 | switch (FromName.getNameKind()) { |
| 8271 | case DeclarationName::Identifier: |
| 8272 | return Import(FromName.getAsIdentifierInfo()); |
| 8273 | |
| 8274 | case DeclarationName::ObjCZeroArgSelector: |
| 8275 | case DeclarationName::ObjCOneArgSelector: |
| 8276 | case DeclarationName::ObjCMultiArgSelector: |
| 8277 | return Import(FromName.getObjCSelector()); |
| 8278 | |
| 8279 | case DeclarationName::CXXConstructorName: { |
| 8280 | QualType T = Import(FromName.getCXXNameType()); |
| 8281 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8282 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8283 | |
| 8284 | return ToContext.DeclarationNames.getCXXConstructorName( |
| 8285 | ToContext.getCanonicalType(T)); |
| 8286 | } |
| 8287 | |
| 8288 | case DeclarationName::CXXDestructorName: { |
| 8289 | QualType T = Import(FromName.getCXXNameType()); |
| 8290 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8291 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8292 | |
| 8293 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 8294 | ToContext.getCanonicalType(T)); |
| 8295 | } |
| 8296 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8297 | case DeclarationName::CXXDeductionGuideName: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8298 | auto *Template = cast_or_null<TemplateDecl>( |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8299 | Import(FromName.getCXXDeductionGuideTemplate())); |
| 8300 | if (!Template) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8301 | return {}; |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8302 | return ToContext.DeclarationNames.getCXXDeductionGuideName(Template); |
| 8303 | } |
| 8304 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8305 | case DeclarationName::CXXConversionFunctionName: { |
| 8306 | QualType T = Import(FromName.getCXXNameType()); |
| 8307 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8308 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8309 | |
| 8310 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 8311 | ToContext.getCanonicalType(T)); |
| 8312 | } |
| 8313 | |
| 8314 | case DeclarationName::CXXOperatorName: |
| 8315 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 8316 | FromName.getCXXOverloadedOperator()); |
| 8317 | |
| 8318 | case DeclarationName::CXXLiteralOperatorName: |
| 8319 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
| 8320 | Import(FromName.getCXXLiteralIdentifier())); |
| 8321 | |
| 8322 | case DeclarationName::CXXUsingDirective: |
| 8323 | // FIXME: STATICS! |
| 8324 | return DeclarationName::getUsingDirectiveName(); |
| 8325 | } |
| 8326 | |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 8327 | llvm_unreachable("Invalid DeclarationName Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8328 | } |
| 8329 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8330 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8331 | if (!FromId) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8332 | return nullptr; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8333 | |
Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 8334 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 8335 | |
| 8336 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 8337 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 8338 | |
| 8339 | return ToId; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8340 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8341 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8342 | Selector ASTImporter::Import(Selector FromSel) { |
| 8343 | if (FromSel.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8344 | return {}; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8345 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 8346 | SmallVector<IdentifierInfo *, 4> Idents; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8347 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 8348 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 8349 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 8350 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 8351 | } |
| 8352 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8353 | DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, |
| 8354 | DeclContext *DC, |
| 8355 | unsigned IDNS, |
| 8356 | NamedDecl **Decls, |
| 8357 | unsigned NumDecls) { |
| 8358 | return Name; |
| 8359 | } |
| 8360 | |
| 8361 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8362 | if (LastDiagFromFrom) |
| 8363 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8364 | FromContext.getDiagnostics()); |
| 8365 | LastDiagFromFrom = false; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8366 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8367 | } |
| 8368 | |
| 8369 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8370 | if (!LastDiagFromFrom) |
| 8371 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8372 | ToContext.getDiagnostics()); |
| 8373 | LastDiagFromFrom = true; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8374 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8375 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8376 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8377 | void ASTImporter::CompleteDecl (Decl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8378 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8379 | if (!ID->getDefinition()) |
| 8380 | ID->startDefinition(); |
| 8381 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8382 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8383 | if (!PD->getDefinition()) |
| 8384 | PD->startDefinition(); |
| 8385 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8386 | else if (auto *TD = dyn_cast<TagDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8387 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 8388 | TD->startDefinition(); |
| 8389 | TD->setCompleteDefinition(true); |
| 8390 | } |
| 8391 | } |
| 8392 | else { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8393 | assert(0 && "CompleteDecl called on a Decl that can't be completed"); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8394 | } |
| 8395 | } |
| 8396 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8397 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { |
| 8398 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); |
| 8399 | assert((Pos == ImportedDecls.end() || Pos->second == To) && |
| 8400 | "Try to import an already imported Decl"); |
| 8401 | if (Pos != ImportedDecls.end()) |
| 8402 | return Pos->second; |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8403 | ImportedDecls[From] = To; |
| 8404 | return To; |
Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 8405 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8406 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8407 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 8408 | bool Complain) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 8409 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8410 | = ImportedTypes.find(From.getTypePtr()); |
| 8411 | if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To)) |
| 8412 | return true; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 8413 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8414 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8415 | getStructuralEquivalenceKind(*this), false, |
| 8416 | Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 8417 | return Ctx.IsEquivalent(From, To); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8418 | } |