Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1 | //===- ASTImporter.cpp - Importing ASTs from other Contexts ---------------===// |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the ASTImporter class which imports AST nodes from one |
| 11 | // context into another context. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 14 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTImporter.h" |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTDiagnostic.h" |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 18 | #include "clang/AST/ASTStructuralEquivalence.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 19 | #include "clang/AST/Attr.h" |
| 20 | #include "clang/AST/Decl.h" |
| 21 | #include "clang/AST/DeclAccessPair.h" |
| 22 | #include "clang/AST/DeclBase.h" |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclCXX.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 24 | #include "clang/AST/DeclFriend.h" |
| 25 | #include "clang/AST/DeclGroup.h" |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 26 | #include "clang/AST/DeclObjC.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 27 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 28 | #include "clang/AST/DeclVisitor.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 29 | #include "clang/AST/DeclarationName.h" |
| 30 | #include "clang/AST/Expr.h" |
| 31 | #include "clang/AST/ExprCXX.h" |
| 32 | #include "clang/AST/ExprObjC.h" |
| 33 | #include "clang/AST/ExternalASTSource.h" |
| 34 | #include "clang/AST/LambdaCapture.h" |
| 35 | #include "clang/AST/NestedNameSpecifier.h" |
| 36 | #include "clang/AST/OperationKinds.h" |
| 37 | #include "clang/AST/Stmt.h" |
| 38 | #include "clang/AST/StmtCXX.h" |
| 39 | #include "clang/AST/StmtObjC.h" |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 40 | #include "clang/AST/StmtVisitor.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 41 | #include "clang/AST/TemplateBase.h" |
| 42 | #include "clang/AST/TemplateName.h" |
| 43 | #include "clang/AST/Type.h" |
| 44 | #include "clang/AST/TypeLoc.h" |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 45 | #include "clang/AST/TypeVisitor.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 46 | #include "clang/AST/UnresolvedSet.h" |
| 47 | #include "clang/Basic/ExceptionSpecificationType.h" |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 48 | #include "clang/Basic/FileManager.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 49 | #include "clang/Basic/IdentifierTable.h" |
| 50 | #include "clang/Basic/LLVM.h" |
| 51 | #include "clang/Basic/LangOptions.h" |
| 52 | #include "clang/Basic/SourceLocation.h" |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 53 | #include "clang/Basic/SourceManager.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 54 | #include "clang/Basic/Specifiers.h" |
| 55 | #include "llvm/ADT/APSInt.h" |
| 56 | #include "llvm/ADT/ArrayRef.h" |
| 57 | #include "llvm/ADT/DenseMap.h" |
| 58 | #include "llvm/ADT/None.h" |
| 59 | #include "llvm/ADT/Optional.h" |
| 60 | #include "llvm/ADT/STLExtras.h" |
| 61 | #include "llvm/ADT/SmallVector.h" |
| 62 | #include "llvm/Support/Casting.h" |
| 63 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 64 | #include "llvm/Support/MemoryBuffer.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 65 | #include <algorithm> |
| 66 | #include <cassert> |
| 67 | #include <cstddef> |
| 68 | #include <memory> |
| 69 | #include <type_traits> |
| 70 | #include <utility> |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 71 | |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 72 | namespace clang { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 73 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 74 | using llvm::make_error; |
| 75 | using llvm::Error; |
| 76 | using llvm::Expected; |
| 77 | using ExpectedType = llvm::Expected<QualType>; |
| 78 | using ExpectedStmt = llvm::Expected<Stmt *>; |
| 79 | using ExpectedExpr = llvm::Expected<Expr *>; |
| 80 | using ExpectedDecl = llvm::Expected<Decl *>; |
| 81 | using ExpectedSLoc = llvm::Expected<SourceLocation>; |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 82 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 83 | std::string ImportError::toString() const { |
| 84 | // FIXME: Improve error texts. |
| 85 | switch (Error) { |
| 86 | case NameConflict: |
| 87 | return "NameConflict"; |
| 88 | case UnsupportedConstruct: |
| 89 | return "UnsupportedConstruct"; |
| 90 | case Unknown: |
| 91 | return "Unknown error"; |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 92 | } |
Balazs Keri | 2a13d66 | 2018-10-19 15:16:51 +0000 | [diff] [blame] | 93 | llvm_unreachable("Invalid error code."); |
| 94 | return "Invalid error code."; |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 97 | void ImportError::log(raw_ostream &OS) const { |
| 98 | OS << toString(); |
| 99 | } |
| 100 | |
| 101 | std::error_code ImportError::convertToErrorCode() const { |
| 102 | llvm_unreachable("Function not implemented."); |
| 103 | } |
| 104 | |
| 105 | char ImportError::ID; |
| 106 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 107 | template <class T> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 108 | SmallVector<Decl *, 2> |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 109 | getCanonicalForwardRedeclChain(Redeclarable<T>* D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 110 | SmallVector<Decl *, 2> Redecls; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 111 | for (auto *R : D->getFirstDecl()->redecls()) { |
| 112 | if (R != D->getFirstDecl()) |
| 113 | Redecls.push_back(R); |
| 114 | } |
| 115 | Redecls.push_back(D->getFirstDecl()); |
| 116 | std::reverse(Redecls.begin(), Redecls.end()); |
| 117 | return Redecls; |
| 118 | } |
| 119 | |
| 120 | SmallVector<Decl*, 2> getCanonicalForwardRedeclChain(Decl* D) { |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 121 | if (auto *FD = dyn_cast<FunctionDecl>(D)) |
| 122 | return getCanonicalForwardRedeclChain<FunctionDecl>(FD); |
| 123 | if (auto *VD = dyn_cast<VarDecl>(D)) |
| 124 | return getCanonicalForwardRedeclChain<VarDecl>(VD); |
| 125 | llvm_unreachable("Bad declaration kind"); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 126 | } |
| 127 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 128 | void updateFlags(const Decl *From, Decl *To) { |
| 129 | // Check if some flags or attrs are new in 'From' and copy into 'To'. |
| 130 | // FIXME: Other flags or attrs? |
| 131 | if (From->isUsed(false) && !To->isUsed(false)) |
| 132 | To->setIsUsed(); |
| 133 | } |
| 134 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 135 | Optional<unsigned> ASTImporter::getFieldIndex(Decl *F) { |
| 136 | assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) && |
| 137 | "Try to get field index for non-field."); |
| 138 | |
| 139 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); |
| 140 | if (!Owner) |
| 141 | return None; |
| 142 | |
| 143 | unsigned Index = 0; |
| 144 | for (const auto *D : Owner->decls()) { |
| 145 | if (D == F) |
| 146 | return Index; |
| 147 | |
| 148 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) |
| 149 | ++Index; |
| 150 | } |
| 151 | |
| 152 | llvm_unreachable("Field was not found in its parent context."); |
| 153 | |
| 154 | return None; |
| 155 | } |
| 156 | |
| 157 | // FIXME: Temporary until every import returns Expected. |
| 158 | template <> |
| 159 | LLVM_NODISCARD Error |
| 160 | ASTImporter::importInto(SourceLocation &To, const SourceLocation &From) { |
| 161 | To = Import(From); |
| 162 | if (From.isValid() && To.isInvalid()) |
| 163 | return llvm::make_error<ImportError>(); |
| 164 | return Error::success(); |
| 165 | } |
| 166 | // FIXME: Temporary until every import returns Expected. |
| 167 | template <> |
| 168 | LLVM_NODISCARD Error |
| 169 | ASTImporter::importInto(QualType &To, const QualType &From) { |
| 170 | To = Import(From); |
| 171 | if (!From.isNull() && To.isNull()) |
| 172 | return llvm::make_error<ImportError>(); |
| 173 | return Error::success(); |
| 174 | } |
| 175 | |
| 176 | class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>, |
| 177 | public DeclVisitor<ASTNodeImporter, ExpectedDecl>, |
| 178 | public StmtVisitor<ASTNodeImporter, ExpectedStmt> { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 179 | ASTImporter &Importer; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 180 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 181 | // Use this instead of Importer.importInto . |
| 182 | template <typename ImportT> |
| 183 | LLVM_NODISCARD Error importInto(ImportT &To, const ImportT &From) { |
| 184 | return Importer.importInto(To, From); |
| 185 | } |
| 186 | |
| 187 | // Use this to import pointers of specific type. |
| 188 | template <typename ImportT> |
| 189 | LLVM_NODISCARD Error importInto(ImportT *&To, ImportT *From) { |
| 190 | auto ToI = Importer.Import(From); |
| 191 | if (!ToI && From) |
| 192 | return make_error<ImportError>(); |
| 193 | To = cast_or_null<ImportT>(ToI); |
| 194 | return Error::success(); |
| 195 | // FIXME: This should be the final code. |
| 196 | //auto ToOrErr = Importer.Import(From); |
| 197 | //if (ToOrErr) { |
| 198 | // To = cast_or_null<ImportT>(*ToOrErr); |
| 199 | //} |
| 200 | //return ToOrErr.takeError(); |
| 201 | } |
| 202 | |
| 203 | // Call the import function of ASTImporter for a baseclass of type `T` and |
| 204 | // cast the return value to `T`. |
| 205 | template <typename T> |
| 206 | Expected<T *> import(T *From) { |
| 207 | auto *To = Importer.Import(From); |
| 208 | if (!To && From) |
| 209 | return make_error<ImportError>(); |
| 210 | return cast_or_null<T>(To); |
| 211 | // FIXME: This should be the final code. |
| 212 | //auto ToOrErr = Importer.Import(From); |
| 213 | //if (!ToOrErr) |
| 214 | // return ToOrErr.takeError(); |
| 215 | //return cast_or_null<T>(*ToOrErr); |
| 216 | } |
| 217 | |
| 218 | template <typename T> |
| 219 | Expected<T *> import(const T *From) { |
| 220 | return import(const_cast<T *>(From)); |
| 221 | } |
| 222 | |
| 223 | // Call the import function of ASTImporter for type `T`. |
| 224 | template <typename T> |
| 225 | Expected<T> import(const T &From) { |
| 226 | T To = Importer.Import(From); |
| 227 | T DefaultT; |
| 228 | if (To == DefaultT && !(From == DefaultT)) |
| 229 | return make_error<ImportError>(); |
| 230 | return To; |
| 231 | // FIXME: This should be the final code. |
| 232 | //return Importer.Import(From); |
| 233 | } |
| 234 | |
| 235 | template <class T> |
| 236 | Expected<std::tuple<T>> |
| 237 | importSeq(const T &From) { |
| 238 | Expected<T> ToOrErr = import(From); |
| 239 | if (!ToOrErr) |
| 240 | return ToOrErr.takeError(); |
| 241 | return std::make_tuple<T>(std::move(*ToOrErr)); |
| 242 | } |
| 243 | |
| 244 | // Import multiple objects with a single function call. |
| 245 | // This should work for every type for which a variant of `import` exists. |
| 246 | // The arguments are processed from left to right and import is stopped on |
| 247 | // first error. |
| 248 | template <class THead, class... TTail> |
| 249 | Expected<std::tuple<THead, TTail...>> |
| 250 | importSeq(const THead &FromHead, const TTail &...FromTail) { |
| 251 | Expected<std::tuple<THead>> ToHeadOrErr = importSeq(FromHead); |
| 252 | if (!ToHeadOrErr) |
| 253 | return ToHeadOrErr.takeError(); |
| 254 | Expected<std::tuple<TTail...>> ToTailOrErr = importSeq(FromTail...); |
| 255 | if (!ToTailOrErr) |
| 256 | return ToTailOrErr.takeError(); |
| 257 | return std::tuple_cat(*ToHeadOrErr, *ToTailOrErr); |
| 258 | } |
| 259 | |
| 260 | // Wrapper for an overload set. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 261 | template <typename ToDeclT> struct CallOverloadedCreateFun { |
| 262 | template <typename... Args> |
| 263 | auto operator()(Args &&... args) |
| 264 | -> decltype(ToDeclT::Create(std::forward<Args>(args)...)) { |
| 265 | return ToDeclT::Create(std::forward<Args>(args)...); |
| 266 | } |
| 267 | }; |
| 268 | |
| 269 | // Always use these functions to create a Decl during import. There are |
| 270 | // certain tasks which must be done after the Decl was created, e.g. we |
| 271 | // must immediately register that as an imported Decl. The parameter `ToD` |
| 272 | // will be set to the newly created Decl or if had been imported before |
| 273 | // then to the already imported Decl. Returns a bool value set to true if |
| 274 | // the `FromD` had been imported before. |
| 275 | template <typename ToDeclT, typename FromDeclT, typename... Args> |
| 276 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, |
| 277 | Args &&... args) { |
| 278 | // There may be several overloads of ToDeclT::Create. We must make sure |
| 279 | // to call the one which would be chosen by the arguments, thus we use a |
| 280 | // wrapper for the overload set. |
| 281 | CallOverloadedCreateFun<ToDeclT> OC; |
| 282 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, |
| 283 | std::forward<Args>(args)...); |
| 284 | } |
| 285 | // Use this overload if a special Type is needed to be created. E.g if we |
| 286 | // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl` |
| 287 | // then: |
| 288 | // TypedefNameDecl *ToTypedef; |
| 289 | // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...); |
| 290 | template <typename NewDeclT, typename ToDeclT, typename FromDeclT, |
| 291 | typename... Args> |
| 292 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, |
| 293 | Args &&... args) { |
| 294 | CallOverloadedCreateFun<NewDeclT> OC; |
| 295 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, |
| 296 | std::forward<Args>(args)...); |
| 297 | } |
| 298 | // Use this version if a special create function must be |
| 299 | // used, e.g. CXXRecordDecl::CreateLambda . |
| 300 | template <typename ToDeclT, typename CreateFunT, typename FromDeclT, |
| 301 | typename... Args> |
| 302 | LLVM_NODISCARD bool |
| 303 | GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun, |
| 304 | FromDeclT *FromD, Args &&... args) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 305 | // FIXME: This code is needed later. |
| 306 | //if (Importer.getImportDeclErrorIfAny(FromD)) { |
| 307 | // ToD = nullptr; |
| 308 | // return true; // Already imported but with error. |
| 309 | //} |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 310 | ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD)); |
| 311 | if (ToD) |
| 312 | return true; // Already imported. |
| 313 | ToD = CreateFun(std::forward<Args>(args)...); |
| 314 | InitializeImportedDecl(FromD, ToD); |
| 315 | return false; // A new Decl is created. |
| 316 | } |
| 317 | |
| 318 | void InitializeImportedDecl(Decl *FromD, Decl *ToD) { |
| 319 | Importer.MapImported(FromD, ToD); |
| 320 | ToD->IdentifierNamespace = FromD->IdentifierNamespace; |
| 321 | if (FromD->hasAttrs()) |
| 322 | for (const Attr *FromAttr : FromD->getAttrs()) |
| 323 | ToD->addAttr(Importer.Import(FromAttr)); |
| 324 | if (FromD->isUsed()) |
| 325 | ToD->setIsUsed(); |
| 326 | if (FromD->isImplicit()) |
| 327 | ToD->setImplicit(); |
| 328 | } |
| 329 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 330 | public: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 331 | explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {} |
Gabor Marton | 344b099 | 2018-05-16 11:48:11 +0000 | [diff] [blame] | 332 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 333 | using TypeVisitor<ASTNodeImporter, ExpectedType>::Visit; |
| 334 | using DeclVisitor<ASTNodeImporter, ExpectedDecl>::Visit; |
| 335 | using StmtVisitor<ASTNodeImporter, ExpectedStmt>::Visit; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 336 | |
| 337 | // Importing types |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 338 | ExpectedType VisitType(const Type *T); |
| 339 | ExpectedType VisitAtomicType(const AtomicType *T); |
| 340 | ExpectedType VisitBuiltinType(const BuiltinType *T); |
| 341 | ExpectedType VisitDecayedType(const DecayedType *T); |
| 342 | ExpectedType VisitComplexType(const ComplexType *T); |
| 343 | ExpectedType VisitPointerType(const PointerType *T); |
| 344 | ExpectedType VisitBlockPointerType(const BlockPointerType *T); |
| 345 | ExpectedType VisitLValueReferenceType(const LValueReferenceType *T); |
| 346 | ExpectedType VisitRValueReferenceType(const RValueReferenceType *T); |
| 347 | ExpectedType VisitMemberPointerType(const MemberPointerType *T); |
| 348 | ExpectedType VisitConstantArrayType(const ConstantArrayType *T); |
| 349 | ExpectedType VisitIncompleteArrayType(const IncompleteArrayType *T); |
| 350 | ExpectedType VisitVariableArrayType(const VariableArrayType *T); |
| 351 | ExpectedType VisitDependentSizedArrayType(const DependentSizedArrayType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 352 | // FIXME: DependentSizedExtVectorType |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 353 | ExpectedType VisitVectorType(const VectorType *T); |
| 354 | ExpectedType VisitExtVectorType(const ExtVectorType *T); |
| 355 | ExpectedType VisitFunctionNoProtoType(const FunctionNoProtoType *T); |
| 356 | ExpectedType VisitFunctionProtoType(const FunctionProtoType *T); |
| 357 | ExpectedType VisitUnresolvedUsingType(const UnresolvedUsingType *T); |
| 358 | ExpectedType VisitParenType(const ParenType *T); |
| 359 | ExpectedType VisitTypedefType(const TypedefType *T); |
| 360 | ExpectedType VisitTypeOfExprType(const TypeOfExprType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 361 | // FIXME: DependentTypeOfExprType |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 362 | ExpectedType VisitTypeOfType(const TypeOfType *T); |
| 363 | ExpectedType VisitDecltypeType(const DecltypeType *T); |
| 364 | ExpectedType VisitUnaryTransformType(const UnaryTransformType *T); |
| 365 | ExpectedType VisitAutoType(const AutoType *T); |
| 366 | ExpectedType VisitInjectedClassNameType(const InjectedClassNameType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 367 | // FIXME: DependentDecltypeType |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 368 | ExpectedType VisitRecordType(const RecordType *T); |
| 369 | ExpectedType VisitEnumType(const EnumType *T); |
| 370 | ExpectedType VisitAttributedType(const AttributedType *T); |
| 371 | ExpectedType VisitTemplateTypeParmType(const TemplateTypeParmType *T); |
| 372 | ExpectedType VisitSubstTemplateTypeParmType( |
| 373 | const SubstTemplateTypeParmType *T); |
| 374 | ExpectedType VisitTemplateSpecializationType( |
| 375 | const TemplateSpecializationType *T); |
| 376 | ExpectedType VisitElaboratedType(const ElaboratedType *T); |
| 377 | ExpectedType VisitDependentNameType(const DependentNameType *T); |
| 378 | ExpectedType VisitPackExpansionType(const PackExpansionType *T); |
| 379 | ExpectedType VisitDependentTemplateSpecializationType( |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 380 | const DependentTemplateSpecializationType *T); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 381 | ExpectedType VisitObjCInterfaceType(const ObjCInterfaceType *T); |
| 382 | ExpectedType VisitObjCObjectType(const ObjCObjectType *T); |
| 383 | ExpectedType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); |
Rafael Stahl | df55620 | 2018-05-29 08:12:15 +0000 | [diff] [blame] | 384 | |
| 385 | // Importing declarations |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 386 | Error ImportDeclParts( |
| 387 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, |
| 388 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc); |
| 389 | Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr); |
| 390 | Error ImportDeclarationNameLoc( |
| 391 | const DeclarationNameInfo &From, DeclarationNameInfo &To); |
| 392 | Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); |
| 393 | Error ImportDeclContext( |
| 394 | Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC); |
| 395 | Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 396 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 397 | Expected<CXXCastPath> ImportCastPath(CastExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 398 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 399 | using Designator = DesignatedInitExpr::Designator; |
| 400 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 401 | /// What we should import from the definition. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 402 | enum ImportDefinitionKind { |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 403 | /// Import the default subset of the definition, which might be |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 404 | /// nothing (if minimal import is set) or might be everything (if minimal |
| 405 | /// import is not set). |
| 406 | IDK_Default, |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 407 | /// Import everything. |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 408 | IDK_Everything, |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 409 | /// Import only the bare bones needed to establish a valid |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 410 | /// DeclContext. |
| 411 | IDK_Basic |
| 412 | }; |
| 413 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 414 | bool shouldForceImportDeclContext(ImportDefinitionKind IDK) { |
| 415 | return IDK == IDK_Everything || |
| 416 | (IDK == IDK_Default && !Importer.isMinimalImport()); |
| 417 | } |
| 418 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 419 | Error ImportInitializer(VarDecl *From, VarDecl *To); |
| 420 | Error ImportDefinition( |
| 421 | RecordDecl *From, RecordDecl *To, |
| 422 | ImportDefinitionKind Kind = IDK_Default); |
| 423 | Error ImportDefinition( |
| 424 | EnumDecl *From, EnumDecl *To, |
| 425 | ImportDefinitionKind Kind = IDK_Default); |
| 426 | Error ImportDefinition( |
| 427 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, |
| 428 | ImportDefinitionKind Kind = IDK_Default); |
| 429 | Error ImportDefinition( |
| 430 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, |
| 431 | ImportDefinitionKind Kind = IDK_Default); |
| 432 | Expected<TemplateParameterList *> ImportTemplateParameterList( |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 433 | TemplateParameterList *Params); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 434 | Error ImportTemplateArguments( |
| 435 | const TemplateArgument *FromArgs, unsigned NumFromArgs, |
| 436 | SmallVectorImpl<TemplateArgument> &ToArgs); |
| 437 | Expected<TemplateArgument> |
| 438 | ImportTemplateArgument(const TemplateArgument &From); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 439 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 440 | template <typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 441 | Error ImportTemplateArgumentListInfo( |
| 442 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 443 | |
| 444 | template<typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 445 | Error ImportTemplateArgumentListInfo( |
| 446 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 447 | const InContainerTy &Container, TemplateArgumentListInfo &Result); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 448 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 449 | using TemplateArgsTy = SmallVector<TemplateArgument, 8>; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 450 | using FunctionTemplateAndArgsTy = |
| 451 | std::tuple<FunctionTemplateDecl *, TemplateArgsTy>; |
| 452 | Expected<FunctionTemplateAndArgsTy> |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 453 | ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 454 | FunctionDecl *FromFD); |
| 455 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 456 | Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 457 | |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 458 | bool IsStructuralMatch(Decl *From, Decl *To, bool Complain); |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 459 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, |
| 460 | bool Complain = true); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 461 | bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 462 | bool Complain = true); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 463 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 464 | bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 465 | bool IsStructuralMatch(FunctionTemplateDecl *From, |
| 466 | FunctionTemplateDecl *To); |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 467 | bool IsStructuralMatch(FunctionDecl *From, FunctionDecl *To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 468 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 469 | bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 470 | ExpectedDecl VisitDecl(Decl *D); |
| 471 | ExpectedDecl VisitImportDecl(ImportDecl *D); |
| 472 | ExpectedDecl VisitEmptyDecl(EmptyDecl *D); |
| 473 | ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D); |
| 474 | ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D); |
| 475 | ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D); |
| 476 | ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D); |
| 477 | ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
| 478 | ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); |
| 479 | ExpectedDecl VisitTypedefDecl(TypedefDecl *D); |
| 480 | ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D); |
| 481 | ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); |
| 482 | ExpectedDecl VisitLabelDecl(LabelDecl *D); |
| 483 | ExpectedDecl VisitEnumDecl(EnumDecl *D); |
| 484 | ExpectedDecl VisitRecordDecl(RecordDecl *D); |
| 485 | ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D); |
| 486 | ExpectedDecl VisitFunctionDecl(FunctionDecl *D); |
| 487 | ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D); |
| 488 | ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 489 | ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 490 | ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D); |
| 491 | ExpectedDecl VisitFieldDecl(FieldDecl *D); |
| 492 | ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D); |
| 493 | ExpectedDecl VisitFriendDecl(FriendDecl *D); |
| 494 | ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D); |
| 495 | ExpectedDecl VisitVarDecl(VarDecl *D); |
| 496 | ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D); |
| 497 | ExpectedDecl VisitParmVarDecl(ParmVarDecl *D); |
| 498 | ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D); |
| 499 | ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
| 500 | ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| 501 | ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| 502 | ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D); |
| 503 | ExpectedDecl VisitUsingDecl(UsingDecl *D); |
| 504 | ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D); |
| 505 | ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 506 | ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
| 507 | ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 508 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 509 | Expected<ObjCTypeParamList *> |
| 510 | ImportObjCTypeParamList(ObjCTypeParamList *list); |
| 511 | |
| 512 | ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
| 513 | ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| 514 | ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| 515 | ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| 516 | ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
| 517 | ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
| 518 | ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 519 | ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
| 520 | ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D); |
| 521 | ExpectedDecl VisitClassTemplateSpecializationDecl( |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 522 | ClassTemplateSpecializationDecl *D); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 523 | ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D); |
| 524 | ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); |
| 525 | ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 526 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 527 | // Importing statements |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 528 | ExpectedStmt VisitStmt(Stmt *S); |
| 529 | ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S); |
| 530 | ExpectedStmt VisitDeclStmt(DeclStmt *S); |
| 531 | ExpectedStmt VisitNullStmt(NullStmt *S); |
| 532 | ExpectedStmt VisitCompoundStmt(CompoundStmt *S); |
| 533 | ExpectedStmt VisitCaseStmt(CaseStmt *S); |
| 534 | ExpectedStmt VisitDefaultStmt(DefaultStmt *S); |
| 535 | ExpectedStmt VisitLabelStmt(LabelStmt *S); |
| 536 | ExpectedStmt VisitAttributedStmt(AttributedStmt *S); |
| 537 | ExpectedStmt VisitIfStmt(IfStmt *S); |
| 538 | ExpectedStmt VisitSwitchStmt(SwitchStmt *S); |
| 539 | ExpectedStmt VisitWhileStmt(WhileStmt *S); |
| 540 | ExpectedStmt VisitDoStmt(DoStmt *S); |
| 541 | ExpectedStmt VisitForStmt(ForStmt *S); |
| 542 | ExpectedStmt VisitGotoStmt(GotoStmt *S); |
| 543 | ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S); |
| 544 | ExpectedStmt VisitContinueStmt(ContinueStmt *S); |
| 545 | ExpectedStmt VisitBreakStmt(BreakStmt *S); |
| 546 | ExpectedStmt VisitReturnStmt(ReturnStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 547 | // FIXME: MSAsmStmt |
| 548 | // FIXME: SEHExceptStmt |
| 549 | // FIXME: SEHFinallyStmt |
| 550 | // FIXME: SEHTryStmt |
| 551 | // FIXME: SEHLeaveStmt |
| 552 | // FIXME: CapturedStmt |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 553 | ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S); |
| 554 | ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S); |
| 555 | ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 556 | // FIXME: MSDependentExistsStmt |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 557 | ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); |
| 558 | ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); |
| 559 | ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); |
| 560 | ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S); |
| 561 | ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); |
| 562 | ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); |
| 563 | ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 564 | |
| 565 | // Importing expressions |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 566 | ExpectedStmt VisitExpr(Expr *E); |
| 567 | ExpectedStmt VisitVAArgExpr(VAArgExpr *E); |
| 568 | ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E); |
| 569 | ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E); |
| 570 | ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E); |
| 571 | ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E); |
| 572 | ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E); |
| 573 | ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); |
| 574 | ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E); |
| 575 | ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E); |
| 576 | ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E); |
| 577 | ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E); |
| 578 | ExpectedStmt VisitStringLiteral(StringLiteral *E); |
| 579 | ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
| 580 | ExpectedStmt VisitAtomicExpr(AtomicExpr *E); |
| 581 | ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E); |
| 582 | ExpectedStmt VisitParenExpr(ParenExpr *E); |
| 583 | ExpectedStmt VisitParenListExpr(ParenListExpr *E); |
| 584 | ExpectedStmt VisitStmtExpr(StmtExpr *E); |
| 585 | ExpectedStmt VisitUnaryOperator(UnaryOperator *E); |
| 586 | ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); |
| 587 | ExpectedStmt VisitBinaryOperator(BinaryOperator *E); |
| 588 | ExpectedStmt VisitConditionalOperator(ConditionalOperator *E); |
| 589 | ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E); |
| 590 | ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E); |
| 591 | ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); |
| 592 | ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E); |
| 593 | ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
| 594 | ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E); |
| 595 | ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E); |
| 596 | ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 597 | ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE); |
| 598 | ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E); |
| 599 | ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E); |
| 600 | ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); |
| 601 | ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); |
| 602 | ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); |
| 603 | ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E); |
| 604 | ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); |
| 605 | ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E); |
| 606 | ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E); |
| 607 | ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E); |
| 608 | ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E); |
| 609 | ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E); |
| 610 | ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E); |
| 611 | ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); |
| 612 | ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E); |
| 613 | ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E); |
| 614 | ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); |
| 615 | ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E); |
| 616 | ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E); |
| 617 | ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E); |
| 618 | ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); |
| 619 | ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); |
| 620 | ExpectedStmt VisitMemberExpr(MemberExpr *E); |
| 621 | ExpectedStmt VisitCallExpr(CallExpr *E); |
| 622 | ExpectedStmt VisitLambdaExpr(LambdaExpr *LE); |
| 623 | ExpectedStmt VisitInitListExpr(InitListExpr *E); |
| 624 | ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E); |
| 625 | ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E); |
| 626 | ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); |
| 627 | ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); |
| 628 | ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); |
| 629 | ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E); |
| 630 | ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); |
| 631 | ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E); |
| 632 | ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 633 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 634 | template<typename IIter, typename OIter> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 635 | Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 636 | using ItemT = typename std::remove_reference<decltype(*Obegin)>::type; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 637 | for (; Ibegin != Iend; ++Ibegin, ++Obegin) { |
| 638 | Expected<ItemT> ToOrErr = import(*Ibegin); |
| 639 | if (!ToOrErr) |
| 640 | return ToOrErr.takeError(); |
| 641 | *Obegin = *ToOrErr; |
| 642 | } |
| 643 | return Error::success(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 644 | } |
| 645 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 646 | // Import every item from a container structure into an output container. |
| 647 | // If error occurs, stops at first error and returns the error. |
| 648 | // The output container should have space for all needed elements (it is not |
| 649 | // expanded, new items are put into from the beginning). |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 650 | template<typename InContainerTy, typename OutContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 651 | Error ImportContainerChecked( |
| 652 | const InContainerTy &InContainer, OutContainerTy &OutContainer) { |
| 653 | return ImportArrayChecked( |
| 654 | InContainer.begin(), InContainer.end(), OutContainer.begin()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | template<typename InContainerTy, typename OIter> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 658 | Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 659 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); |
| 660 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 661 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 662 | void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 663 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 664 | Expected<FunctionDecl *> FindFunctionTemplateSpecialization( |
| 665 | FunctionDecl *FromFD); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 666 | }; |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 667 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 668 | // FIXME: Temporary until every import returns Expected. |
| 669 | template <> |
| 670 | Expected<TemplateName> ASTNodeImporter::import(const TemplateName &From) { |
| 671 | TemplateName To = Importer.Import(From); |
| 672 | if (To.isNull() && !From.isNull()) |
| 673 | return make_error<ImportError>(); |
| 674 | return To; |
| 675 | } |
| 676 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 677 | template <typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 678 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 679 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 680 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 681 | auto ToLAngleLocOrErr = import(FromLAngleLoc); |
| 682 | if (!ToLAngleLocOrErr) |
| 683 | return ToLAngleLocOrErr.takeError(); |
| 684 | auto ToRAngleLocOrErr = import(FromRAngleLoc); |
| 685 | if (!ToRAngleLocOrErr) |
| 686 | return ToRAngleLocOrErr.takeError(); |
| 687 | |
| 688 | TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr); |
| 689 | if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo)) |
| 690 | return Err; |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 691 | Result = ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 692 | return Error::success(); |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 693 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 694 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 695 | template <> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 696 | Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 697 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { |
| 698 | return ImportTemplateArgumentListInfo( |
| 699 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); |
| 700 | } |
| 701 | |
| 702 | template <> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 703 | Error ASTNodeImporter::ImportTemplateArgumentListInfo< |
| 704 | ASTTemplateArgumentListInfo>( |
| 705 | const ASTTemplateArgumentListInfo &From, |
| 706 | TemplateArgumentListInfo &Result) { |
| 707 | return ImportTemplateArgumentListInfo( |
| 708 | From.LAngleLoc, From.RAngleLoc, From.arguments(), Result); |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 709 | } |
| 710 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 711 | Expected<ASTNodeImporter::FunctionTemplateAndArgsTy> |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 712 | ASTNodeImporter::ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 713 | FunctionDecl *FromFD) { |
| 714 | assert(FromFD->getTemplatedKind() == |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 715 | FunctionDecl::TK_FunctionTemplateSpecialization); |
| 716 | |
| 717 | FunctionTemplateAndArgsTy Result; |
| 718 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 719 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 720 | if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate())) |
| 721 | return std::move(Err); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 722 | |
| 723 | // Import template arguments. |
| 724 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 725 | if (Error Err = ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), |
| 726 | std::get<1>(Result))) |
| 727 | return std::move(Err); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 728 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 729 | return Result; |
| 730 | } |
| 731 | |
| 732 | template <> |
| 733 | Expected<TemplateParameterList *> |
| 734 | ASTNodeImporter::import(TemplateParameterList *From) { |
| 735 | SmallVector<NamedDecl *, 4> To(From->size()); |
| 736 | if (Error Err = ImportContainerChecked(*From, To)) |
| 737 | return std::move(Err); |
| 738 | |
| 739 | ExpectedExpr ToRequiresClause = import(From->getRequiresClause()); |
| 740 | if (!ToRequiresClause) |
| 741 | return ToRequiresClause.takeError(); |
| 742 | |
| 743 | auto ToTemplateLocOrErr = import(From->getTemplateLoc()); |
| 744 | if (!ToTemplateLocOrErr) |
| 745 | return ToTemplateLocOrErr.takeError(); |
| 746 | auto ToLAngleLocOrErr = import(From->getLAngleLoc()); |
| 747 | if (!ToLAngleLocOrErr) |
| 748 | return ToLAngleLocOrErr.takeError(); |
| 749 | auto ToRAngleLocOrErr = import(From->getRAngleLoc()); |
| 750 | if (!ToRAngleLocOrErr) |
| 751 | return ToRAngleLocOrErr.takeError(); |
| 752 | |
| 753 | return TemplateParameterList::Create( |
| 754 | Importer.getToContext(), |
| 755 | *ToTemplateLocOrErr, |
| 756 | *ToLAngleLocOrErr, |
| 757 | To, |
| 758 | *ToRAngleLocOrErr, |
| 759 | *ToRequiresClause); |
| 760 | } |
| 761 | |
| 762 | template <> |
| 763 | Expected<TemplateArgument> |
| 764 | ASTNodeImporter::import(const TemplateArgument &From) { |
| 765 | switch (From.getKind()) { |
| 766 | case TemplateArgument::Null: |
| 767 | return TemplateArgument(); |
| 768 | |
| 769 | case TemplateArgument::Type: { |
| 770 | ExpectedType ToTypeOrErr = import(From.getAsType()); |
| 771 | if (!ToTypeOrErr) |
| 772 | return ToTypeOrErr.takeError(); |
| 773 | return TemplateArgument(*ToTypeOrErr); |
| 774 | } |
| 775 | |
| 776 | case TemplateArgument::Integral: { |
| 777 | ExpectedType ToTypeOrErr = import(From.getIntegralType()); |
| 778 | if (!ToTypeOrErr) |
| 779 | return ToTypeOrErr.takeError(); |
| 780 | return TemplateArgument(From, *ToTypeOrErr); |
| 781 | } |
| 782 | |
| 783 | case TemplateArgument::Declaration: { |
| 784 | Expected<ValueDecl *> ToOrErr = import(From.getAsDecl()); |
| 785 | if (!ToOrErr) |
| 786 | return ToOrErr.takeError(); |
| 787 | ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl()); |
| 788 | if (!ToTypeOrErr) |
| 789 | return ToTypeOrErr.takeError(); |
| 790 | return TemplateArgument(*ToOrErr, *ToTypeOrErr); |
| 791 | } |
| 792 | |
| 793 | case TemplateArgument::NullPtr: { |
| 794 | ExpectedType ToTypeOrErr = import(From.getNullPtrType()); |
| 795 | if (!ToTypeOrErr) |
| 796 | return ToTypeOrErr.takeError(); |
| 797 | return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true); |
| 798 | } |
| 799 | |
| 800 | case TemplateArgument::Template: { |
| 801 | Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate()); |
| 802 | if (!ToTemplateOrErr) |
| 803 | return ToTemplateOrErr.takeError(); |
| 804 | |
| 805 | return TemplateArgument(*ToTemplateOrErr); |
| 806 | } |
| 807 | |
| 808 | case TemplateArgument::TemplateExpansion: { |
| 809 | Expected<TemplateName> ToTemplateOrErr = |
| 810 | import(From.getAsTemplateOrTemplatePattern()); |
| 811 | if (!ToTemplateOrErr) |
| 812 | return ToTemplateOrErr.takeError(); |
| 813 | |
| 814 | return TemplateArgument( |
| 815 | *ToTemplateOrErr, From.getNumTemplateExpansions()); |
| 816 | } |
| 817 | |
| 818 | case TemplateArgument::Expression: |
| 819 | if (ExpectedExpr ToExpr = import(From.getAsExpr())) |
| 820 | return TemplateArgument(*ToExpr); |
| 821 | else |
| 822 | return ToExpr.takeError(); |
| 823 | |
| 824 | case TemplateArgument::Pack: { |
| 825 | SmallVector<TemplateArgument, 2> ToPack; |
| 826 | ToPack.reserve(From.pack_size()); |
| 827 | if (Error Err = ImportTemplateArguments( |
| 828 | From.pack_begin(), From.pack_size(), ToPack)) |
| 829 | return std::move(Err); |
| 830 | |
| 831 | return TemplateArgument( |
| 832 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | llvm_unreachable("Invalid template argument kind"); |
| 837 | } |
| 838 | |
| 839 | template <> |
| 840 | Expected<TemplateArgumentLoc> |
| 841 | ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) { |
| 842 | Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument()); |
| 843 | if (!ArgOrErr) |
| 844 | return ArgOrErr.takeError(); |
| 845 | TemplateArgument Arg = *ArgOrErr; |
| 846 | |
| 847 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); |
| 848 | |
| 849 | TemplateArgumentLocInfo ToInfo; |
| 850 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 851 | ExpectedExpr E = import(FromInfo.getAsExpr()); |
| 852 | if (!E) |
| 853 | return E.takeError(); |
| 854 | ToInfo = TemplateArgumentLocInfo(*E); |
| 855 | } else if (Arg.getKind() == TemplateArgument::Type) { |
| 856 | if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo())) |
| 857 | ToInfo = TemplateArgumentLocInfo(*TSIOrErr); |
| 858 | else |
| 859 | return TSIOrErr.takeError(); |
| 860 | } else { |
| 861 | auto ToTemplateQualifierLocOrErr = |
| 862 | import(FromInfo.getTemplateQualifierLoc()); |
| 863 | if (!ToTemplateQualifierLocOrErr) |
| 864 | return ToTemplateQualifierLocOrErr.takeError(); |
| 865 | auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc()); |
| 866 | if (!ToTemplateNameLocOrErr) |
| 867 | return ToTemplateNameLocOrErr.takeError(); |
| 868 | auto ToTemplateEllipsisLocOrErr = |
| 869 | import(FromInfo.getTemplateEllipsisLoc()); |
| 870 | if (!ToTemplateEllipsisLocOrErr) |
| 871 | return ToTemplateEllipsisLocOrErr.takeError(); |
| 872 | |
| 873 | ToInfo = TemplateArgumentLocInfo( |
| 874 | *ToTemplateQualifierLocOrErr, |
| 875 | *ToTemplateNameLocOrErr, |
| 876 | *ToTemplateEllipsisLocOrErr); |
| 877 | } |
| 878 | |
| 879 | return TemplateArgumentLoc(Arg, ToInfo); |
| 880 | } |
| 881 | |
| 882 | template <> |
| 883 | Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) { |
| 884 | if (DG.isNull()) |
| 885 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); |
| 886 | size_t NumDecls = DG.end() - DG.begin(); |
| 887 | SmallVector<Decl *, 1> ToDecls; |
| 888 | ToDecls.reserve(NumDecls); |
| 889 | for (Decl *FromD : DG) { |
| 890 | if (auto ToDOrErr = import(FromD)) |
| 891 | ToDecls.push_back(*ToDOrErr); |
| 892 | else |
| 893 | return ToDOrErr.takeError(); |
| 894 | } |
| 895 | return DeclGroupRef::Create(Importer.getToContext(), |
| 896 | ToDecls.begin(), |
| 897 | NumDecls); |
| 898 | } |
| 899 | |
| 900 | template <> |
| 901 | Expected<ASTNodeImporter::Designator> |
| 902 | ASTNodeImporter::import(const Designator &D) { |
| 903 | if (D.isFieldDesignator()) { |
| 904 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); |
| 905 | |
| 906 | ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc()); |
| 907 | if (!ToDotLocOrErr) |
| 908 | return ToDotLocOrErr.takeError(); |
| 909 | |
| 910 | ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc()); |
| 911 | if (!ToFieldLocOrErr) |
| 912 | return ToFieldLocOrErr.takeError(); |
| 913 | |
| 914 | return Designator(ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr); |
| 915 | } |
| 916 | |
| 917 | ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc()); |
| 918 | if (!ToLBracketLocOrErr) |
| 919 | return ToLBracketLocOrErr.takeError(); |
| 920 | |
| 921 | ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc()); |
| 922 | if (!ToRBracketLocOrErr) |
| 923 | return ToRBracketLocOrErr.takeError(); |
| 924 | |
| 925 | if (D.isArrayDesignator()) |
| 926 | return Designator(D.getFirstExprIndex(), |
| 927 | *ToLBracketLocOrErr, *ToRBracketLocOrErr); |
| 928 | |
| 929 | ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc()); |
| 930 | if (!ToEllipsisLocOrErr) |
| 931 | return ToEllipsisLocOrErr.takeError(); |
| 932 | |
| 933 | assert(D.isArrayRangeDesignator()); |
| 934 | return Designator( |
| 935 | D.getFirstExprIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr, |
| 936 | *ToRBracketLocOrErr); |
| 937 | } |
| 938 | |
| 939 | template <> |
| 940 | Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) { |
| 941 | VarDecl *Var = nullptr; |
| 942 | if (From.capturesVariable()) { |
| 943 | if (auto VarOrErr = import(From.getCapturedVar())) |
| 944 | Var = *VarOrErr; |
| 945 | else |
| 946 | return VarOrErr.takeError(); |
| 947 | } |
| 948 | |
| 949 | auto LocationOrErr = import(From.getLocation()); |
| 950 | if (!LocationOrErr) |
| 951 | return LocationOrErr.takeError(); |
| 952 | |
| 953 | SourceLocation EllipsisLoc; |
| 954 | if (From.isPackExpansion()) |
| 955 | if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc())) |
| 956 | return std::move(Err); |
| 957 | |
| 958 | return LambdaCapture( |
| 959 | *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var, |
| 960 | EllipsisLoc); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 961 | } |
| 962 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 963 | } // namespace clang |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 964 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 965 | //---------------------------------------------------------------------------- |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 966 | // Import Types |
| 967 | //---------------------------------------------------------------------------- |
| 968 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 969 | using namespace clang; |
| 970 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 971 | ExpectedType ASTNodeImporter::VisitType(const Type *T) { |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 972 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) |
| 973 | << T->getTypeClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 974 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 975 | } |
| 976 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 977 | ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ |
| 978 | ExpectedType UnderlyingTypeOrErr = import(T->getValueType()); |
| 979 | if (!UnderlyingTypeOrErr) |
| 980 | return UnderlyingTypeOrErr.takeError(); |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 981 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 982 | return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr); |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 983 | } |
| 984 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 985 | ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 986 | switch (T->getKind()) { |
Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 987 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 988 | case BuiltinType::Id: \ |
| 989 | return Importer.getToContext().SingletonId; |
Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 990 | #include "clang/Basic/OpenCLImageTypes.def" |
John McCall | e314e27 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 991 | #define SHARED_SINGLETON_TYPE(Expansion) |
| 992 | #define BUILTIN_TYPE(Id, SingletonId) \ |
| 993 | case BuiltinType::Id: return Importer.getToContext().SingletonId; |
| 994 | #include "clang/AST/BuiltinTypes.def" |
| 995 | |
| 996 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" |
| 997 | // context supports C++. |
| 998 | |
| 999 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" |
| 1000 | // context supports ObjC. |
| 1001 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1002 | case BuiltinType::Char_U: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1003 | // The context we're importing from has an unsigned 'char'. If we're |
| 1004 | // importing into a context with a signed 'char', translate to |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1005 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1006 | if (Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1007 | return Importer.getToContext().UnsignedCharTy; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1008 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1009 | return Importer.getToContext().CharTy; |
| 1010 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1011 | case BuiltinType::Char_S: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1012 | // The context we're importing from has an unsigned 'char'. If we're |
| 1013 | // importing into a context with a signed 'char', translate to |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1014 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1015 | if (!Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1016 | return Importer.getToContext().SignedCharTy; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1017 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1018 | return Importer.getToContext().CharTy; |
| 1019 | |
Chris Lattner | ad3467e | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 1020 | case BuiltinType::WChar_S: |
| 1021 | case BuiltinType::WChar_U: |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1022 | // FIXME: If not in C++, shall we translate to the C equivalent of |
| 1023 | // wchar_t? |
| 1024 | return Importer.getToContext().WCharTy; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1025 | } |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 1026 | |
| 1027 | llvm_unreachable("Invalid BuiltinType Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1028 | } |
| 1029 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1030 | ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { |
| 1031 | ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType()); |
| 1032 | if (!ToOriginalTypeOrErr) |
| 1033 | return ToOriginalTypeOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1034 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1035 | return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1038 | ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) { |
| 1039 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1040 | if (!ToElementTypeOrErr) |
| 1041 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1042 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1043 | return Importer.getToContext().getComplexType(*ToElementTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1044 | } |
| 1045 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1046 | ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) { |
| 1047 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1048 | if (!ToPointeeTypeOrErr) |
| 1049 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1050 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1051 | return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1054 | ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1055 | // FIXME: Check for blocks support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1056 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1057 | if (!ToPointeeTypeOrErr) |
| 1058 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1059 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1060 | return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1063 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1064 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1065 | // FIXME: Check for C++ support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1066 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); |
| 1067 | if (!ToPointeeTypeOrErr) |
| 1068 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1069 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1070 | return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1073 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1074 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1075 | // FIXME: Check for C++0x support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1076 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); |
| 1077 | if (!ToPointeeTypeOrErr) |
| 1078 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1079 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1080 | return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1081 | } |
| 1082 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1083 | ExpectedType |
| 1084 | ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1085 | // FIXME: Check for C++ support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1086 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1087 | if (!ToPointeeTypeOrErr) |
| 1088 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1089 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1090 | ExpectedType ClassTypeOrErr = import(QualType(T->getClass(), 0)); |
| 1091 | if (!ClassTypeOrErr) |
| 1092 | return ClassTypeOrErr.takeError(); |
| 1093 | |
| 1094 | return Importer.getToContext().getMemberPointerType( |
| 1095 | *ToPointeeTypeOrErr, (*ClassTypeOrErr).getTypePtr()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1096 | } |
| 1097 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1098 | ExpectedType |
| 1099 | ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { |
| 1100 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1101 | if (!ToElementTypeOrErr) |
| 1102 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1103 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1104 | return Importer.getToContext().getConstantArrayType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1105 | T->getSize(), |
| 1106 | T->getSizeModifier(), |
| 1107 | T->getIndexTypeCVRQualifiers()); |
| 1108 | } |
| 1109 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1110 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1111 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1112 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1113 | if (!ToElementTypeOrErr) |
| 1114 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1115 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1116 | return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1117 | T->getSizeModifier(), |
| 1118 | T->getIndexTypeCVRQualifiers()); |
| 1119 | } |
| 1120 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1121 | ExpectedType |
| 1122 | ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { |
| 1123 | QualType ToElementType; |
| 1124 | Expr *ToSizeExpr; |
| 1125 | SourceRange ToBracketsRange; |
| 1126 | if (auto Imp = importSeq( |
| 1127 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) |
| 1128 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; |
| 1129 | else |
| 1130 | return Imp.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1131 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1132 | return Importer.getToContext().getVariableArrayType( |
| 1133 | ToElementType, ToSizeExpr, T->getSizeModifier(), |
| 1134 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1135 | } |
| 1136 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1137 | ExpectedType ASTNodeImporter::VisitDependentSizedArrayType( |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1138 | const DependentSizedArrayType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1139 | QualType ToElementType; |
| 1140 | Expr *ToSizeExpr; |
| 1141 | SourceRange ToBracketsRange; |
| 1142 | if (auto Imp = importSeq( |
| 1143 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) |
| 1144 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; |
| 1145 | else |
| 1146 | return Imp.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1147 | // SizeExpr may be null if size is not specified directly. |
| 1148 | // For example, 'int a[]'. |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1149 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1150 | return Importer.getToContext().getDependentSizedArrayType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1151 | ToElementType, ToSizeExpr, T->getSizeModifier(), |
| 1152 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1153 | } |
| 1154 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1155 | ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) { |
| 1156 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1157 | if (!ToElementTypeOrErr) |
| 1158 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1159 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1160 | return Importer.getToContext().getVectorType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1161 | T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 1162 | T->getVectorKind()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1165 | ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { |
| 1166 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1167 | if (!ToElementTypeOrErr) |
| 1168 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1169 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1170 | return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1171 | T->getNumElements()); |
| 1172 | } |
| 1173 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1174 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1175 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1176 | // FIXME: What happens if we're importing a function without a prototype |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1177 | // into C++? Should we make it variadic? |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1178 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); |
| 1179 | if (!ToReturnTypeOrErr) |
| 1180 | return ToReturnTypeOrErr.takeError(); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1181 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1182 | return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr, |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1183 | T->getExtInfo()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1186 | ExpectedType |
| 1187 | ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { |
| 1188 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); |
| 1189 | if (!ToReturnTypeOrErr) |
| 1190 | return ToReturnTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1191 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1192 | // Import argument types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1193 | SmallVector<QualType, 4> ArgTypes; |
Aaron Ballman | 40bd0aa | 2014-03-17 15:23:01 +0000 | [diff] [blame] | 1194 | for (const auto &A : T->param_types()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1195 | ExpectedType TyOrErr = import(A); |
| 1196 | if (!TyOrErr) |
| 1197 | return TyOrErr.takeError(); |
| 1198 | ArgTypes.push_back(*TyOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1199 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1200 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1201 | // Import exception types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1202 | SmallVector<QualType, 4> ExceptionTypes; |
Aaron Ballman | b088fbe | 2014-03-17 15:38:09 +0000 | [diff] [blame] | 1203 | for (const auto &E : T->exceptions()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1204 | ExpectedType TyOrErr = import(E); |
| 1205 | if (!TyOrErr) |
| 1206 | return TyOrErr.takeError(); |
| 1207 | ExceptionTypes.push_back(*TyOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1208 | } |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 1209 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1210 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); |
| 1211 | FunctionProtoType::ExtProtoInfo ToEPI; |
| 1212 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1213 | auto Imp = importSeq( |
| 1214 | FromEPI.ExceptionSpec.NoexceptExpr, |
| 1215 | FromEPI.ExceptionSpec.SourceDecl, |
| 1216 | FromEPI.ExceptionSpec.SourceTemplate); |
| 1217 | if (!Imp) |
| 1218 | return Imp.takeError(); |
| 1219 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1220 | ToEPI.ExtInfo = FromEPI.ExtInfo; |
| 1221 | ToEPI.Variadic = FromEPI.Variadic; |
| 1222 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; |
| 1223 | ToEPI.TypeQuals = FromEPI.TypeQuals; |
| 1224 | ToEPI.RefQualifier = FromEPI.RefQualifier; |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 1225 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; |
| 1226 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1227 | std::tie( |
| 1228 | ToEPI.ExceptionSpec.NoexceptExpr, |
| 1229 | ToEPI.ExceptionSpec.SourceDecl, |
| 1230 | ToEPI.ExceptionSpec.SourceTemplate) = *Imp; |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1231 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1232 | return Importer.getToContext().getFunctionType( |
| 1233 | *ToReturnTypeOrErr, ArgTypes, ToEPI); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1234 | } |
| 1235 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1236 | ExpectedType ASTNodeImporter::VisitUnresolvedUsingType( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1237 | const UnresolvedUsingType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1238 | UnresolvedUsingTypenameDecl *ToD; |
| 1239 | Decl *ToPrevD; |
| 1240 | if (auto Imp = importSeq(T->getDecl(), T->getDecl()->getPreviousDecl())) |
| 1241 | std::tie(ToD, ToPrevD) = *Imp; |
| 1242 | else |
| 1243 | return Imp.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1244 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1245 | return Importer.getToContext().getTypeDeclType( |
| 1246 | ToD, cast_or_null<TypeDecl>(ToPrevD)); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1247 | } |
| 1248 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1249 | ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) { |
| 1250 | ExpectedType ToInnerTypeOrErr = import(T->getInnerType()); |
| 1251 | if (!ToInnerTypeOrErr) |
| 1252 | return ToInnerTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1253 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1254 | return Importer.getToContext().getParenType(*ToInnerTypeOrErr); |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 1255 | } |
| 1256 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1257 | ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { |
| 1258 | Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1259 | if (!ToDeclOrErr) |
| 1260 | return ToDeclOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1261 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1262 | return Importer.getToContext().getTypeDeclType(*ToDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1263 | } |
| 1264 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1265 | ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { |
| 1266 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); |
| 1267 | if (!ToExprOrErr) |
| 1268 | return ToExprOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1269 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1270 | return Importer.getToContext().getTypeOfExprType(*ToExprOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1273 | ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { |
| 1274 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1275 | if (!ToUnderlyingTypeOrErr) |
| 1276 | return ToUnderlyingTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1277 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1278 | return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1279 | } |
| 1280 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1281 | ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1282 | // FIXME: Make sure that the "to" context supports C++0x! |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1283 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); |
| 1284 | if (!ToExprOrErr) |
| 1285 | return ToExprOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1286 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1287 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1288 | if (!ToUnderlyingTypeOrErr) |
| 1289 | return ToUnderlyingTypeOrErr.takeError(); |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 1290 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1291 | return Importer.getToContext().getDecltypeType( |
| 1292 | *ToExprOrErr, *ToUnderlyingTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1293 | } |
| 1294 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1295 | ExpectedType |
| 1296 | ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 1297 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); |
| 1298 | if (!ToBaseTypeOrErr) |
| 1299 | return ToBaseTypeOrErr.takeError(); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1300 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1301 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1302 | if (!ToUnderlyingTypeOrErr) |
| 1303 | return ToUnderlyingTypeOrErr.takeError(); |
| 1304 | |
| 1305 | return Importer.getToContext().getUnaryTransformType( |
| 1306 | *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind()); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1307 | } |
| 1308 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1309 | ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 1310 | // FIXME: Make sure that the "to" context supports C++11! |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1311 | ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType()); |
| 1312 | if (!ToDeducedTypeOrErr) |
| 1313 | return ToDeducedTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1314 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1315 | return Importer.getToContext().getAutoType(*ToDeducedTypeOrErr, |
| 1316 | T->getKeyword(), |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 1317 | /*IsDependent*/false); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1318 | } |
| 1319 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1320 | ExpectedType ASTNodeImporter::VisitInjectedClassNameType( |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1321 | const InjectedClassNameType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1322 | Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1323 | if (!ToDeclOrErr) |
| 1324 | return ToDeclOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1325 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1326 | ExpectedType ToInjTypeOrErr = import(T->getInjectedSpecializationType()); |
| 1327 | if (!ToInjTypeOrErr) |
| 1328 | return ToInjTypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1329 | |
| 1330 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading |
| 1331 | // See comments in InjectedClassNameType definition for details |
| 1332 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); |
| 1333 | enum { |
| 1334 | TypeAlignmentInBits = 4, |
| 1335 | TypeAlignment = 1 << TypeAlignmentInBits |
| 1336 | }; |
| 1337 | |
| 1338 | return QualType(new (Importer.getToContext(), TypeAlignment) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1339 | InjectedClassNameType(*ToDeclOrErr, *ToInjTypeOrErr), 0); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1340 | } |
| 1341 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1342 | ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) { |
| 1343 | Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1344 | if (!ToDeclOrErr) |
| 1345 | return ToDeclOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1346 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1347 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1348 | } |
| 1349 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1350 | ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) { |
| 1351 | Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1352 | if (!ToDeclOrErr) |
| 1353 | return ToDeclOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1354 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1355 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1356 | } |
| 1357 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1358 | ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { |
| 1359 | ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType()); |
| 1360 | if (!ToModifiedTypeOrErr) |
| 1361 | return ToModifiedTypeOrErr.takeError(); |
| 1362 | ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType()); |
| 1363 | if (!ToEquivalentTypeOrErr) |
| 1364 | return ToEquivalentTypeOrErr.takeError(); |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1365 | |
| 1366 | return Importer.getToContext().getAttributedType(T->getAttrKind(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1367 | *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr); |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1368 | } |
| 1369 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1370 | ExpectedType ASTNodeImporter::VisitTemplateTypeParmType( |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1371 | const TemplateTypeParmType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1372 | Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1373 | if (!ToDeclOrErr) |
| 1374 | return ToDeclOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1375 | |
| 1376 | return Importer.getToContext().getTemplateTypeParmType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1377 | T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1378 | } |
| 1379 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1380 | ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType( |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1381 | const SubstTemplateTypeParmType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1382 | ExpectedType ReplacedOrErr = import(QualType(T->getReplacedParameter(), 0)); |
| 1383 | if (!ReplacedOrErr) |
| 1384 | return ReplacedOrErr.takeError(); |
| 1385 | const TemplateTypeParmType *Replaced = |
| 1386 | cast<TemplateTypeParmType>((*ReplacedOrErr).getTypePtr()); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1387 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1388 | ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType()); |
| 1389 | if (!ToReplacementTypeOrErr) |
| 1390 | return ToReplacementTypeOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1391 | |
| 1392 | return Importer.getToContext().getSubstTemplateTypeParmType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1393 | Replaced, (*ToReplacementTypeOrErr).getCanonicalType()); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1394 | } |
| 1395 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1396 | ExpectedType ASTNodeImporter::VisitTemplateSpecializationType( |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1397 | const TemplateSpecializationType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1398 | auto ToTemplateOrErr = import(T->getTemplateName()); |
| 1399 | if (!ToTemplateOrErr) |
| 1400 | return ToTemplateOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1401 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1402 | SmallVector<TemplateArgument, 2> ToTemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1403 | if (Error Err = ImportTemplateArguments( |
| 1404 | T->getArgs(), T->getNumArgs(), ToTemplateArgs)) |
| 1405 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1406 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1407 | QualType ToCanonType; |
| 1408 | if (!QualType(T, 0).isCanonical()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1409 | QualType FromCanonType |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1410 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1411 | if (ExpectedType TyOrErr = import(FromCanonType)) |
| 1412 | ToCanonType = *TyOrErr; |
| 1413 | else |
| 1414 | return TyOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1415 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1416 | return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr, |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 1417 | ToTemplateArgs, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1418 | ToCanonType); |
| 1419 | } |
| 1420 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1421 | ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1422 | // Note: the qualifier in an ElaboratedType is optional. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1423 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1424 | if (!ToQualifierOrErr) |
| 1425 | return ToQualifierOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1426 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1427 | ExpectedType ToNamedTypeOrErr = import(T->getNamedType()); |
| 1428 | if (!ToNamedTypeOrErr) |
| 1429 | return ToNamedTypeOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1430 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1431 | Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl()); |
| 1432 | if (!ToOwnedTagDeclOrErr) |
| 1433 | return ToOwnedTagDeclOrErr.takeError(); |
Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 1434 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1435 | return Importer.getToContext().getElaboratedType(T->getKeyword(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1436 | *ToQualifierOrErr, |
| 1437 | *ToNamedTypeOrErr, |
| 1438 | *ToOwnedTagDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1439 | } |
| 1440 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1441 | ExpectedType |
| 1442 | ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { |
| 1443 | ExpectedType ToPatternOrErr = import(T->getPattern()); |
| 1444 | if (!ToPatternOrErr) |
| 1445 | return ToPatternOrErr.takeError(); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1446 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1447 | return Importer.getToContext().getPackExpansionType(*ToPatternOrErr, |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1448 | T->getNumExpansions()); |
| 1449 | } |
| 1450 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1451 | ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType( |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1452 | const DependentTemplateSpecializationType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1453 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1454 | if (!ToQualifierOrErr) |
| 1455 | return ToQualifierOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1456 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1457 | IdentifierInfo *ToName = Importer.Import(T->getIdentifier()); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1458 | |
| 1459 | SmallVector<TemplateArgument, 2> ToPack; |
| 1460 | ToPack.reserve(T->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1461 | if (Error Err = ImportTemplateArguments( |
| 1462 | T->getArgs(), T->getNumArgs(), ToPack)) |
| 1463 | return std::move(Err); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1464 | |
| 1465 | return Importer.getToContext().getDependentTemplateSpecializationType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1466 | T->getKeyword(), *ToQualifierOrErr, ToName, ToPack); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1467 | } |
| 1468 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1469 | ExpectedType |
| 1470 | ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) { |
| 1471 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1472 | if (!ToQualifierOrErr) |
| 1473 | return ToQualifierOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1474 | |
| 1475 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1476 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1477 | QualType Canon; |
| 1478 | if (T != T->getCanonicalTypeInternal().getTypePtr()) { |
| 1479 | if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal())) |
| 1480 | Canon = (*TyOrErr).getCanonicalType(); |
| 1481 | else |
| 1482 | return TyOrErr.takeError(); |
| 1483 | } |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1484 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1485 | return Importer.getToContext().getDependentNameType(T->getKeyword(), |
| 1486 | *ToQualifierOrErr, |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1487 | Name, Canon); |
| 1488 | } |
| 1489 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1490 | ExpectedType |
| 1491 | ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
| 1492 | Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1493 | if (!ToDeclOrErr) |
| 1494 | return ToDeclOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1495 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1496 | return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1497 | } |
| 1498 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1499 | ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { |
| 1500 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); |
| 1501 | if (!ToBaseTypeOrErr) |
| 1502 | return ToBaseTypeOrErr.takeError(); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1503 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1504 | SmallVector<QualType, 4> TypeArgs; |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 1505 | for (auto TypeArg : T->getTypeArgsAsWritten()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1506 | if (ExpectedType TyOrErr = import(TypeArg)) |
| 1507 | TypeArgs.push_back(*TyOrErr); |
| 1508 | else |
| 1509 | return TyOrErr.takeError(); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1510 | } |
| 1511 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1512 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 1513 | for (auto *P : T->quals()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1514 | if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P)) |
| 1515 | Protocols.push_back(*ProtocolOrErr); |
| 1516 | else |
| 1517 | return ProtocolOrErr.takeError(); |
| 1518 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1519 | } |
| 1520 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1521 | return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs, |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 1522 | Protocols, |
| 1523 | T->isKindOfTypeAsWritten()); |
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 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1527 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1528 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1529 | if (!ToPointeeTypeOrErr) |
| 1530 | return ToPointeeTypeOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1531 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1532 | return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1533 | } |
| 1534 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 1535 | //---------------------------------------------------------------------------- |
| 1536 | // Import Declarations |
| 1537 | //---------------------------------------------------------------------------- |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1538 | Error ASTNodeImporter::ImportDeclParts( |
| 1539 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, |
| 1540 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) { |
Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1541 | // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop. |
| 1542 | // example: int struct_in_proto(struct data_t{int a;int b;} *d); |
| 1543 | DeclContext *OrigDC = D->getDeclContext(); |
| 1544 | FunctionDecl *FunDecl; |
| 1545 | if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) && |
| 1546 | FunDecl->hasBody()) { |
Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1547 | auto getLeafPointeeType = [](const Type *T) { |
| 1548 | while (T->isPointerType() || T->isArrayType()) { |
| 1549 | T = T->getPointeeOrArrayElementType(); |
| 1550 | } |
| 1551 | return T; |
| 1552 | }; |
| 1553 | for (const ParmVarDecl *P : FunDecl->parameters()) { |
| 1554 | const Type *LeafT = |
| 1555 | getLeafPointeeType(P->getType().getCanonicalType().getTypePtr()); |
| 1556 | auto *RT = dyn_cast<RecordType>(LeafT); |
| 1557 | if (RT && RT->getDecl() == D) { |
| 1558 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 1559 | << D->getDeclKindName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1560 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1561 | } |
Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1562 | } |
| 1563 | } |
| 1564 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1565 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1566 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 1567 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1568 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1569 | // Import the name of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1570 | if (Error Err = importInto(Name, D->getDeclName())) |
| 1571 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1572 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1573 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1574 | if (Error Err = importInto(Loc, D->getLocation())) |
| 1575 | return Err; |
| 1576 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1577 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1578 | |
| 1579 | return Error::success(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1580 | } |
| 1581 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1582 | Error ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1583 | if (!FromD) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1584 | return Error::success(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1585 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1586 | if (!ToD) |
| 1587 | if (Error Err = importInto(ToD, FromD)) |
| 1588 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1589 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1590 | if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) { |
| 1591 | if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) { |
| 1592 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && |
| 1593 | !ToRecord->getDefinition()) { |
| 1594 | if (Error Err = ImportDefinition(FromRecord, ToRecord)) |
| 1595 | return Err; |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1596 | } |
| 1597 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1598 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1599 | } |
| 1600 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1601 | if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) { |
| 1602 | if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1603 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1604 | if (Error Err = ImportDefinition(FromEnum, ToEnum)) |
| 1605 | return Err; |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1606 | } |
| 1607 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1608 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1609 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1610 | |
| 1611 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1612 | } |
| 1613 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1614 | Error |
| 1615 | ASTNodeImporter::ImportDeclarationNameLoc( |
| 1616 | const DeclarationNameInfo &From, DeclarationNameInfo& To) { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1617 | // NOTE: To.Name and To.Loc are already imported. |
| 1618 | // We only have to import To.LocInfo. |
| 1619 | switch (To.getName().getNameKind()) { |
| 1620 | case DeclarationName::Identifier: |
| 1621 | case DeclarationName::ObjCZeroArgSelector: |
| 1622 | case DeclarationName::ObjCOneArgSelector: |
| 1623 | case DeclarationName::ObjCMultiArgSelector: |
| 1624 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1625 | case DeclarationName::CXXDeductionGuideName: |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1626 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1627 | |
| 1628 | case DeclarationName::CXXOperatorName: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1629 | if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange())) |
| 1630 | To.setCXXOperatorNameRange(*ToRangeOrErr); |
| 1631 | else |
| 1632 | return ToRangeOrErr.takeError(); |
| 1633 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1634 | } |
| 1635 | case DeclarationName::CXXLiteralOperatorName: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1636 | if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc())) |
| 1637 | To.setCXXLiteralOperatorNameLoc(*LocOrErr); |
| 1638 | else |
| 1639 | return LocOrErr.takeError(); |
| 1640 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1641 | } |
| 1642 | case DeclarationName::CXXConstructorName: |
| 1643 | case DeclarationName::CXXDestructorName: |
| 1644 | case DeclarationName::CXXConversionFunctionName: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1645 | if (auto ToTInfoOrErr = import(From.getNamedTypeInfo())) |
| 1646 | To.setNamedTypeInfo(*ToTInfoOrErr); |
| 1647 | else |
| 1648 | return ToTInfoOrErr.takeError(); |
| 1649 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1650 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1651 | } |
Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 1652 | llvm_unreachable("Unknown name kind."); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1653 | } |
| 1654 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1655 | Error |
| 1656 | ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1657 | if (Importer.isMinimalImport() && !ForceImport) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1658 | auto ToDCOrErr = Importer.ImportContext(FromDC); |
| 1659 | return ToDCOrErr.takeError(); |
| 1660 | } |
| 1661 | llvm::SmallVector<Decl *, 8> ImportedDecls; |
| 1662 | for (auto *From : FromDC->decls()) { |
| 1663 | ExpectedDecl ImportedOrErr = import(From); |
| 1664 | if (!ImportedOrErr) |
| 1665 | // Ignore the error, continue with next Decl. |
| 1666 | // FIXME: Handle this case somehow better. |
| 1667 | consumeError(ImportedOrErr.takeError()); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1668 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1669 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1670 | return Error::success(); |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 1671 | } |
| 1672 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1673 | Error ASTNodeImporter::ImportDeclContext( |
| 1674 | Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) { |
| 1675 | auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext()); |
| 1676 | if (!ToDCOrErr) |
| 1677 | return ToDCOrErr.takeError(); |
| 1678 | ToDC = *ToDCOrErr; |
| 1679 | |
| 1680 | if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) { |
| 1681 | auto ToLexicalDCOrErr = Importer.ImportContext( |
| 1682 | FromD->getLexicalDeclContext()); |
| 1683 | if (!ToLexicalDCOrErr) |
| 1684 | return ToLexicalDCOrErr.takeError(); |
| 1685 | ToLexicalDC = *ToLexicalDCOrErr; |
| 1686 | } else |
| 1687 | ToLexicalDC = ToDC; |
| 1688 | |
| 1689 | return Error::success(); |
| 1690 | } |
| 1691 | |
| 1692 | Error ASTNodeImporter::ImportImplicitMethods( |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1693 | const CXXRecordDecl *From, CXXRecordDecl *To) { |
| 1694 | assert(From->isCompleteDefinition() && To->getDefinition() == To && |
| 1695 | "Import implicit methods to or from non-definition"); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1696 | |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1697 | for (CXXMethodDecl *FromM : From->methods()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1698 | if (FromM->isImplicit()) { |
| 1699 | Expected<CXXMethodDecl *> ToMOrErr = import(FromM); |
| 1700 | if (!ToMOrErr) |
| 1701 | return ToMOrErr.takeError(); |
| 1702 | } |
| 1703 | |
| 1704 | return Error::success(); |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1705 | } |
| 1706 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1707 | static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, |
| 1708 | ASTImporter &Importer) { |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1709 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1710 | Decl *ToTypedef = Importer.Import(FromTypedef); |
| 1711 | if (!ToTypedef) |
| 1712 | return make_error<ImportError>(); |
| 1713 | To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(ToTypedef)); |
| 1714 | // FIXME: This should be the final code. |
| 1715 | //if (Expected<Decl *> ToTypedefOrErr = Importer.Import(FromTypedef)) |
| 1716 | // To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr)); |
| 1717 | //else |
| 1718 | // return ToTypedefOrErr.takeError(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1719 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1720 | return Error::success(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1721 | } |
| 1722 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1723 | Error ASTNodeImporter::ImportDefinition( |
| 1724 | RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1725 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1726 | if (Kind == IDK_Everything) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1727 | return ImportDeclContext(From, /*ForceImport=*/true); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1728 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1729 | return Error::success(); |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1730 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1731 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1732 | To->startDefinition(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1733 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1734 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 1735 | return Err; |
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 | // Add base classes. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1738 | if (auto *ToCXX = dyn_cast<CXXRecordDecl>(To)) { |
| 1739 | auto *FromCXX = cast<CXXRecordDecl>(From); |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1740 | |
| 1741 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); |
| 1742 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); |
| 1743 | ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1744 | ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1745 | ToData.Aggregate = FromData.Aggregate; |
| 1746 | ToData.PlainOldData = FromData.PlainOldData; |
| 1747 | ToData.Empty = FromData.Empty; |
| 1748 | ToData.Polymorphic = FromData.Polymorphic; |
| 1749 | ToData.Abstract = FromData.Abstract; |
| 1750 | ToData.IsStandardLayout = FromData.IsStandardLayout; |
Richard Smith | b6070db | 2018-04-05 18:55:37 +0000 | [diff] [blame] | 1751 | ToData.IsCXX11StandardLayout = FromData.IsCXX11StandardLayout; |
| 1752 | ToData.HasBasesWithFields = FromData.HasBasesWithFields; |
| 1753 | ToData.HasBasesWithNonStaticDataMembers = |
| 1754 | FromData.HasBasesWithNonStaticDataMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1755 | ToData.HasPrivateFields = FromData.HasPrivateFields; |
| 1756 | ToData.HasProtectedFields = FromData.HasProtectedFields; |
| 1757 | ToData.HasPublicFields = FromData.HasPublicFields; |
| 1758 | ToData.HasMutableFields = FromData.HasMutableFields; |
Richard Smith | ab44d5b | 2013-12-10 08:25:00 +0000 | [diff] [blame] | 1759 | ToData.HasVariantMembers = FromData.HasVariantMembers; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1760 | ToData.HasOnlyCMembers = FromData.HasOnlyCMembers; |
Richard Smith | e2648ba | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 1761 | ToData.HasInClassInitializer = FromData.HasInClassInitializer; |
Richard Smith | 593f993 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 1762 | ToData.HasUninitializedReferenceMember |
| 1763 | = FromData.HasUninitializedReferenceMember; |
Nico Weber | 6a6376b | 2016-02-19 01:52:46 +0000 | [diff] [blame] | 1764 | ToData.HasUninitializedFields = FromData.HasUninitializedFields; |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 1765 | ToData.HasInheritedConstructor = FromData.HasInheritedConstructor; |
| 1766 | ToData.HasInheritedAssignment = FromData.HasInheritedAssignment; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1767 | ToData.NeedOverloadResolutionForCopyConstructor |
| 1768 | = FromData.NeedOverloadResolutionForCopyConstructor; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1769 | ToData.NeedOverloadResolutionForMoveConstructor |
| 1770 | = FromData.NeedOverloadResolutionForMoveConstructor; |
| 1771 | ToData.NeedOverloadResolutionForMoveAssignment |
| 1772 | = FromData.NeedOverloadResolutionForMoveAssignment; |
| 1773 | ToData.NeedOverloadResolutionForDestructor |
| 1774 | = FromData.NeedOverloadResolutionForDestructor; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1775 | ToData.DefaultedCopyConstructorIsDeleted |
| 1776 | = FromData.DefaultedCopyConstructorIsDeleted; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1777 | ToData.DefaultedMoveConstructorIsDeleted |
| 1778 | = FromData.DefaultedMoveConstructorIsDeleted; |
| 1779 | ToData.DefaultedMoveAssignmentIsDeleted |
| 1780 | = FromData.DefaultedMoveAssignmentIsDeleted; |
| 1781 | ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1782 | ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers; |
| 1783 | ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1784 | ToData.HasConstexprNonCopyMoveConstructor |
| 1785 | = FromData.HasConstexprNonCopyMoveConstructor; |
Nico Weber | 72c57f4 | 2016-02-24 20:58:14 +0000 | [diff] [blame] | 1786 | ToData.HasDefaultedDefaultConstructor |
| 1787 | = FromData.HasDefaultedDefaultConstructor; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1788 | ToData.DefaultedDefaultConstructorIsConstexpr |
| 1789 | = FromData.DefaultedDefaultConstructorIsConstexpr; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1790 | ToData.HasConstexprDefaultConstructor |
| 1791 | = FromData.HasConstexprDefaultConstructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1792 | ToData.HasNonLiteralTypeFieldsOrBases |
| 1793 | = FromData.HasNonLiteralTypeFieldsOrBases; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1794 | // ComputedVisibleConversions not imported. |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1795 | ToData.UserProvidedDefaultConstructor |
| 1796 | = FromData.UserProvidedDefaultConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1797 | ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers; |
Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 1798 | ToData.ImplicitCopyConstructorCanHaveConstParamForVBase |
| 1799 | = FromData.ImplicitCopyConstructorCanHaveConstParamForVBase; |
| 1800 | ToData.ImplicitCopyConstructorCanHaveConstParamForNonVBase |
| 1801 | = FromData.ImplicitCopyConstructorCanHaveConstParamForNonVBase; |
Richard Smith | 1c33fe8 | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 1802 | ToData.ImplicitCopyAssignmentHasConstParam |
| 1803 | = FromData.ImplicitCopyAssignmentHasConstParam; |
| 1804 | ToData.HasDeclaredCopyConstructorWithConstParam |
| 1805 | = FromData.HasDeclaredCopyConstructorWithConstParam; |
| 1806 | ToData.HasDeclaredCopyAssignmentWithConstParam |
| 1807 | = FromData.HasDeclaredCopyAssignmentWithConstParam; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1808 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1809 | SmallVector<CXXBaseSpecifier *, 4> Bases; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1810 | for (const auto &Base1 : FromCXX->bases()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1811 | ExpectedType TyOrErr = import(Base1.getType()); |
| 1812 | if (!TyOrErr) |
| 1813 | return TyOrErr.takeError(); |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1814 | |
| 1815 | SourceLocation EllipsisLoc; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1816 | if (Base1.isPackExpansion()) { |
| 1817 | if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc())) |
| 1818 | EllipsisLoc = *LocOrErr; |
| 1819 | else |
| 1820 | return LocOrErr.takeError(); |
| 1821 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1822 | |
| 1823 | // Ensure that we have a definition for the base. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1824 | if (Error Err = |
| 1825 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl())) |
| 1826 | return Err; |
| 1827 | |
| 1828 | auto RangeOrErr = import(Base1.getSourceRange()); |
| 1829 | if (!RangeOrErr) |
| 1830 | return RangeOrErr.takeError(); |
| 1831 | |
| 1832 | auto TSIOrErr = import(Base1.getTypeSourceInfo()); |
| 1833 | if (!TSIOrErr) |
| 1834 | return TSIOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1835 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1836 | Bases.push_back( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1837 | new (Importer.getToContext()) CXXBaseSpecifier( |
| 1838 | *RangeOrErr, |
| 1839 | Base1.isVirtual(), |
| 1840 | Base1.isBaseOfClass(), |
| 1841 | Base1.getAccessSpecifierAsWritten(), |
| 1842 | *TSIOrErr, |
| 1843 | EllipsisLoc)); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1844 | } |
| 1845 | if (!Bases.empty()) |
Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1846 | ToCXX->setBases(Bases.data(), Bases.size()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1847 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1848 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1849 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1850 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 1851 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1852 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1853 | To->completeDefinition(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1854 | return Error::success(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1855 | } |
| 1856 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1857 | Error ASTNodeImporter::ImportInitializer(VarDecl *From, VarDecl *To) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1858 | if (To->getAnyInitializer()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1859 | return Error::success(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1860 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1861 | Expr *FromInit = From->getInit(); |
| 1862 | if (!FromInit) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1863 | return Error::success(); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1864 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1865 | ExpectedExpr ToInitOrErr = import(FromInit); |
| 1866 | if (!ToInitOrErr) |
| 1867 | return ToInitOrErr.takeError(); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1868 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1869 | To->setInit(*ToInitOrErr); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1870 | if (From->isInitKnownICE()) { |
| 1871 | EvaluatedStmt *Eval = To->ensureEvaluatedStmt(); |
| 1872 | Eval->CheckedICE = true; |
| 1873 | Eval->IsICE = From->isInitICE(); |
| 1874 | } |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1875 | |
| 1876 | // FIXME: Other bits to merge? |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1877 | return Error::success(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1878 | } |
| 1879 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1880 | Error ASTNodeImporter::ImportDefinition( |
| 1881 | EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1882 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1883 | if (Kind == IDK_Everything) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1884 | return ImportDeclContext(From, /*ForceImport=*/true); |
| 1885 | return Error::success(); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1886 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1887 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1888 | To->startDefinition(); |
| 1889 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1890 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 1891 | return Err; |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1892 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1893 | ExpectedType ToTypeOrErr = |
| 1894 | import(Importer.getFromContext().getTypeDeclType(From)); |
| 1895 | if (!ToTypeOrErr) |
| 1896 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1897 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1898 | ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType()); |
| 1899 | if (!ToPromotionTypeOrErr) |
| 1900 | return ToPromotionTypeOrErr.takeError(); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1901 | |
| 1902 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1903 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 1904 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1905 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1906 | // FIXME: we might need to merge the number of positive or negative bits |
| 1907 | // if the enumerator lists don't match. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1908 | To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr, |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1909 | From->getNumPositiveBits(), |
| 1910 | From->getNumNegativeBits()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1911 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1912 | } |
| 1913 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1914 | // FIXME: Remove this, use `import` instead. |
| 1915 | Expected<TemplateParameterList *> ASTNodeImporter::ImportTemplateParameterList( |
| 1916 | TemplateParameterList *Params) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1917 | SmallVector<NamedDecl *, 4> ToParams(Params->size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1918 | if (Error Err = ImportContainerChecked(*Params, ToParams)) |
| 1919 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1920 | |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1921 | Expr *ToRequiresClause; |
| 1922 | if (Expr *const R = Params->getRequiresClause()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1923 | if (Error Err = importInto(ToRequiresClause, R)) |
| 1924 | return std::move(Err); |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1925 | } else { |
| 1926 | ToRequiresClause = nullptr; |
| 1927 | } |
| 1928 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1929 | auto ToTemplateLocOrErr = import(Params->getTemplateLoc()); |
| 1930 | if (!ToTemplateLocOrErr) |
| 1931 | return ToTemplateLocOrErr.takeError(); |
| 1932 | auto ToLAngleLocOrErr = import(Params->getLAngleLoc()); |
| 1933 | if (!ToLAngleLocOrErr) |
| 1934 | return ToLAngleLocOrErr.takeError(); |
| 1935 | auto ToRAngleLocOrErr = import(Params->getRAngleLoc()); |
| 1936 | if (!ToRAngleLocOrErr) |
| 1937 | return ToRAngleLocOrErr.takeError(); |
| 1938 | |
| 1939 | return TemplateParameterList::Create( |
| 1940 | Importer.getToContext(), |
| 1941 | *ToTemplateLocOrErr, |
| 1942 | *ToLAngleLocOrErr, |
| 1943 | ToParams, |
| 1944 | *ToRAngleLocOrErr, |
| 1945 | ToRequiresClause); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1946 | } |
| 1947 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1948 | Error ASTNodeImporter::ImportTemplateArguments( |
| 1949 | const TemplateArgument *FromArgs, unsigned NumFromArgs, |
| 1950 | SmallVectorImpl<TemplateArgument> &ToArgs) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1951 | for (unsigned I = 0; I != NumFromArgs; ++I) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1952 | if (auto ToOrErr = import(FromArgs[I])) |
| 1953 | ToArgs.push_back(*ToOrErr); |
| 1954 | else |
| 1955 | return ToOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1956 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1957 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1958 | return Error::success(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1959 | } |
| 1960 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1961 | // FIXME: Do not forget to remove this and use only 'import'. |
| 1962 | Expected<TemplateArgument> |
| 1963 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { |
| 1964 | return import(From); |
| 1965 | } |
| 1966 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1967 | template <typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1968 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1969 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { |
| 1970 | for (const auto &FromLoc : Container) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1971 | if (auto ToLocOrErr = import(FromLoc)) |
| 1972 | ToTAInfo.addArgument(*ToLocOrErr); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1973 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1974 | return ToLocOrErr.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1975 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1976 | return Error::success(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1977 | } |
| 1978 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1979 | static StructuralEquivalenceKind |
| 1980 | getStructuralEquivalenceKind(const ASTImporter &Importer) { |
| 1981 | return Importer.isMinimalImport() ? StructuralEquivalenceKind::Minimal |
| 1982 | : StructuralEquivalenceKind::Default; |
| 1983 | } |
| 1984 | |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1985 | bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) { |
| 1986 | StructuralEquivalenceContext Ctx( |
| 1987 | Importer.getFromContext(), Importer.getToContext(), |
| 1988 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1989 | false, Complain); |
| 1990 | return Ctx.IsEquivalent(From, To); |
| 1991 | } |
| 1992 | |
| 1993 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1994 | RecordDecl *ToRecord, bool Complain) { |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1995 | // Eliminate a potential failure point where we attempt to re-import |
| 1996 | // something we're trying to import while completing ToRecord. |
| 1997 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); |
| 1998 | if (ToOrigin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1999 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2000 | if (ToOriginRecord) |
| 2001 | ToRecord = ToOriginRecord; |
| 2002 | } |
| 2003 | |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 2004 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2005 | ToRecord->getASTContext(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2006 | Importer.getNonEquivalentDecls(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2007 | getStructuralEquivalenceKind(Importer), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2008 | false, Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2009 | return Ctx.IsEquivalent(FromRecord, ToRecord); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2010 | } |
| 2011 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2012 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 2013 | bool Complain) { |
| 2014 | StructuralEquivalenceContext Ctx( |
| 2015 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2016 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2017 | false, Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2018 | return Ctx.IsEquivalent(FromVar, ToVar); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2019 | } |
| 2020 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2021 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2022 | StructuralEquivalenceContext Ctx( |
| 2023 | Importer.getFromContext(), Importer.getToContext(), |
| 2024 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2025 | return Ctx.IsEquivalent(FromEnum, ToEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2026 | } |
| 2027 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2028 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, |
| 2029 | FunctionTemplateDecl *To) { |
| 2030 | StructuralEquivalenceContext Ctx( |
| 2031 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2032 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2033 | false, false); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2034 | return Ctx.IsEquivalent(From, To); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2035 | } |
| 2036 | |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2037 | bool ASTNodeImporter::IsStructuralMatch(FunctionDecl *From, FunctionDecl *To) { |
| 2038 | StructuralEquivalenceContext Ctx( |
| 2039 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2040 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2041 | false, false); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2042 | return Ctx.IsEquivalent(From, To); |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2043 | } |
| 2044 | |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2045 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2046 | EnumConstantDecl *ToEC) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2047 | const llvm::APSInt &FromVal = FromEC->getInitVal(); |
| 2048 | const llvm::APSInt &ToVal = ToEC->getInitVal(); |
| 2049 | |
| 2050 | return FromVal.isSigned() == ToVal.isSigned() && |
| 2051 | FromVal.getBitWidth() == ToVal.getBitWidth() && |
| 2052 | FromVal == ToVal; |
| 2053 | } |
| 2054 | |
| 2055 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2056 | ClassTemplateDecl *To) { |
| 2057 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2058 | Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2059 | Importer.getNonEquivalentDecls(), |
| 2060 | getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2061 | return Ctx.IsEquivalent(From, To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2062 | } |
| 2063 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2064 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, |
| 2065 | VarTemplateDecl *To) { |
| 2066 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2067 | Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2068 | Importer.getNonEquivalentDecls(), |
| 2069 | getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2070 | return Ctx.IsEquivalent(From, To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2071 | } |
| 2072 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2073 | ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 2074 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2075 | << D->getDeclKindName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2076 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2077 | } |
| 2078 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2079 | ExpectedDecl ASTNodeImporter::VisitImportDecl(ImportDecl *D) { |
| 2080 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 2081 | << D->getDeclKindName(); |
| 2082 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| 2083 | } |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2084 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2085 | ExpectedDecl ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { |
| 2086 | // Import the context of this declaration. |
| 2087 | DeclContext *DC, *LexicalDC; |
| 2088 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 2089 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2090 | |
| 2091 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2092 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2093 | if (!LocOrErr) |
| 2094 | return LocOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2095 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2096 | EmptyDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2097 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2098 | return ToD; |
| 2099 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2100 | ToD->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2101 | LexicalDC->addDeclInternal(ToD); |
| 2102 | return ToD; |
| 2103 | } |
| 2104 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2105 | ExpectedDecl ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2106 | TranslationUnitDecl *ToD = |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2107 | Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2108 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2109 | Importer.MapImported(D, ToD); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2110 | |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2111 | return ToD; |
| 2112 | } |
| 2113 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2114 | ExpectedDecl ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
| 2115 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2116 | if (!LocOrErr) |
| 2117 | return LocOrErr.takeError(); |
| 2118 | auto ColonLocOrErr = import(D->getColonLoc()); |
| 2119 | if (!ColonLocOrErr) |
| 2120 | return ColonLocOrErr.takeError(); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2121 | |
| 2122 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2123 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2124 | if (!DCOrErr) |
| 2125 | return DCOrErr.takeError(); |
| 2126 | DeclContext *DC = *DCOrErr; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2127 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2128 | AccessSpecDecl *ToD; |
| 2129 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2130 | DC, *LocOrErr, *ColonLocOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2131 | return ToD; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2132 | |
| 2133 | // Lexical DeclContext and Semantic DeclContext |
| 2134 | // is always the same for the accessSpec. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2135 | ToD->setLexicalDeclContext(DC); |
| 2136 | DC->addDeclInternal(ToD); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2137 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2138 | return ToD; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2139 | } |
| 2140 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2141 | ExpectedDecl ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 2142 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2143 | if (!DCOrErr) |
| 2144 | return DCOrErr.takeError(); |
| 2145 | DeclContext *DC = *DCOrErr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2146 | DeclContext *LexicalDC = DC; |
| 2147 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2148 | SourceLocation ToLocation, ToRParenLoc; |
| 2149 | Expr *ToAssertExpr; |
| 2150 | StringLiteral *ToMessage; |
| 2151 | if (auto Imp = importSeq( |
| 2152 | D->getLocation(), D->getAssertExpr(), D->getMessage(), D->getRParenLoc())) |
| 2153 | std::tie(ToLocation, ToAssertExpr, ToMessage, ToRParenLoc) = *Imp; |
| 2154 | else |
| 2155 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2156 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2157 | StaticAssertDecl *ToD; |
| 2158 | if (GetImportedOrCreateDecl( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2159 | ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage, |
| 2160 | ToRParenLoc, D->isFailed())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2161 | return ToD; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2162 | |
| 2163 | ToD->setLexicalDeclContext(LexicalDC); |
| 2164 | LexicalDC->addDeclInternal(ToD); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2165 | return ToD; |
| 2166 | } |
| 2167 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2168 | ExpectedDecl ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2169 | // Import the major distinguishing characteristics of this namespace. |
| 2170 | DeclContext *DC, *LexicalDC; |
| 2171 | DeclarationName Name; |
| 2172 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2173 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2174 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2175 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2176 | if (ToD) |
| 2177 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2178 | |
| 2179 | NamespaceDecl *MergeWithNamespace = nullptr; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2180 | if (!Name) { |
| 2181 | // This is an anonymous namespace. Adopt an existing anonymous |
| 2182 | // namespace if we can. |
| 2183 | // FIXME: Not testable. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2184 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2185 | MergeWithNamespace = TU->getAnonymousNamespace(); |
| 2186 | else |
| 2187 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); |
| 2188 | } else { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2189 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2190 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2191 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2192 | for (auto *FoundDecl : FoundDecls) { |
| 2193 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2194 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2195 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2196 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2197 | MergeWithNamespace = FoundNS; |
| 2198 | ConflictingDecls.clear(); |
| 2199 | break; |
| 2200 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2201 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2202 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2203 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2204 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2205 | if (!ConflictingDecls.empty()) { |
John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 2206 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2207 | ConflictingDecls.data(), |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2208 | ConflictingDecls.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2209 | if (!Name) |
| 2210 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2211 | } |
| 2212 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2213 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2214 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2215 | if (!BeginLocOrErr) |
| 2216 | return BeginLocOrErr.takeError(); |
| 2217 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2218 | // Create the "to" namespace, if needed. |
| 2219 | NamespaceDecl *ToNamespace = MergeWithNamespace; |
| 2220 | if (!ToNamespace) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2221 | if (GetImportedOrCreateDecl( |
| 2222 | ToNamespace, D, Importer.getToContext(), DC, D->isInline(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2223 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2224 | /*PrevDecl=*/nullptr)) |
| 2225 | return ToNamespace; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2226 | ToNamespace->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2227 | LexicalDC->addDeclInternal(ToNamespace); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2228 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2229 | // If this is an anonymous namespace, register it as the anonymous |
| 2230 | // namespace within its context. |
| 2231 | if (!Name) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2232 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2233 | TU->setAnonymousNamespace(ToNamespace); |
| 2234 | else |
| 2235 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); |
| 2236 | } |
| 2237 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2238 | Importer.MapImported(D, ToNamespace); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2239 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2240 | if (Error Err = ImportDeclContext(D)) |
| 2241 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2242 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2243 | return ToNamespace; |
| 2244 | } |
| 2245 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2246 | ExpectedDecl ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2247 | // Import the major distinguishing characteristics of this namespace. |
| 2248 | DeclContext *DC, *LexicalDC; |
| 2249 | DeclarationName Name; |
| 2250 | SourceLocation Loc; |
| 2251 | NamedDecl *LookupD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2252 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) |
| 2253 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2254 | if (LookupD) |
| 2255 | return LookupD; |
| 2256 | |
| 2257 | // NOTE: No conflict resolution is done for namespace aliases now. |
| 2258 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2259 | SourceLocation ToNamespaceLoc, ToAliasLoc, ToTargetNameLoc; |
| 2260 | NestedNameSpecifierLoc ToQualifierLoc; |
| 2261 | NamespaceDecl *ToNamespace; |
| 2262 | if (auto Imp = importSeq( |
| 2263 | D->getNamespaceLoc(), D->getAliasLoc(), D->getQualifierLoc(), |
| 2264 | D->getTargetNameLoc(), D->getNamespace())) |
| 2265 | std::tie( |
| 2266 | ToNamespaceLoc, ToAliasLoc, ToQualifierLoc, ToTargetNameLoc, |
| 2267 | ToNamespace) = *Imp; |
| 2268 | else |
| 2269 | return Imp.takeError(); |
| 2270 | IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier()); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2271 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2272 | NamespaceAliasDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2273 | if (GetImportedOrCreateDecl( |
| 2274 | ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc, |
| 2275 | ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2276 | return ToD; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2277 | |
| 2278 | ToD->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2279 | LexicalDC->addDeclInternal(ToD); |
| 2280 | |
| 2281 | return ToD; |
| 2282 | } |
| 2283 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2284 | ExpectedDecl |
| 2285 | ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2286 | // Import the major distinguishing characteristics of this typedef. |
| 2287 | DeclContext *DC, *LexicalDC; |
| 2288 | DeclarationName Name; |
| 2289 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2290 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2291 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2292 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2293 | if (ToD) |
| 2294 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2295 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2296 | // If this typedef is not in block scope, determine whether we've |
| 2297 | // seen a typedef with the same name (that we can merge with) or any |
| 2298 | // other entity by that name (which name lookup could conflict with). |
| 2299 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2300 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2301 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2302 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2303 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2304 | for (auto *FoundDecl : FoundDecls) { |
| 2305 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2306 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2307 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2308 | if (Importer.IsStructurallyEquivalent( |
| 2309 | D->getUnderlyingType(), FoundTypedef->getUnderlyingType())) |
| 2310 | return Importer.MapImported(D, FoundTypedef); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2311 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2312 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2313 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2314 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2315 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2316 | if (!ConflictingDecls.empty()) { |
| 2317 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2318 | ConflictingDecls.data(), |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2319 | ConflictingDecls.size()); |
| 2320 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2321 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2322 | } |
| 2323 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2324 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2325 | QualType ToUnderlyingType; |
| 2326 | TypeSourceInfo *ToTypeSourceInfo; |
| 2327 | SourceLocation ToBeginLoc; |
| 2328 | if (auto Imp = importSeq( |
| 2329 | D->getUnderlyingType(), D->getTypeSourceInfo(), D->getBeginLoc())) |
| 2330 | std::tie(ToUnderlyingType, ToTypeSourceInfo, ToBeginLoc) = *Imp; |
| 2331 | else |
| 2332 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2333 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2334 | // Create the new typedef node. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2335 | // FIXME: ToUnderlyingType is not used. |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2336 | TypedefNameDecl *ToTypedef; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2337 | if (IsAlias) { |
| 2338 | if (GetImportedOrCreateDecl<TypeAliasDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2339 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2340 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2341 | return ToTypedef; |
| 2342 | } else if (GetImportedOrCreateDecl<TypedefDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2343 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2344 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2345 | return ToTypedef; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2346 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2347 | ToTypedef->setAccess(D->getAccess()); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2348 | ToTypedef->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2349 | |
| 2350 | // Templated declarations should not appear in DeclContext. |
| 2351 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; |
| 2352 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) |
| 2353 | LexicalDC->addDeclInternal(ToTypedef); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2354 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2355 | return ToTypedef; |
| 2356 | } |
| 2357 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2358 | ExpectedDecl ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2359 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); |
| 2360 | } |
| 2361 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2362 | ExpectedDecl ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2363 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); |
| 2364 | } |
| 2365 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2366 | ExpectedDecl |
| 2367 | ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2368 | // Import the major distinguishing characteristics of this typedef. |
| 2369 | DeclContext *DC, *LexicalDC; |
| 2370 | DeclarationName Name; |
| 2371 | SourceLocation Loc; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2372 | NamedDecl *FoundD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2373 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) |
| 2374 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2375 | if (FoundD) |
| 2376 | return FoundD; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2377 | |
| 2378 | // If this typedef is not in block scope, determine whether we've |
| 2379 | // seen a typedef with the same name (that we can merge with) or any |
| 2380 | // other entity by that name (which name lookup could conflict with). |
| 2381 | if (!DC->isFunctionOrMethod()) { |
| 2382 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 2383 | unsigned IDNS = Decl::IDNS_Ordinary; |
| 2384 | SmallVector<NamedDecl *, 2> FoundDecls; |
| 2385 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2386 | for (auto *FoundDecl : FoundDecls) { |
| 2387 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2388 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2389 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2390 | return Importer.MapImported(D, FoundAlias); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2391 | ConflictingDecls.push_back(FoundDecl); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2392 | } |
| 2393 | |
| 2394 | if (!ConflictingDecls.empty()) { |
| 2395 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2396 | ConflictingDecls.data(), |
| 2397 | ConflictingDecls.size()); |
| 2398 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2399 | return make_error<ImportError>(ImportError::NameConflict); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2400 | } |
| 2401 | } |
| 2402 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2403 | TemplateParameterList *ToTemplateParameters; |
| 2404 | TypeAliasDecl *ToTemplatedDecl; |
| 2405 | if (auto Imp = importSeq(D->getTemplateParameters(), D->getTemplatedDecl())) |
| 2406 | std::tie(ToTemplateParameters, ToTemplatedDecl) = *Imp; |
| 2407 | else |
| 2408 | return Imp.takeError(); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2409 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2410 | TypeAliasTemplateDecl *ToAlias; |
| 2411 | if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2412 | Name, ToTemplateParameters, ToTemplatedDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2413 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2414 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2415 | ToTemplatedDecl->setDescribedAliasTemplate(ToAlias); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2416 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2417 | ToAlias->setAccess(D->getAccess()); |
| 2418 | ToAlias->setLexicalDeclContext(LexicalDC); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2419 | LexicalDC->addDeclInternal(ToAlias); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2420 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2421 | } |
| 2422 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2423 | ExpectedDecl ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2424 | // Import the major distinguishing characteristics of this label. |
| 2425 | DeclContext *DC, *LexicalDC; |
| 2426 | DeclarationName Name; |
| 2427 | SourceLocation Loc; |
| 2428 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2429 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2430 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2431 | if (ToD) |
| 2432 | return ToD; |
| 2433 | |
| 2434 | assert(LexicalDC->isFunctionOrMethod()); |
| 2435 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2436 | LabelDecl *ToLabel; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2437 | if (D->isGnuLocal()) { |
| 2438 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2439 | if (!BeginLocOrErr) |
| 2440 | return BeginLocOrErr.takeError(); |
| 2441 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2442 | Name.getAsIdentifierInfo(), *BeginLocOrErr)) |
| 2443 | return ToLabel; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2444 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2445 | } else { |
| 2446 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2447 | Name.getAsIdentifierInfo())) |
| 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 | } |
| 2451 | |
| 2452 | Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt()); |
| 2453 | if (!ToStmtOrErr) |
| 2454 | return ToStmtOrErr.takeError(); |
| 2455 | |
| 2456 | ToLabel->setStmt(*ToStmtOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2457 | ToLabel->setLexicalDeclContext(LexicalDC); |
| 2458 | LexicalDC->addDeclInternal(ToLabel); |
| 2459 | return ToLabel; |
| 2460 | } |
| 2461 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2462 | ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2463 | // Import the major distinguishing characteristics of this enum. |
| 2464 | DeclContext *DC, *LexicalDC; |
| 2465 | DeclarationName Name; |
| 2466 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2467 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2468 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2469 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2470 | if (ToD) |
| 2471 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2472 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2473 | // Figure out what enum name we're looking for. |
| 2474 | unsigned IDNS = Decl::IDNS_Tag; |
| 2475 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2476 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2477 | if (Error Err = importInto( |
| 2478 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2479 | return std::move(Err); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2480 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2481 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2482 | IDNS |= Decl::IDNS_Ordinary; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2483 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2484 | // We may already have an enum of the same name; try to find and match it. |
| 2485 | if (!DC->isFunctionOrMethod() && SearchName) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2486 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2487 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 2488 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2489 | for (auto *FoundDecl : FoundDecls) { |
| 2490 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2491 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2492 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2493 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2494 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2495 | FoundDecl = Tag->getDecl(); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2496 | } |
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 *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) { |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2499 | if (IsStructuralMatch(D, FoundEnum)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2500 | return Importer.MapImported(D, FoundEnum); |
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 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2503 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2504 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2505 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2506 | if (!ConflictingDecls.empty()) { |
| 2507 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2508 | ConflictingDecls.data(), |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2509 | ConflictingDecls.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2510 | if (!Name) |
| 2511 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2512 | } |
| 2513 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2514 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2515 | SourceLocation ToBeginLoc; |
| 2516 | NestedNameSpecifierLoc ToQualifierLoc; |
| 2517 | QualType ToIntegerType; |
| 2518 | if (auto Imp = importSeq( |
| 2519 | D->getBeginLoc(), D->getQualifierLoc(), D->getIntegerType())) |
| 2520 | std::tie(ToBeginLoc, ToQualifierLoc, ToIntegerType) = *Imp; |
| 2521 | else |
| 2522 | return Imp.takeError(); |
| 2523 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2524 | // Create the enum declaration. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2525 | EnumDecl *D2; |
| 2526 | if (GetImportedOrCreateDecl( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2527 | D2, D, Importer.getToContext(), DC, ToBeginLoc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2528 | Loc, Name.getAsIdentifierInfo(), nullptr, D->isScoped(), |
| 2529 | D->isScopedUsingClassTag(), D->isFixed())) |
| 2530 | return D2; |
| 2531 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2532 | D2->setQualifierInfo(ToQualifierLoc); |
| 2533 | D2->setIntegerType(ToIntegerType); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2534 | D2->setAccess(D->getAccess()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2535 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2536 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2537 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2538 | // Import the definition |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2539 | if (D->isCompleteDefinition()) |
| 2540 | if (Error Err = ImportDefinition(D, D2)) |
| 2541 | return std::move(Err); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2542 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2543 | return D2; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2544 | } |
| 2545 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2546 | ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2547 | bool IsFriendTemplate = false; |
| 2548 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2549 | IsFriendTemplate = |
| 2550 | DCXX->getDescribedClassTemplate() && |
| 2551 | DCXX->getDescribedClassTemplate()->getFriendObjectKind() != |
| 2552 | Decl::FOK_None; |
| 2553 | } |
| 2554 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2555 | // If this record has a definition in the translation unit we're coming from, |
| 2556 | // but this particular declaration is not that definition, import the |
| 2557 | // definition and map to that. |
Douglas Gregor | 0a5a221 | 2010-02-11 01:04:33 +0000 | [diff] [blame] | 2558 | TagDecl *Definition = D->getDefinition(); |
Gabor Marton | a3af567 | 2018-05-23 14:24:02 +0000 | [diff] [blame] | 2559 | if (Definition && Definition != D && |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2560 | // Friend template declaration must be imported on its own. |
| 2561 | !IsFriendTemplate && |
Gabor Marton | a3af567 | 2018-05-23 14:24:02 +0000 | [diff] [blame] | 2562 | // In contrast to a normal CXXRecordDecl, the implicit |
| 2563 | // CXXRecordDecl of ClassTemplateSpecializationDecl is its redeclaration. |
| 2564 | // The definition of the implicit CXXRecordDecl in this case is the |
| 2565 | // ClassTemplateSpecializationDecl itself. Thus, we start with an extra |
| 2566 | // condition in order to be able to import the implict Decl. |
| 2567 | !D->isImplicit()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2568 | ExpectedDecl ImportedDefOrErr = import(Definition); |
| 2569 | if (!ImportedDefOrErr) |
| 2570 | return ImportedDefOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2571 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2572 | return Importer.MapImported(D, *ImportedDefOrErr); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2573 | } |
Gabor Marton | a3af567 | 2018-05-23 14:24:02 +0000 | [diff] [blame] | 2574 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2575 | // Import the major distinguishing characteristics of this record. |
| 2576 | DeclContext *DC, *LexicalDC; |
| 2577 | DeclarationName Name; |
| 2578 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2579 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2580 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2581 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2582 | if (ToD) |
| 2583 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2584 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2585 | // Figure out what structure name we're looking for. |
| 2586 | unsigned IDNS = Decl::IDNS_Tag; |
| 2587 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2588 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2589 | if (Error Err = importInto( |
| 2590 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2591 | return std::move(Err); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2592 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2593 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2594 | IDNS |= Decl::IDNS_Ordinary; |
| 2595 | |
| 2596 | // 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] | 2597 | RecordDecl *AdoptDecl = nullptr; |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2598 | RecordDecl *PrevDecl = nullptr; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2599 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2600 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2601 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 2602 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2603 | |
| 2604 | if (!FoundDecls.empty()) { |
| 2605 | // We're going to have to compare D against potentially conflicting Decls, so complete it. |
| 2606 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) |
| 2607 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 2608 | } |
| 2609 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2610 | for (auto *FoundDecl : FoundDecls) { |
| 2611 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2612 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2613 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2614 | Decl *Found = FoundDecl; |
| 2615 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 2616 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2617 | Found = Tag->getDecl(); |
| 2618 | } |
Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2619 | |
| 2620 | if (D->getDescribedTemplate()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2621 | if (auto *Template = dyn_cast<ClassTemplateDecl>(Found)) { |
Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2622 | Found = Template->getTemplatedDecl(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2623 | } else { |
| 2624 | ConflictingDecls.push_back(FoundDecl); |
Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2625 | continue; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2626 | } |
Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2627 | } |
| 2628 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2629 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { |
Aleksei Sidorin | 499de6c | 2018-04-05 15:31:49 +0000 | [diff] [blame] | 2630 | if (!SearchName) { |
Gabor Marton | 0bebf95 | 2018-07-05 09:51:13 +0000 | [diff] [blame] | 2631 | if (!IsStructuralMatch(D, FoundRecord, false)) |
| 2632 | continue; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2633 | } else { |
| 2634 | if (!IsStructuralMatch(D, FoundRecord)) { |
| 2635 | ConflictingDecls.push_back(FoundDecl); |
| 2636 | continue; |
| 2637 | } |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2638 | } |
| 2639 | |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2640 | PrevDecl = FoundRecord; |
| 2641 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2642 | if (RecordDecl *FoundDef = FoundRecord->getDefinition()) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2643 | if ((SearchName && !D->isCompleteDefinition() && !IsFriendTemplate) |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2644 | || (D->isCompleteDefinition() && |
| 2645 | D->isAnonymousStructOrUnion() |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2646 | == FoundDef->isAnonymousStructOrUnion())) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2647 | // The record types structurally match, or the "from" translation |
| 2648 | // unit only had a forward declaration anyway; call it the same |
| 2649 | // function. |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2650 | // FIXME: Structural equivalence check should check for same |
| 2651 | // user-defined methods. |
| 2652 | Importer.MapImported(D, FoundDef); |
| 2653 | if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2654 | auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef); |
| 2655 | assert(FoundCXX && "Record type mismatch"); |
| 2656 | |
| 2657 | if (D->isCompleteDefinition() && !Importer.isMinimalImport()) |
| 2658 | // FoundDef may not have every implicit method that D has |
| 2659 | // because implicit methods are created only if they are used. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2660 | if (Error Err = ImportImplicitMethods(DCXX, FoundCXX)) |
| 2661 | return std::move(Err); |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2662 | } |
| 2663 | return FoundDef; |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2664 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2665 | if (IsFriendTemplate) |
| 2666 | continue; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2667 | } else if (!D->isCompleteDefinition()) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2668 | // We have a forward declaration of this type, so adopt that forward |
| 2669 | // declaration rather than building a new one. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2670 | |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 2671 | // If one or both can be completed from external storage then try one |
| 2672 | // last time to complete and compare them before doing this. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2673 | |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 2674 | if (FoundRecord->hasExternalLexicalStorage() && |
| 2675 | !FoundRecord->isCompleteDefinition()) |
| 2676 | FoundRecord->getASTContext().getExternalSource()->CompleteType(FoundRecord); |
| 2677 | if (D->hasExternalLexicalStorage()) |
| 2678 | D->getASTContext().getExternalSource()->CompleteType(D); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2679 | |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 2680 | if (FoundRecord->isCompleteDefinition() && |
| 2681 | D->isCompleteDefinition() && |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2682 | !IsStructuralMatch(D, FoundRecord)) { |
| 2683 | ConflictingDecls.push_back(FoundDecl); |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 2684 | continue; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2685 | } |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2686 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2687 | AdoptDecl = FoundRecord; |
| 2688 | continue; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2689 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2690 | |
| 2691 | continue; |
| 2692 | } else if (isa<ValueDecl>(Found)) |
| 2693 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2694 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2695 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2696 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2697 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2698 | if (!ConflictingDecls.empty() && SearchName) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2699 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2700 | ConflictingDecls.data(), |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2701 | ConflictingDecls.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2702 | if (!Name) |
| 2703 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2704 | } |
| 2705 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2706 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2707 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2708 | if (!BeginLocOrErr) |
| 2709 | return BeginLocOrErr.takeError(); |
| 2710 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2711 | // Create the record declaration. |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2712 | RecordDecl *D2 = AdoptDecl; |
| 2713 | if (!D2) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2714 | CXXRecordDecl *D2CXX = nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2715 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2716 | if (DCXX->isLambda()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2717 | auto TInfoOrErr = import(DCXX->getLambdaTypeInfo()); |
| 2718 | if (!TInfoOrErr) |
| 2719 | return TInfoOrErr.takeError(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2720 | if (GetImportedOrCreateSpecialDecl( |
| 2721 | D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2722 | DC, *TInfoOrErr, Loc, DCXX->isDependentLambda(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2723 | DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault())) |
| 2724 | return D2CXX; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2725 | ExpectedDecl CDeclOrErr = import(DCXX->getLambdaContextDecl()); |
| 2726 | if (!CDeclOrErr) |
| 2727 | return CDeclOrErr.takeError(); |
| 2728 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), *CDeclOrErr); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2729 | } else if (DCXX->isInjectedClassName()) { |
| 2730 | // We have to be careful to do a similar dance to the one in |
| 2731 | // Sema::ActOnStartCXXMemberDeclarations |
| 2732 | CXXRecordDecl *const PrevDecl = nullptr; |
| 2733 | const bool DelayTypeCreation = true; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2734 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2735 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2736 | Name.getAsIdentifierInfo(), PrevDecl, |
| 2737 | DelayTypeCreation)) |
| 2738 | return D2CXX; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2739 | Importer.getToContext().getTypeDeclType( |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2740 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2741 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2742 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2743 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2744 | Name.getAsIdentifierInfo(), |
| 2745 | cast_or_null<CXXRecordDecl>(PrevDecl))) |
| 2746 | return D2CXX; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2747 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2748 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2749 | D2 = D2CXX; |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2750 | D2->setAccess(D->getAccess()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2751 | D2->setLexicalDeclContext(LexicalDC); |
Gabor Marton | de8bf26 | 2018-05-17 09:46:07 +0000 | [diff] [blame] | 2752 | if (!DCXX->getDescribedClassTemplate() || DCXX->isImplicit()) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2753 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2754 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2755 | if (ClassTemplateDecl *FromDescribed = |
| 2756 | DCXX->getDescribedClassTemplate()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2757 | ClassTemplateDecl *ToDescribed; |
| 2758 | if (Error Err = importInto(ToDescribed, FromDescribed)) |
| 2759 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2760 | D2CXX->setDescribedClassTemplate(ToDescribed); |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2761 | if (!DCXX->isInjectedClassName() && !IsFriendTemplate) { |
Gabor Marton | 5915777e | 2018-06-26 13:44:24 +0000 | [diff] [blame] | 2762 | // In a record describing a template the type should be an |
| 2763 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the |
| 2764 | // previously set type to the correct value here (ToDescribed is not |
| 2765 | // available at record create). |
| 2766 | // FIXME: The previous type is cleared but not removed from |
| 2767 | // ASTContext's internal storage. |
| 2768 | CXXRecordDecl *Injected = nullptr; |
| 2769 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { |
| 2770 | auto *Record = dyn_cast<CXXRecordDecl>(Found); |
| 2771 | if (Record && Record->isInjectedClassName()) { |
| 2772 | Injected = Record; |
| 2773 | break; |
| 2774 | } |
| 2775 | } |
| 2776 | D2CXX->setTypeForDecl(nullptr); |
| 2777 | Importer.getToContext().getInjectedClassNameType(D2CXX, |
| 2778 | ToDescribed->getInjectedClassNameSpecialization()); |
| 2779 | if (Injected) { |
| 2780 | Injected->setTypeForDecl(nullptr); |
| 2781 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); |
| 2782 | } |
| 2783 | } |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2784 | } else if (MemberSpecializationInfo *MemberInfo = |
| 2785 | DCXX->getMemberSpecializationInfo()) { |
| 2786 | TemplateSpecializationKind SK = |
| 2787 | MemberInfo->getTemplateSpecializationKind(); |
| 2788 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2789 | |
| 2790 | if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst)) |
| 2791 | D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK); |
| 2792 | else |
| 2793 | return ToInstOrErr.takeError(); |
| 2794 | |
| 2795 | if (ExpectedSLoc POIOrErr = |
| 2796 | import(MemberInfo->getPointOfInstantiation())) |
| 2797 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( |
| 2798 | *POIOrErr); |
| 2799 | else |
| 2800 | return POIOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2801 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2802 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2803 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2804 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2805 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2806 | Name.getAsIdentifierInfo(), PrevDecl)) |
| 2807 | return D2; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2808 | D2->setLexicalDeclContext(LexicalDC); |
| 2809 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2810 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2811 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2812 | if (auto QualifierLocOrErr = import(D->getQualifierLoc())) |
| 2813 | D2->setQualifierInfo(*QualifierLocOrErr); |
| 2814 | else |
| 2815 | return QualifierLocOrErr.takeError(); |
| 2816 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2817 | if (D->isAnonymousStructOrUnion()) |
| 2818 | D2->setAnonymousStructOrUnion(true); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2819 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2820 | |
| 2821 | Importer.MapImported(D, D2); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2822 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2823 | if (D->isCompleteDefinition()) |
| 2824 | if (Error Err = ImportDefinition(D, D2, IDK_Default)) |
| 2825 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2826 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2827 | return D2; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2828 | } |
| 2829 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2830 | ExpectedDecl ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2831 | // Import the major distinguishing characteristics of this enumerator. |
| 2832 | DeclContext *DC, *LexicalDC; |
| 2833 | DeclarationName Name; |
| 2834 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2835 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2836 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2837 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2838 | if (ToD) |
| 2839 | return ToD; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2840 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2841 | // Determine whether there are any other declarations with the same name and |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2842 | // in the same context. |
| 2843 | if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2844 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2845 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2846 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2847 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2848 | for (auto *FoundDecl : FoundDecls) { |
| 2849 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2850 | continue; |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2851 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2852 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2853 | if (IsStructuralMatch(D, FoundEnumConstant)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2854 | return Importer.MapImported(D, FoundEnumConstant); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2855 | } |
| 2856 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2857 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2858 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2859 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2860 | if (!ConflictingDecls.empty()) { |
| 2861 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2862 | ConflictingDecls.data(), |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2863 | ConflictingDecls.size()); |
| 2864 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2865 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2866 | } |
| 2867 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2868 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2869 | ExpectedType TypeOrErr = import(D->getType()); |
| 2870 | if (!TypeOrErr) |
| 2871 | return TypeOrErr.takeError(); |
| 2872 | |
| 2873 | ExpectedExpr InitOrErr = import(D->getInitExpr()); |
| 2874 | if (!InitOrErr) |
| 2875 | return InitOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2876 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2877 | EnumConstantDecl *ToEnumerator; |
| 2878 | if (GetImportedOrCreateDecl( |
| 2879 | ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2880 | Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2881 | return ToEnumerator; |
| 2882 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2883 | ToEnumerator->setAccess(D->getAccess()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2884 | ToEnumerator->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2885 | LexicalDC->addDeclInternal(ToEnumerator); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2886 | return ToEnumerator; |
| 2887 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2888 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2889 | Error ASTNodeImporter::ImportTemplateInformation( |
| 2890 | FunctionDecl *FromFD, FunctionDecl *ToFD) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2891 | switch (FromFD->getTemplatedKind()) { |
| 2892 | case FunctionDecl::TK_NonTemplate: |
| 2893 | case FunctionDecl::TK_FunctionTemplate: |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2894 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2895 | |
| 2896 | case FunctionDecl::TK_MemberSpecialization: { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2897 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2898 | |
| 2899 | if (Expected<FunctionDecl *> InstFDOrErr = |
| 2900 | import(FromFD->getInstantiatedFromMemberFunction())) |
| 2901 | ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK); |
| 2902 | else |
| 2903 | return InstFDOrErr.takeError(); |
| 2904 | |
| 2905 | if (ExpectedSLoc POIOrErr = import( |
| 2906 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation())) |
| 2907 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr); |
| 2908 | else |
| 2909 | return POIOrErr.takeError(); |
| 2910 | |
| 2911 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2912 | } |
| 2913 | |
| 2914 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2915 | auto FunctionAndArgsOrErr = |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2916 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2917 | if (!FunctionAndArgsOrErr) |
| 2918 | return FunctionAndArgsOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2919 | |
| 2920 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2921 | Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr)); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2922 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2923 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2924 | TemplateArgumentListInfo ToTAInfo; |
| 2925 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2926 | if (FromTAArgsAsWritten) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2927 | if (Error Err = ImportTemplateArgumentListInfo( |
| 2928 | *FromTAArgsAsWritten, ToTAInfo)) |
| 2929 | return Err; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2930 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2931 | ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation()); |
| 2932 | if (!POIOrErr) |
| 2933 | return POIOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2934 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2935 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2936 | ToFD->setFunctionTemplateSpecialization( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2937 | std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr, |
| 2938 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr); |
| 2939 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2940 | } |
| 2941 | |
| 2942 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 2943 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); |
| 2944 | UnresolvedSet<8> TemplDecls; |
| 2945 | unsigned NumTemplates = FromInfo->getNumTemplates(); |
| 2946 | for (unsigned I = 0; I < NumTemplates; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2947 | if (Expected<FunctionTemplateDecl *> ToFTDOrErr = |
| 2948 | import(FromInfo->getTemplate(I))) |
| 2949 | TemplDecls.addDecl(*ToFTDOrErr); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2950 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2951 | return ToFTDOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2952 | } |
| 2953 | |
| 2954 | // Import TemplateArgumentListInfo. |
| 2955 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2956 | if (Error Err = ImportTemplateArgumentListInfo( |
| 2957 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), |
| 2958 | llvm::makeArrayRef( |
| 2959 | FromInfo->getTemplateArgs(), FromInfo->getNumTemplateArgs()), |
| 2960 | ToTAInfo)) |
| 2961 | return Err; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2962 | |
| 2963 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), |
| 2964 | TemplDecls, ToTAInfo); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2965 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2966 | } |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2967 | } |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2968 | llvm_unreachable("All cases should be covered!"); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2969 | } |
| 2970 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2971 | Expected<FunctionDecl *> |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2972 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2973 | auto FunctionAndArgsOrErr = |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2974 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2975 | if (!FunctionAndArgsOrErr) |
| 2976 | return FunctionAndArgsOrErr.takeError(); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2977 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2978 | FunctionTemplateDecl *Template; |
| 2979 | TemplateArgsTy ToTemplArgs; |
| 2980 | std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2981 | void *InsertPos = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2982 | auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2983 | return FoundSpec; |
| 2984 | } |
| 2985 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2986 | ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2987 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2988 | SmallVector<Decl *, 2> Redecls = getCanonicalForwardRedeclChain(D); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2989 | auto RedeclIt = Redecls.begin(); |
| 2990 | // Import the first part of the decl chain. I.e. import all previous |
| 2991 | // declarations starting from the canonical decl. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2992 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 2993 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 2994 | if (!ToRedeclOrErr) |
| 2995 | return ToRedeclOrErr.takeError(); |
| 2996 | } |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2997 | assert(*RedeclIt == D); |
| 2998 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2999 | // Import the major distinguishing characteristics of this function. |
| 3000 | DeclContext *DC, *LexicalDC; |
| 3001 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3002 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3003 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3004 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3005 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3006 | if (ToD) |
| 3007 | return ToD; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3008 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3009 | const FunctionDecl *FoundByLookup = nullptr; |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3010 | FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 3011 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3012 | // If this is a function template specialization, then try to find the same |
| 3013 | // existing specialization in the "to" context. The localUncachedLookup |
| 3014 | // below will not find any specialization, but would find the primary |
| 3015 | // template; thus, we have to skip normal lookup in case of specializations. |
| 3016 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? |
| 3017 | if (D->getTemplatedKind() == |
| 3018 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3019 | auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D); |
| 3020 | if (!FoundFunctionOrErr) |
| 3021 | return FoundFunctionOrErr.takeError(); |
| 3022 | if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) { |
| 3023 | if (D->doesThisDeclarationHaveABody() && FoundFunction->hasBody()) |
| 3024 | return Importer.MapImported(D, FoundFunction); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3025 | FoundByLookup = FoundFunction; |
| 3026 | } |
| 3027 | } |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3028 | // Try to find a function in our own ("to") context with the same name, same |
| 3029 | // type, and in the same context as the function we're importing. |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3030 | else if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3031 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3032 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3033 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3034 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3035 | for (auto *FoundDecl : FoundDecls) { |
| 3036 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3037 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3038 | |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3039 | // If template was found, look at the templated function. |
| 3040 | if (FromFT) { |
| 3041 | if (auto *Template = dyn_cast<FunctionTemplateDecl>(FoundDecl)) |
| 3042 | FoundDecl = Template->getTemplatedDecl(); |
| 3043 | else |
| 3044 | continue; |
| 3045 | } |
| 3046 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3047 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { |
Rafael Espindola | 3ae0005 | 2013-05-13 00:12:11 +0000 | [diff] [blame] | 3048 | if (FoundFunction->hasExternalFormalLinkage() && |
| 3049 | D->hasExternalFormalLinkage()) { |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 3050 | if (IsStructuralMatch(D, FoundFunction)) { |
| 3051 | const FunctionDecl *Definition = nullptr; |
| 3052 | if (D->doesThisDeclarationHaveABody() && |
| 3053 | FoundFunction->hasBody(Definition)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3054 | return Importer.MapImported( |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 3055 | D, const_cast<FunctionDecl *>(Definition)); |
| 3056 | } |
| 3057 | FoundByLookup = FoundFunction; |
| 3058 | break; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3059 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3060 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3061 | // FIXME: Check for overloading more carefully, e.g., by boosting |
| 3062 | // Sema::IsOverload out to the AST library. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3063 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3064 | // Function overloading is okay in C++. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3065 | if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3066 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3067 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3068 | // Complain about inconsistent function types. |
| 3069 | Importer.ToDiag(Loc, diag::err_odr_function_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3070 | << Name << D->getType() << FoundFunction->getType(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3071 | Importer.ToDiag(FoundFunction->getLocation(), |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3072 | diag::note_odr_value_here) |
| 3073 | << FoundFunction->getType(); |
| 3074 | } |
| 3075 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3076 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3077 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3078 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3079 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3080 | if (!ConflictingDecls.empty()) { |
| 3081 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3082 | ConflictingDecls.data(), |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3083 | ConflictingDecls.size()); |
| 3084 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3085 | return make_error<ImportError>(ImportError::NameConflict); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3086 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3087 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3088 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3089 | DeclarationNameInfo NameInfo(Name, Loc); |
| 3090 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3091 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 3092 | return std::move(Err); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3093 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3094 | QualType FromTy = D->getType(); |
| 3095 | bool usedDifferentExceptionSpec = false; |
| 3096 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3097 | if (const auto *FromFPT = D->getType()->getAs<FunctionProtoType>()) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3098 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); |
| 3099 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the |
| 3100 | // FunctionDecl that we are importing the FunctionProtoType for. |
| 3101 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| 3102 | // with a simplified function type and update it afterwards. |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 3103 | if (FromEPI.ExceptionSpec.SourceDecl || |
| 3104 | FromEPI.ExceptionSpec.SourceTemplate || |
| 3105 | FromEPI.ExceptionSpec.NoexceptExpr) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3106 | FunctionProtoType::ExtProtoInfo DefaultEPI; |
| 3107 | FromTy = Importer.getFromContext().getFunctionType( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3108 | FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI); |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3109 | usedDifferentExceptionSpec = true; |
| 3110 | } |
| 3111 | } |
| 3112 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3113 | QualType T; |
| 3114 | TypeSourceInfo *TInfo; |
| 3115 | SourceLocation ToInnerLocStart, ToEndLoc; |
| 3116 | NestedNameSpecifierLoc ToQualifierLoc; |
| 3117 | if (auto Imp = importSeq( |
| 3118 | FromTy, D->getTypeSourceInfo(), D->getInnerLocStart(), |
| 3119 | D->getQualifierLoc(), D->getEndLoc())) |
| 3120 | std::tie(T, TInfo, ToInnerLocStart, ToQualifierLoc, ToEndLoc) = *Imp; |
| 3121 | else |
| 3122 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3123 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3124 | // Import the function parameters. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3125 | SmallVector<ParmVarDecl *, 8> Parameters; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3126 | for (auto P : D->parameters()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3127 | if (Expected<ParmVarDecl *> ToPOrErr = import(P)) |
| 3128 | Parameters.push_back(*ToPOrErr); |
| 3129 | else |
| 3130 | return ToPOrErr.takeError(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3131 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3132 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3133 | // Create the imported function. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3134 | FunctionDecl *ToFunction = nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3135 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3136 | if (GetImportedOrCreateDecl<CXXConstructorDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3137 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3138 | ToInnerLocStart, NameInfo, T, TInfo, |
| 3139 | FromConstructor->isExplicit(), |
| 3140 | D->isInlineSpecified(), D->isImplicit(), D->isConstexpr())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3141 | return ToFunction; |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 3142 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3143 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers); |
| 3144 | // Import first, then allocate memory and copy if there was no error. |
| 3145 | if (Error Err = ImportContainerChecked( |
| 3146 | FromConstructor->inits(), CtorInitializers)) |
| 3147 | return std::move(Err); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3148 | auto **Memory = |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 3149 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 3150 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3151 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 3152 | ToCtor->setCtorInitializers(Memory); |
| 3153 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 3154 | } |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3155 | } else if (isa<CXXDestructorDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3156 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3157 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3158 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| 3159 | D->isImplicit())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3160 | return ToFunction; |
| 3161 | } else if (CXXConversionDecl *FromConversion = |
| 3162 | dyn_cast<CXXConversionDecl>(D)) { |
| 3163 | if (GetImportedOrCreateDecl<CXXConversionDecl>( |
| 3164 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3165 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3166 | FromConversion->isExplicit(), D->isConstexpr(), SourceLocation())) |
| 3167 | return ToFunction; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3168 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3169 | if (GetImportedOrCreateDecl<CXXMethodDecl>( |
| 3170 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3171 | ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3172 | Method->isInlineSpecified(), D->isConstexpr(), SourceLocation())) |
| 3173 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3174 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3175 | if (GetImportedOrCreateDecl(ToFunction, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3176 | ToInnerLocStart, NameInfo, T, TInfo, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3177 | D->getStorageClass(), D->isInlineSpecified(), |
| 3178 | D->hasWrittenPrototype(), D->isConstexpr())) |
| 3179 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3180 | } |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3181 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3182 | ToFunction->setQualifierInfo(ToQualifierLoc); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3183 | ToFunction->setAccess(D->getAccess()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3184 | ToFunction->setLexicalDeclContext(LexicalDC); |
John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 3185 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 3186 | ToFunction->setTrivial(D->isTrivial()); |
| 3187 | ToFunction->setPure(D->isPure()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3188 | ToFunction->setRangeEnd(ToEndLoc); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3189 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3190 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3191 | for (auto *Param : Parameters) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3192 | Param->setOwningFunction(ToFunction); |
| 3193 | ToFunction->addDeclInternal(Param); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3194 | } |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 3195 | ToFunction->setParams(Parameters); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3196 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3197 | if (FoundByLookup) { |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 3198 | auto *Recent = const_cast<FunctionDecl *>( |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3199 | FoundByLookup->getMostRecentDecl()); |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 3200 | ToFunction->setPreviousDecl(Recent); |
| 3201 | } |
| 3202 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3203 | // We need to complete creation of FunctionProtoTypeLoc manually with setting |
| 3204 | // params it refers to. |
| 3205 | if (TInfo) { |
| 3206 | if (auto ProtoLoc = |
| 3207 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { |
| 3208 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) |
| 3209 | ProtoLoc.setParam(I, Parameters[I]); |
| 3210 | } |
| 3211 | } |
| 3212 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3213 | if (usedDifferentExceptionSpec) { |
| 3214 | // Update FunctionProtoType::ExtProtoInfo. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3215 | if (ExpectedType TyOrErr = import(D->getType())) |
| 3216 | ToFunction->setType(*TyOrErr); |
| 3217 | else |
| 3218 | return TyOrErr.takeError(); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 3219 | } |
| 3220 | |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3221 | // Import the describing template function, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3222 | if (FromFT) { |
| 3223 | auto ToFTOrErr = import(FromFT); |
| 3224 | if (!ToFTOrErr) |
| 3225 | return ToFTOrErr.takeError(); |
| 3226 | } |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3227 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3228 | if (D->doesThisDeclarationHaveABody()) { |
| 3229 | if (Stmt *FromBody = D->getBody()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3230 | if (ExpectedStmt ToBodyOrErr = import(FromBody)) |
| 3231 | ToFunction->setBody(*ToBodyOrErr); |
| 3232 | else |
| 3233 | return ToBodyOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3234 | } |
| 3235 | } |
| 3236 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3237 | // FIXME: Other bits to merge? |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3238 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3239 | // If it is a template, import all related things. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3240 | if (Error Err = ImportTemplateInformation(D, ToFunction)) |
| 3241 | return std::move(Err); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3242 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3243 | bool IsFriend = D->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend); |
| 3244 | |
| 3245 | // TODO Can we generalize this approach to other AST nodes as well? |
| 3246 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 3247 | DC->addDeclInternal(ToFunction); |
| 3248 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3249 | LexicalDC->addDeclInternal(ToFunction); |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3250 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3251 | // Friend declaration's lexical context is the befriending class, but the |
| 3252 | // semantic context is the enclosing scope of the befriending class. |
| 3253 | // We want the friend functions to be found in the semantic context by lookup. |
| 3254 | // FIXME should we handle this generically in VisitFriendDecl? |
| 3255 | // In Other cases when LexicalDC != DC we don't want it to be added, |
| 3256 | // e.g out-of-class definitions like void B::f() {} . |
| 3257 | if (LexicalDC != DC && IsFriend) { |
| 3258 | DC->makeDeclVisibleInContext(ToFunction); |
| 3259 | } |
| 3260 | |
Gabor Marton | 7a0841e | 2018-10-29 10:18:28 +0000 | [diff] [blame] | 3261 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) |
| 3262 | ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod); |
| 3263 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3264 | // Import the rest of the chain. I.e. import all subsequent declarations. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3265 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3266 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 3267 | if (!ToRedeclOrErr) |
| 3268 | return ToRedeclOrErr.takeError(); |
| 3269 | } |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3270 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3271 | return ToFunction; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3272 | } |
| 3273 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3274 | ExpectedDecl ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3275 | return VisitFunctionDecl(D); |
| 3276 | } |
| 3277 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3278 | ExpectedDecl ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3279 | return VisitCXXMethodDecl(D); |
| 3280 | } |
| 3281 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3282 | ExpectedDecl ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3283 | return VisitCXXMethodDecl(D); |
| 3284 | } |
| 3285 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3286 | ExpectedDecl ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3287 | return VisitCXXMethodDecl(D); |
| 3288 | } |
| 3289 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3290 | ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3291 | // Import the major distinguishing characteristics of a variable. |
| 3292 | DeclContext *DC, *LexicalDC; |
| 3293 | DeclarationName Name; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3294 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3295 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3296 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3297 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3298 | if (ToD) |
| 3299 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3300 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3301 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3302 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3303 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3304 | for (auto *FoundDecl : FoundDecls) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3305 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3306 | // For anonymous fields, match up by index. |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3307 | if (!Name && |
| 3308 | ASTImporter::getFieldIndex(D) != |
| 3309 | ASTImporter::getFieldIndex(FoundField)) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3310 | continue; |
| 3311 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3312 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3313 | FoundField->getType())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3314 | Importer.MapImported(D, FoundField); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3315 | // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the |
| 3316 | // initializer of a FieldDecl might not had been instantiated in the |
| 3317 | // "To" context. However, the "From" context might instantiated that, |
| 3318 | // thus we have to merge that. |
| 3319 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
| 3320 | // We don't have yet the initializer set. |
| 3321 | if (FoundField->hasInClassInitializer() && |
| 3322 | !FoundField->getInClassInitializer()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3323 | if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) |
| 3324 | FoundField->setInClassInitializer(*ToInitializerOrErr); |
| 3325 | else { |
| 3326 | // We can't return error here, |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3327 | // since we already mapped D as imported. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3328 | // FIXME: warning message? |
| 3329 | consumeError(ToInitializerOrErr.takeError()); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3330 | return FoundField; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3331 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3332 | } |
| 3333 | } |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3334 | return FoundField; |
| 3335 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3336 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3337 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3338 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 3339 | << Name << D->getType() << FoundField->getType(); |
| 3340 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3341 | << FoundField->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3342 | |
| 3343 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3344 | } |
| 3345 | } |
| 3346 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3347 | QualType ToType; |
| 3348 | TypeSourceInfo *ToTInfo; |
| 3349 | Expr *ToBitWidth; |
| 3350 | SourceLocation ToInnerLocStart; |
| 3351 | Expr *ToInitializer; |
| 3352 | if (auto Imp = importSeq( |
| 3353 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), |
| 3354 | D->getInnerLocStart(), D->getInClassInitializer())) |
| 3355 | std::tie( |
| 3356 | ToType, ToTInfo, ToBitWidth, ToInnerLocStart, ToInitializer) = *Imp; |
| 3357 | else |
| 3358 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3359 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3360 | FieldDecl *ToField; |
| 3361 | if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3362 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3363 | ToType, ToTInfo, ToBitWidth, D->isMutable(), |
| 3364 | D->getInClassInitStyle())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3365 | return ToField; |
| 3366 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3367 | ToField->setAccess(D->getAccess()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3368 | ToField->setLexicalDeclContext(LexicalDC); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3369 | if (ToInitializer) |
| 3370 | ToField->setInClassInitializer(ToInitializer); |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3371 | ToField->setImplicit(D->isImplicit()); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3372 | LexicalDC->addDeclInternal(ToField); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3373 | return ToField; |
| 3374 | } |
| 3375 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3376 | ExpectedDecl ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3377 | // Import the major distinguishing characteristics of a variable. |
| 3378 | DeclContext *DC, *LexicalDC; |
| 3379 | DeclarationName Name; |
| 3380 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3381 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3382 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3383 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3384 | if (ToD) |
| 3385 | return ToD; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3386 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3387 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3388 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3389 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3390 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3391 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3392 | // For anonymous indirect fields, match up by index. |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3393 | if (!Name && |
| 3394 | ASTImporter::getFieldIndex(D) != |
| 3395 | ASTImporter::getFieldIndex(FoundField)) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3396 | continue; |
| 3397 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3398 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3399 | FoundField->getType(), |
David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 3400 | !Name.isEmpty())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3401 | Importer.MapImported(D, FoundField); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3402 | return FoundField; |
| 3403 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3404 | |
| 3405 | // If there are more anonymous fields to check, continue. |
| 3406 | if (!Name && I < N-1) |
| 3407 | continue; |
| 3408 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3409 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3410 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 3411 | << Name << D->getType() << FoundField->getType(); |
| 3412 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3413 | << FoundField->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3414 | |
| 3415 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3416 | } |
| 3417 | } |
| 3418 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3419 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3420 | auto TypeOrErr = import(D->getType()); |
| 3421 | if (!TypeOrErr) |
| 3422 | return TypeOrErr.takeError(); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3423 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3424 | auto **NamedChain = |
| 3425 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3426 | |
| 3427 | unsigned i = 0; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3428 | for (auto *PI : D->chain()) |
| 3429 | if (Expected<NamedDecl *> ToD = import(PI)) |
| 3430 | NamedChain[i++] = *ToD; |
| 3431 | else |
| 3432 | return ToD.takeError(); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3433 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3434 | llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()}; |
| 3435 | IndirectFieldDecl *ToIndirectField; |
| 3436 | if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3437 | Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3438 | // FIXME here we leak `NamedChain` which is allocated before |
| 3439 | return ToIndirectField; |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 3440 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3441 | for (const auto *Attr : D->attrs()) |
| 3442 | ToIndirectField->addAttr(Importer.Import(Attr)); |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 3443 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3444 | ToIndirectField->setAccess(D->getAccess()); |
| 3445 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3446 | LexicalDC->addDeclInternal(ToIndirectField); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3447 | return ToIndirectField; |
| 3448 | } |
| 3449 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3450 | ExpectedDecl ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3451 | // Import the major distinguishing characteristics of a declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3452 | DeclContext *DC, *LexicalDC; |
| 3453 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 3454 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3455 | |
| 3456 | // Determine whether we've already imported this decl. |
| 3457 | // FriendDecl is not a NamedDecl so we cannot use localUncachedLookup. |
| 3458 | auto *RD = cast<CXXRecordDecl>(DC); |
| 3459 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3460 | |
| 3461 | while (ImportedFriend) { |
| 3462 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 3463 | if (IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(), |
| 3464 | /*Complain=*/false)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3465 | return Importer.MapImported(D, ImportedFriend); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3466 | |
| 3467 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| 3468 | if (Importer.IsStructurallyEquivalent( |
| 3469 | D->getFriendType()->getType(), |
| 3470 | ImportedFriend->getFriendType()->getType(), true)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3471 | return Importer.MapImported(D, ImportedFriend); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3472 | } |
| 3473 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 3474 | } |
| 3475 | |
| 3476 | // Not found. Create it. |
| 3477 | FriendDecl::FriendUnion ToFU; |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3478 | if (NamedDecl *FriendD = D->getFriendDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3479 | NamedDecl *ToFriendD; |
| 3480 | if (Error Err = importInto(ToFriendD, FriendD)) |
| 3481 | return std::move(Err); |
| 3482 | |
| 3483 | if (FriendD->getFriendObjectKind() != Decl::FOK_None && |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3484 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) |
| 3485 | ToFriendD->setObjectOfFriendDecl(false); |
| 3486 | |
| 3487 | ToFU = ToFriendD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3488 | } else { // The friend is a type, not a decl. |
| 3489 | if (auto TSIOrErr = import(D->getFriendType())) |
| 3490 | ToFU = *TSIOrErr; |
| 3491 | else |
| 3492 | return TSIOrErr.takeError(); |
| 3493 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3494 | |
| 3495 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3496 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3497 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3498 | if (auto ListOrErr = ImportTemplateParameterList(FromTPLists[I])) |
| 3499 | ToTPLists[I] = *ListOrErr; |
| 3500 | else |
| 3501 | return ListOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3502 | } |
| 3503 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3504 | auto LocationOrErr = import(D->getLocation()); |
| 3505 | if (!LocationOrErr) |
| 3506 | return LocationOrErr.takeError(); |
| 3507 | auto FriendLocOrErr = import(D->getFriendLoc()); |
| 3508 | if (!FriendLocOrErr) |
| 3509 | return FriendLocOrErr.takeError(); |
| 3510 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3511 | FriendDecl *FrD; |
| 3512 | if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3513 | *LocationOrErr, ToFU, |
| 3514 | *FriendLocOrErr, ToTPLists)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3515 | return FrD; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3516 | |
| 3517 | FrD->setAccess(D->getAccess()); |
| 3518 | FrD->setLexicalDeclContext(LexicalDC); |
| 3519 | LexicalDC->addDeclInternal(FrD); |
| 3520 | return FrD; |
| 3521 | } |
| 3522 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3523 | ExpectedDecl ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3524 | // Import the major distinguishing characteristics of an ivar. |
| 3525 | DeclContext *DC, *LexicalDC; |
| 3526 | DeclarationName Name; |
| 3527 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3528 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3529 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3530 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3531 | if (ToD) |
| 3532 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3533 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3534 | // Determine whether we've already imported this ivar |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3535 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3536 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3537 | for (auto *FoundDecl : FoundDecls) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3538 | if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3539 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3540 | FoundIvar->getType())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3541 | Importer.MapImported(D, FoundIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3542 | return FoundIvar; |
| 3543 | } |
| 3544 | |
| 3545 | Importer.ToDiag(Loc, diag::err_odr_ivar_type_inconsistent) |
| 3546 | << Name << D->getType() << FoundIvar->getType(); |
| 3547 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) |
| 3548 | << FoundIvar->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3549 | |
| 3550 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3551 | } |
| 3552 | } |
| 3553 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3554 | QualType ToType; |
| 3555 | TypeSourceInfo *ToTypeSourceInfo; |
| 3556 | Expr *ToBitWidth; |
| 3557 | SourceLocation ToInnerLocStart; |
| 3558 | if (auto Imp = importSeq( |
| 3559 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), D->getInnerLocStart())) |
| 3560 | std::tie(ToType, ToTypeSourceInfo, ToBitWidth, ToInnerLocStart) = *Imp; |
| 3561 | else |
| 3562 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3563 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3564 | ObjCIvarDecl *ToIvar; |
| 3565 | if (GetImportedOrCreateDecl( |
| 3566 | ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3567 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3568 | ToType, ToTypeSourceInfo, |
| 3569 | D->getAccessControl(),ToBitWidth, D->getSynthesize())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3570 | return ToIvar; |
| 3571 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3572 | ToIvar->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3573 | LexicalDC->addDeclInternal(ToIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3574 | return ToIvar; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3575 | } |
| 3576 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3577 | ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) { |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3578 | |
| 3579 | SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D); |
| 3580 | auto RedeclIt = Redecls.begin(); |
| 3581 | // Import the first part of the decl chain. I.e. import all previous |
| 3582 | // declarations starting from the canonical decl. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3583 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 3584 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3585 | if (!RedeclOrErr) |
| 3586 | return RedeclOrErr.takeError(); |
| 3587 | } |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3588 | assert(*RedeclIt == D); |
| 3589 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3590 | // Import the major distinguishing characteristics of a variable. |
| 3591 | DeclContext *DC, *LexicalDC; |
| 3592 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3593 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3594 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3595 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3596 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3597 | if (ToD) |
| 3598 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3599 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3600 | // Try to find a variable in our own ("to") context with the same name and |
| 3601 | // in the same context as the variable we're importing. |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3602 | VarDecl *FoundByLookup = nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3603 | if (D->isFileVarDecl()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3604 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3605 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3606 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3607 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3608 | for (auto *FoundDecl : FoundDecls) { |
| 3609 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3610 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3611 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3612 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3613 | // 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] | 3614 | if (FoundVar->hasExternalFormalLinkage() && |
| 3615 | D->hasExternalFormalLinkage()) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3616 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3617 | FoundVar->getType())) { |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3618 | |
| 3619 | // The VarDecl in the "From" context has a definition, but in the |
| 3620 | // "To" context we already have a definition. |
| 3621 | VarDecl *FoundDef = FoundVar->getDefinition(); |
| 3622 | if (D->isThisDeclarationADefinition() && FoundDef) |
| 3623 | // FIXME Check for ODR error if the two definitions have |
| 3624 | // different initializers? |
| 3625 | return Importer.MapImported(D, FoundDef); |
| 3626 | |
| 3627 | // The VarDecl in the "From" context has an initializer, but in the |
| 3628 | // "To" context we already have an initializer. |
| 3629 | const VarDecl *FoundDInit = nullptr; |
| 3630 | if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit)) |
| 3631 | // FIXME Diagnose ODR error if the two initializers are different? |
| 3632 | return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit)); |
| 3633 | |
| 3634 | FoundByLookup = FoundVar; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3635 | break; |
| 3636 | } |
| 3637 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3638 | const ArrayType *FoundArray |
| 3639 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 3640 | const ArrayType *TArray |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3641 | = Importer.getToContext().getAsArrayType(D->getType()); |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3642 | if (FoundArray && TArray) { |
| 3643 | if (isa<IncompleteArrayType>(FoundArray) && |
| 3644 | isa<ConstantArrayType>(TArray)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3645 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3646 | if (auto TyOrErr = import(D->getType())) |
| 3647 | FoundVar->setType(*TyOrErr); |
| 3648 | else |
| 3649 | return TyOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3650 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3651 | FoundByLookup = FoundVar; |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3652 | break; |
| 3653 | } else if (isa<IncompleteArrayType>(TArray) && |
| 3654 | isa<ConstantArrayType>(FoundArray)) { |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3655 | FoundByLookup = FoundVar; |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3656 | break; |
Douglas Gregor | 2fbe558 | 2010-02-10 17:16:49 +0000 | [diff] [blame] | 3657 | } |
| 3658 | } |
| 3659 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3660 | Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3661 | << Name << D->getType() << FoundVar->getType(); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3662 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 3663 | << FoundVar->getType(); |
| 3664 | } |
| 3665 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3666 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3667 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3668 | } |
| 3669 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3670 | if (!ConflictingDecls.empty()) { |
| 3671 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3672 | ConflictingDecls.data(), |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3673 | ConflictingDecls.size()); |
| 3674 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3675 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3676 | } |
| 3677 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3678 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3679 | QualType ToType; |
| 3680 | TypeSourceInfo *ToTypeSourceInfo; |
| 3681 | SourceLocation ToInnerLocStart; |
| 3682 | NestedNameSpecifierLoc ToQualifierLoc; |
| 3683 | if (auto Imp = importSeq( |
| 3684 | D->getType(), D->getTypeSourceInfo(), D->getInnerLocStart(), |
| 3685 | D->getQualifierLoc())) |
| 3686 | std::tie(ToType, ToTypeSourceInfo, ToInnerLocStart, ToQualifierLoc) = *Imp; |
| 3687 | else |
| 3688 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3689 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3690 | // Create the imported variable. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3691 | VarDecl *ToVar; |
| 3692 | if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3693 | ToInnerLocStart, Loc, |
| 3694 | Name.getAsIdentifierInfo(), |
| 3695 | ToType, ToTypeSourceInfo, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3696 | D->getStorageClass())) |
| 3697 | return ToVar; |
| 3698 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3699 | ToVar->setQualifierInfo(ToQualifierLoc); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3700 | ToVar->setAccess(D->getAccess()); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3701 | ToVar->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3702 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3703 | if (FoundByLookup) { |
| 3704 | auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl()); |
| 3705 | ToVar->setPreviousDecl(Recent); |
| 3706 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3707 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3708 | if (Error Err = ImportInitializer(D, ToVar)) |
| 3709 | return std::move(Err); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3710 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3711 | if (D->isConstexpr()) |
| 3712 | ToVar->setConstexpr(true); |
| 3713 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3714 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 3715 | DC->addDeclInternal(ToVar); |
| 3716 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
| 3717 | LexicalDC->addDeclInternal(ToVar); |
| 3718 | |
| 3719 | // Import the rest of the chain. I.e. import all subsequent declarations. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3720 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3721 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3722 | if (!RedeclOrErr) |
| 3723 | return RedeclOrErr.takeError(); |
| 3724 | } |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3725 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3726 | return ToVar; |
| 3727 | } |
| 3728 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3729 | ExpectedDecl ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3730 | // Parameters are created in the translation unit's context, then moved |
| 3731 | // into the function declaration's context afterward. |
| 3732 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3733 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3734 | DeclarationName ToDeclName; |
| 3735 | SourceLocation ToLocation; |
| 3736 | QualType ToType; |
| 3737 | if (auto Imp = importSeq(D->getDeclName(), D->getLocation(), D->getType())) |
| 3738 | std::tie(ToDeclName, ToLocation, ToType) = *Imp; |
| 3739 | else |
| 3740 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3741 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3742 | // Create the imported parameter. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3743 | ImplicitParamDecl *ToParm = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3744 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
| 3745 | ToLocation, ToDeclName.getAsIdentifierInfo(), |
| 3746 | ToType, D->getParameterKind())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3747 | return ToParm; |
| 3748 | return ToParm; |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3749 | } |
| 3750 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3751 | ExpectedDecl ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3752 | // Parameters are created in the translation unit's context, then moved |
| 3753 | // into the function declaration's context afterward. |
| 3754 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3755 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3756 | DeclarationName ToDeclName; |
| 3757 | SourceLocation ToLocation, ToInnerLocStart; |
| 3758 | QualType ToType; |
| 3759 | TypeSourceInfo *ToTypeSourceInfo; |
| 3760 | if (auto Imp = importSeq( |
| 3761 | D->getDeclName(), D->getLocation(), D->getType(), D->getInnerLocStart(), |
| 3762 | D->getTypeSourceInfo())) |
| 3763 | std::tie( |
| 3764 | ToDeclName, ToLocation, ToType, ToInnerLocStart, |
| 3765 | ToTypeSourceInfo) = *Imp; |
| 3766 | else |
| 3767 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3768 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3769 | ParmVarDecl *ToParm; |
| 3770 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3771 | ToInnerLocStart, ToLocation, |
| 3772 | ToDeclName.getAsIdentifierInfo(), ToType, |
| 3773 | ToTypeSourceInfo, D->getStorageClass(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3774 | /*DefaultArg*/ nullptr)) |
| 3775 | return ToParm; |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3776 | |
| 3777 | // Set the default argument. |
John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 3778 | ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg()); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3779 | ToParm->setKNRPromoted(D->isKNRPromoted()); |
| 3780 | |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3781 | if (D->hasUninstantiatedDefaultArg()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3782 | if (auto ToDefArgOrErr = import(D->getUninstantiatedDefaultArg())) |
| 3783 | ToParm->setUninstantiatedDefaultArg(*ToDefArgOrErr); |
| 3784 | else |
| 3785 | return ToDefArgOrErr.takeError(); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3786 | } else if (D->hasUnparsedDefaultArg()) { |
| 3787 | ToParm->setUnparsedDefaultArg(); |
| 3788 | } else if (D->hasDefaultArg()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3789 | if (auto ToDefArgOrErr = import(D->getDefaultArg())) |
| 3790 | ToParm->setDefaultArg(*ToDefArgOrErr); |
| 3791 | else |
| 3792 | return ToDefArgOrErr.takeError(); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3793 | } |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3794 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3795 | if (D->isObjCMethodParameter()) { |
| 3796 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); |
| 3797 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); |
| 3798 | } else { |
| 3799 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), |
| 3800 | D->getFunctionScopeIndex()); |
| 3801 | } |
| 3802 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3803 | return ToParm; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3804 | } |
| 3805 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3806 | ExpectedDecl ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3807 | // Import the major distinguishing characteristics of a method. |
| 3808 | DeclContext *DC, *LexicalDC; |
| 3809 | DeclarationName Name; |
| 3810 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3811 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3812 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3813 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3814 | if (ToD) |
| 3815 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3816 | |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3817 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3818 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3819 | for (auto *FoundDecl : FoundDecls) { |
| 3820 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3821 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 3822 | continue; |
| 3823 | |
| 3824 | // Check return types. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3825 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 3826 | FoundMethod->getReturnType())) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3827 | Importer.ToDiag(Loc, diag::err_odr_objc_method_result_type_inconsistent) |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3828 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 3829 | << FoundMethod->getReturnType(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3830 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3831 | diag::note_odr_objc_method_here) |
| 3832 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3833 | |
| 3834 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3835 | } |
| 3836 | |
| 3837 | // Check the number of parameters. |
| 3838 | if (D->param_size() != FoundMethod->param_size()) { |
| 3839 | Importer.ToDiag(Loc, diag::err_odr_objc_method_num_params_inconsistent) |
| 3840 | << D->isInstanceMethod() << Name |
| 3841 | << D->param_size() << FoundMethod->param_size(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3842 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3843 | diag::note_odr_objc_method_here) |
| 3844 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3845 | |
| 3846 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3847 | } |
| 3848 | |
| 3849 | // Check parameter types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3850 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3851 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 3852 | P != PEnd; ++P, ++FoundP) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3853 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3854 | (*FoundP)->getType())) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3855 | Importer.FromDiag((*P)->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3856 | diag::err_odr_objc_method_param_type_inconsistent) |
| 3857 | << D->isInstanceMethod() << Name |
| 3858 | << (*P)->getType() << (*FoundP)->getType(); |
| 3859 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 3860 | << (*FoundP)->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3861 | |
| 3862 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3863 | } |
| 3864 | } |
| 3865 | |
| 3866 | // Check variadic/non-variadic. |
| 3867 | // Check the number of parameters. |
| 3868 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
| 3869 | Importer.ToDiag(Loc, diag::err_odr_objc_method_variadic_inconsistent) |
| 3870 | << D->isInstanceMethod() << Name; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3871 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3872 | diag::note_odr_objc_method_here) |
| 3873 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3874 | |
| 3875 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3876 | } |
| 3877 | |
| 3878 | // FIXME: Any other bits we need to merge? |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3879 | return Importer.MapImported(D, FoundMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3880 | } |
| 3881 | } |
| 3882 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3883 | SourceLocation ToEndLoc; |
| 3884 | QualType ToReturnType; |
| 3885 | TypeSourceInfo *ToReturnTypeSourceInfo; |
| 3886 | if (auto Imp = importSeq( |
| 3887 | D->getEndLoc(), D->getReturnType(), D->getReturnTypeSourceInfo())) |
| 3888 | std::tie(ToEndLoc, ToReturnType, ToReturnTypeSourceInfo) = *Imp; |
| 3889 | else |
| 3890 | return Imp.takeError(); |
Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 3891 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3892 | ObjCMethodDecl *ToMethod; |
| 3893 | if (GetImportedOrCreateDecl( |
| 3894 | ToMethod, D, Importer.getToContext(), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3895 | ToEndLoc, Name.getObjCSelector(), ToReturnType, |
| 3896 | ToReturnTypeSourceInfo, DC, D->isInstanceMethod(), D->isVariadic(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3897 | D->isPropertyAccessor(), D->isImplicit(), D->isDefined(), |
| 3898 | D->getImplementationControl(), D->hasRelatedResultType())) |
| 3899 | return ToMethod; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3900 | |
| 3901 | // FIXME: When we decide to merge method definitions, we'll need to |
| 3902 | // deal with implicit parameters. |
| 3903 | |
| 3904 | // Import the parameters |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3905 | SmallVector<ParmVarDecl *, 5> ToParams; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3906 | for (auto *FromP : D->parameters()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3907 | if (Expected<ParmVarDecl *> ToPOrErr = import(FromP)) |
| 3908 | ToParams.push_back(*ToPOrErr); |
| 3909 | else |
| 3910 | return ToPOrErr.takeError(); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3911 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3912 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3913 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3914 | for (auto *ToParam : ToParams) { |
| 3915 | ToParam->setOwningFunction(ToMethod); |
| 3916 | ToMethod->addDeclInternal(ToParam); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3917 | } |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3918 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3919 | SmallVector<SourceLocation, 12> FromSelLocs; |
| 3920 | D->getSelectorLocs(FromSelLocs); |
| 3921 | SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size()); |
| 3922 | if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs)) |
| 3923 | return std::move(Err); |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3924 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3925 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3926 | |
| 3927 | ToMethod->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3928 | LexicalDC->addDeclInternal(ToMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3929 | return ToMethod; |
| 3930 | } |
| 3931 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3932 | ExpectedDecl ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3933 | // Import the major distinguishing characteristics of a category. |
| 3934 | DeclContext *DC, *LexicalDC; |
| 3935 | DeclarationName Name; |
| 3936 | SourceLocation Loc; |
| 3937 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3938 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3939 | return std::move(Err); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3940 | if (ToD) |
| 3941 | return ToD; |
| 3942 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3943 | SourceLocation ToVarianceLoc, ToLocation, ToColonLoc; |
| 3944 | TypeSourceInfo *ToTypeSourceInfo; |
| 3945 | if (auto Imp = importSeq( |
| 3946 | D->getVarianceLoc(), D->getLocation(), D->getColonLoc(), |
| 3947 | D->getTypeSourceInfo())) |
| 3948 | std::tie(ToVarianceLoc, ToLocation, ToColonLoc, ToTypeSourceInfo) = *Imp; |
| 3949 | else |
| 3950 | return Imp.takeError(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3951 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3952 | ObjCTypeParamDecl *Result; |
| 3953 | if (GetImportedOrCreateDecl( |
| 3954 | Result, D, Importer.getToContext(), DC, D->getVariance(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3955 | ToVarianceLoc, D->getIndex(), |
| 3956 | ToLocation, Name.getAsIdentifierInfo(), |
| 3957 | ToColonLoc, ToTypeSourceInfo)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3958 | return Result; |
| 3959 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3960 | Result->setLexicalDeclContext(LexicalDC); |
| 3961 | return Result; |
| 3962 | } |
| 3963 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3964 | ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3965 | // Import the major distinguishing characteristics of a category. |
| 3966 | DeclContext *DC, *LexicalDC; |
| 3967 | DeclarationName Name; |
| 3968 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3969 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3970 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3971 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3972 | if (ToD) |
| 3973 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3974 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3975 | ObjCInterfaceDecl *ToInterface; |
| 3976 | if (Error Err = importInto(ToInterface, D->getClassInterface())) |
| 3977 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3978 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3979 | // Determine if we've already encountered this category. |
| 3980 | ObjCCategoryDecl *MergeWithCategory |
| 3981 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 3982 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 3983 | if (!ToCategory) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3984 | SourceLocation ToAtStartLoc, ToCategoryNameLoc; |
| 3985 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; |
| 3986 | if (auto Imp = importSeq( |
| 3987 | D->getAtStartLoc(), D->getCategoryNameLoc(), |
| 3988 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) |
| 3989 | std::tie( |
| 3990 | ToAtStartLoc, ToCategoryNameLoc, |
| 3991 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; |
| 3992 | else |
| 3993 | return Imp.takeError(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3994 | |
| 3995 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3996 | ToAtStartLoc, Loc, |
| 3997 | ToCategoryNameLoc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3998 | Name.getAsIdentifierInfo(), ToInterface, |
| 3999 | /*TypeParamList=*/nullptr, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4000 | ToIvarLBraceLoc, |
| 4001 | ToIvarRBraceLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4002 | return ToCategory; |
| 4003 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4004 | ToCategory->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4005 | LexicalDC->addDeclInternal(ToCategory); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4006 | // Import the type parameter list after MapImported, to avoid |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4007 | // loops when bringing in their DeclContext. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4008 | if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList())) |
| 4009 | ToCategory->setTypeParamList(*PListOrErr); |
| 4010 | else |
| 4011 | return PListOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4012 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4013 | // Import protocols |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4014 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4015 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4016 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 4017 | = D->protocol_loc_begin(); |
| 4018 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 4019 | FromProtoEnd = D->protocol_end(); |
| 4020 | FromProto != FromProtoEnd; |
| 4021 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4022 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4023 | Protocols.push_back(*ToProtoOrErr); |
| 4024 | else |
| 4025 | return ToProtoOrErr.takeError(); |
| 4026 | |
| 4027 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4028 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4029 | else |
| 4030 | return ToProtoLocOrErr.takeError(); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4031 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4032 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4033 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4034 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 4035 | ProtocolLocs.data(), Importer.getToContext()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4036 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4037 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4038 | Importer.MapImported(D, ToCategory); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4039 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4040 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4041 | // Import all of the members of this category. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4042 | if (Error Err = ImportDeclContext(D)) |
| 4043 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4044 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4045 | // If we have an implementation, import it as well. |
| 4046 | if (D->getImplementation()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4047 | if (Expected<ObjCCategoryImplDecl *> ToImplOrErr = |
| 4048 | import(D->getImplementation())) |
| 4049 | ToCategory->setImplementation(*ToImplOrErr); |
| 4050 | else |
| 4051 | return ToImplOrErr.takeError(); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4052 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4053 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4054 | return ToCategory; |
| 4055 | } |
| 4056 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4057 | Error ASTNodeImporter::ImportDefinition( |
| 4058 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4059 | if (To->getDefinition()) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4060 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4061 | if (Error Err = ImportDeclContext(From)) |
| 4062 | return Err; |
| 4063 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4064 | } |
| 4065 | |
| 4066 | // Start the protocol definition |
| 4067 | To->startDefinition(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4068 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4069 | // Import protocols |
| 4070 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4071 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4072 | ObjCProtocolDecl::protocol_loc_iterator FromProtoLoc = |
| 4073 | From->protocol_loc_begin(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4074 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4075 | FromProtoEnd = From->protocol_end(); |
| 4076 | FromProto != FromProtoEnd; |
| 4077 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4078 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4079 | Protocols.push_back(*ToProtoOrErr); |
| 4080 | else |
| 4081 | return ToProtoOrErr.takeError(); |
| 4082 | |
| 4083 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4084 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4085 | else |
| 4086 | return ToProtoLocOrErr.takeError(); |
| 4087 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4088 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4089 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4090 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4091 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4092 | ProtocolLocs.data(), Importer.getToContext()); |
| 4093 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4094 | if (shouldForceImportDeclContext(Kind)) { |
| 4095 | // Import all of the members of this protocol. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4096 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4097 | return Err; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4098 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4099 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4100 | } |
| 4101 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4102 | ExpectedDecl ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4103 | // 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] | 4104 | // from, but this particular declaration is not that definition, import the |
| 4105 | // definition and map to that. |
| 4106 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 4107 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4108 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4109 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4110 | else |
| 4111 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4112 | } |
| 4113 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4114 | // Import the major distinguishing characteristics of a protocol. |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4115 | DeclContext *DC, *LexicalDC; |
| 4116 | DeclarationName Name; |
| 4117 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4118 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4119 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4120 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4121 | if (ToD) |
| 4122 | return ToD; |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4123 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4124 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4125 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4126 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4127 | for (auto *FoundDecl : FoundDecls) { |
| 4128 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4129 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4130 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4131 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4132 | break; |
| 4133 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4134 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4135 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4136 | if (!ToProto) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4137 | auto ToAtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4138 | if (!ToAtBeginLocOrErr) |
| 4139 | return ToAtBeginLocOrErr.takeError(); |
| 4140 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4141 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, |
| 4142 | Name.getAsIdentifierInfo(), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4143 | *ToAtBeginLocOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4144 | /*PrevDecl=*/nullptr)) |
| 4145 | return ToProto; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4146 | ToProto->setLexicalDeclContext(LexicalDC); |
| 4147 | LexicalDC->addDeclInternal(ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4148 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4149 | |
| 4150 | Importer.MapImported(D, ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4151 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4152 | if (D->isThisDeclarationADefinition()) |
| 4153 | if (Error Err = ImportDefinition(D, ToProto)) |
| 4154 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4155 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4156 | return ToProto; |
| 4157 | } |
| 4158 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4159 | ExpectedDecl ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 4160 | DeclContext *DC, *LexicalDC; |
| 4161 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4162 | return std::move(Err); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4163 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4164 | ExpectedSLoc ExternLocOrErr = import(D->getExternLoc()); |
| 4165 | if (!ExternLocOrErr) |
| 4166 | return ExternLocOrErr.takeError(); |
| 4167 | |
| 4168 | ExpectedSLoc LangLocOrErr = import(D->getLocation()); |
| 4169 | if (!LangLocOrErr) |
| 4170 | return LangLocOrErr.takeError(); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4171 | |
| 4172 | bool HasBraces = D->hasBraces(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4173 | |
| 4174 | LinkageSpecDecl *ToLinkageSpec; |
| 4175 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4176 | *ExternLocOrErr, *LangLocOrErr, |
| 4177 | D->getLanguage(), HasBraces)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4178 | return ToLinkageSpec; |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4179 | |
| 4180 | if (HasBraces) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4181 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); |
| 4182 | if (!RBraceLocOrErr) |
| 4183 | return RBraceLocOrErr.takeError(); |
| 4184 | ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4185 | } |
| 4186 | |
| 4187 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 4188 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 4189 | |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4190 | return ToLinkageSpec; |
| 4191 | } |
| 4192 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4193 | ExpectedDecl ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4194 | DeclContext *DC, *LexicalDC; |
| 4195 | DeclarationName Name; |
| 4196 | SourceLocation Loc; |
| 4197 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4198 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4199 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4200 | if (ToD) |
| 4201 | return ToD; |
| 4202 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4203 | SourceLocation ToLoc, ToUsingLoc; |
| 4204 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4205 | if (auto Imp = importSeq( |
| 4206 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc())) |
| 4207 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc) = *Imp; |
| 4208 | else |
| 4209 | return Imp.takeError(); |
| 4210 | |
| 4211 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4212 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4213 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4214 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4215 | UsingDecl *ToUsing; |
| 4216 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4217 | ToUsingLoc, ToQualifierLoc, NameInfo, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4218 | D->hasTypename())) |
| 4219 | return ToUsing; |
| 4220 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4221 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4222 | LexicalDC->addDeclInternal(ToUsing); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4223 | |
| 4224 | if (NamedDecl *FromPattern = |
| 4225 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4226 | if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern)) |
| 4227 | Importer.getToContext().setInstantiatedFromUsingDecl( |
| 4228 | ToUsing, *ToPatternOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4229 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4230 | return ToPatternOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4231 | } |
| 4232 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4233 | for (UsingShadowDecl *FromShadow : D->shadows()) { |
| 4234 | if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow)) |
| 4235 | ToUsing->addShadowDecl(*ToShadowOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4236 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4237 | // FIXME: We return error here but the definition is already created |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4238 | // and available with lookups. How to fix this?.. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4239 | return ToShadowOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4240 | } |
| 4241 | return ToUsing; |
| 4242 | } |
| 4243 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4244 | ExpectedDecl ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4245 | DeclContext *DC, *LexicalDC; |
| 4246 | DeclarationName Name; |
| 4247 | SourceLocation Loc; |
| 4248 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4249 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4250 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4251 | if (ToD) |
| 4252 | return ToD; |
| 4253 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4254 | Expected<UsingDecl *> ToUsingOrErr = import(D->getUsingDecl()); |
| 4255 | if (!ToUsingOrErr) |
| 4256 | return ToUsingOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4257 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4258 | Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl()); |
| 4259 | if (!ToTargetOrErr) |
| 4260 | return ToTargetOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4261 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4262 | UsingShadowDecl *ToShadow; |
| 4263 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4264 | *ToUsingOrErr, *ToTargetOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4265 | return ToShadow; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4266 | |
| 4267 | ToShadow->setLexicalDeclContext(LexicalDC); |
| 4268 | ToShadow->setAccess(D->getAccess()); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4269 | |
| 4270 | if (UsingShadowDecl *FromPattern = |
| 4271 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4272 | if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern)) |
| 4273 | Importer.getToContext().setInstantiatedFromUsingShadowDecl( |
| 4274 | ToShadow, *ToPatternOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4275 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4276 | // FIXME: We return error here but the definition is already created |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4277 | // and available with lookups. How to fix this?.. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4278 | return ToPatternOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4279 | } |
| 4280 | |
| 4281 | LexicalDC->addDeclInternal(ToShadow); |
| 4282 | |
| 4283 | return ToShadow; |
| 4284 | } |
| 4285 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4286 | ExpectedDecl ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4287 | DeclContext *DC, *LexicalDC; |
| 4288 | DeclarationName Name; |
| 4289 | SourceLocation Loc; |
| 4290 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4291 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4292 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4293 | if (ToD) |
| 4294 | return ToD; |
| 4295 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4296 | auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor()); |
| 4297 | if (!ToComAncestorOrErr) |
| 4298 | return ToComAncestorOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4299 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4300 | NamespaceDecl *ToNominatedNamespace; |
| 4301 | SourceLocation ToUsingLoc, ToNamespaceKeyLocation, ToIdentLocation; |
| 4302 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4303 | if (auto Imp = importSeq( |
| 4304 | D->getNominatedNamespace(), D->getUsingLoc(), |
| 4305 | D->getNamespaceKeyLocation(), D->getQualifierLoc(), |
| 4306 | D->getIdentLocation())) |
| 4307 | std::tie( |
| 4308 | ToNominatedNamespace, ToUsingLoc, ToNamespaceKeyLocation, |
| 4309 | ToQualifierLoc, ToIdentLocation) = *Imp; |
| 4310 | else |
| 4311 | return Imp.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4312 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4313 | UsingDirectiveDecl *ToUsingDir; |
| 4314 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4315 | ToUsingLoc, |
| 4316 | ToNamespaceKeyLocation, |
| 4317 | ToQualifierLoc, |
| 4318 | ToIdentLocation, |
| 4319 | ToNominatedNamespace, *ToComAncestorOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4320 | return ToUsingDir; |
| 4321 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4322 | ToUsingDir->setLexicalDeclContext(LexicalDC); |
| 4323 | LexicalDC->addDeclInternal(ToUsingDir); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4324 | |
| 4325 | return ToUsingDir; |
| 4326 | } |
| 4327 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4328 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4329 | UnresolvedUsingValueDecl *D) { |
| 4330 | DeclContext *DC, *LexicalDC; |
| 4331 | DeclarationName Name; |
| 4332 | SourceLocation Loc; |
| 4333 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4334 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4335 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4336 | if (ToD) |
| 4337 | return ToD; |
| 4338 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4339 | SourceLocation ToLoc, ToUsingLoc, ToEllipsisLoc; |
| 4340 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4341 | if (auto Imp = importSeq( |
| 4342 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc(), |
| 4343 | D->getEllipsisLoc())) |
| 4344 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; |
| 4345 | else |
| 4346 | return Imp.takeError(); |
| 4347 | |
| 4348 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4349 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4350 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4351 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4352 | UnresolvedUsingValueDecl *ToUsingValue; |
| 4353 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4354 | ToUsingLoc, ToQualifierLoc, NameInfo, |
| 4355 | ToEllipsisLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4356 | return ToUsingValue; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4357 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4358 | ToUsingValue->setAccess(D->getAccess()); |
| 4359 | ToUsingValue->setLexicalDeclContext(LexicalDC); |
| 4360 | LexicalDC->addDeclInternal(ToUsingValue); |
| 4361 | |
| 4362 | return ToUsingValue; |
| 4363 | } |
| 4364 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4365 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4366 | UnresolvedUsingTypenameDecl *D) { |
| 4367 | DeclContext *DC, *LexicalDC; |
| 4368 | DeclarationName Name; |
| 4369 | SourceLocation Loc; |
| 4370 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4371 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4372 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4373 | if (ToD) |
| 4374 | return ToD; |
| 4375 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4376 | SourceLocation ToUsingLoc, ToTypenameLoc, ToEllipsisLoc; |
| 4377 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4378 | if (auto Imp = importSeq( |
| 4379 | D->getUsingLoc(), D->getTypenameLoc(), D->getQualifierLoc(), |
| 4380 | D->getEllipsisLoc())) |
| 4381 | std::tie(ToUsingLoc, ToTypenameLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; |
| 4382 | else |
| 4383 | return Imp.takeError(); |
| 4384 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4385 | UnresolvedUsingTypenameDecl *ToUsing; |
| 4386 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4387 | ToUsingLoc, ToTypenameLoc, |
| 4388 | ToQualifierLoc, Loc, Name, ToEllipsisLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4389 | return ToUsing; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4390 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4391 | ToUsing->setAccess(D->getAccess()); |
| 4392 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4393 | LexicalDC->addDeclInternal(ToUsing); |
| 4394 | |
| 4395 | return ToUsing; |
| 4396 | } |
| 4397 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4398 | |
| 4399 | Error ASTNodeImporter::ImportDefinition( |
| 4400 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4401 | if (To->getDefinition()) { |
| 4402 | // Check consistency of superclass. |
| 4403 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 4404 | if (FromSuper) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4405 | if (auto FromSuperOrErr = import(FromSuper)) |
| 4406 | FromSuper = *FromSuperOrErr; |
| 4407 | else |
| 4408 | return FromSuperOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4409 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4410 | |
| 4411 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4412 | if ((bool)FromSuper != (bool)ToSuper || |
| 4413 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4414 | Importer.ToDiag(To->getLocation(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4415 | diag::err_odr_objc_superclass_inconsistent) |
| 4416 | << To->getDeclName(); |
| 4417 | if (ToSuper) |
| 4418 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 4419 | << To->getSuperClass()->getDeclName(); |
| 4420 | else |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4421 | Importer.ToDiag(To->getLocation(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4422 | diag::note_odr_objc_missing_superclass); |
| 4423 | if (From->getSuperClass()) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4424 | Importer.FromDiag(From->getSuperClassLoc(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4425 | diag::note_odr_objc_superclass) |
| 4426 | << From->getSuperClass()->getDeclName(); |
| 4427 | else |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4428 | Importer.FromDiag(From->getLocation(), |
| 4429 | diag::note_odr_objc_missing_superclass); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4430 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4431 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4432 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4433 | if (Error Err = ImportDeclContext(From)) |
| 4434 | return Err; |
| 4435 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4436 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4437 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4438 | // Start the definition. |
| 4439 | To->startDefinition(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4440 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4441 | // If this class has a superclass, import it. |
| 4442 | if (From->getSuperClass()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4443 | if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo())) |
| 4444 | To->setSuperClass(*SuperTInfoOrErr); |
| 4445 | else |
| 4446 | return SuperTInfoOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4447 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4448 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4449 | // Import protocols |
| 4450 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4451 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4452 | ObjCInterfaceDecl::protocol_loc_iterator FromProtoLoc = |
| 4453 | From->protocol_loc_begin(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4454 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4455 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4456 | FromProtoEnd = From->protocol_end(); |
| 4457 | FromProto != FromProtoEnd; |
| 4458 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4459 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4460 | Protocols.push_back(*ToProtoOrErr); |
| 4461 | else |
| 4462 | return ToProtoOrErr.takeError(); |
| 4463 | |
| 4464 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4465 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4466 | else |
| 4467 | return ToProtoLocOrErr.takeError(); |
| 4468 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4469 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4470 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4471 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4472 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4473 | ProtocolLocs.data(), Importer.getToContext()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4474 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4475 | // Import categories. When the categories themselves are imported, they'll |
| 4476 | // hook themselves into this interface. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4477 | for (auto *Cat : From->known_categories()) { |
| 4478 | auto ToCatOrErr = import(Cat); |
| 4479 | if (!ToCatOrErr) |
| 4480 | return ToCatOrErr.takeError(); |
| 4481 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4482 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4483 | // If we have an @implementation, import it as well. |
| 4484 | if (From->getImplementation()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4485 | if (Expected<ObjCImplementationDecl *> ToImplOrErr = |
| 4486 | import(From->getImplementation())) |
| 4487 | To->setImplementation(*ToImplOrErr); |
| 4488 | else |
| 4489 | return ToImplOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4490 | } |
| 4491 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4492 | if (shouldForceImportDeclContext(Kind)) { |
| 4493 | // Import all of the members of this class. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4494 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4495 | return Err; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4496 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4497 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4498 | } |
| 4499 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4500 | Expected<ObjCTypeParamList *> |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4501 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 4502 | if (!list) |
| 4503 | return nullptr; |
| 4504 | |
| 4505 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4506 | for (auto *fromTypeParam : *list) { |
| 4507 | if (auto toTypeParamOrErr = import(fromTypeParam)) |
| 4508 | toTypeParams.push_back(*toTypeParamOrErr); |
| 4509 | else |
| 4510 | return toTypeParamOrErr.takeError(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4511 | } |
| 4512 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4513 | auto LAngleLocOrErr = import(list->getLAngleLoc()); |
| 4514 | if (!LAngleLocOrErr) |
| 4515 | return LAngleLocOrErr.takeError(); |
| 4516 | |
| 4517 | auto RAngleLocOrErr = import(list->getRAngleLoc()); |
| 4518 | if (!RAngleLocOrErr) |
| 4519 | return RAngleLocOrErr.takeError(); |
| 4520 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4521 | return ObjCTypeParamList::create(Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4522 | *LAngleLocOrErr, |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4523 | toTypeParams, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4524 | *RAngleLocOrErr); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4525 | } |
| 4526 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4527 | ExpectedDecl ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4528 | // If this class has a definition in the translation unit we're coming from, |
| 4529 | // but this particular declaration is not that definition, import the |
| 4530 | // definition and map to that. |
| 4531 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 4532 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4533 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4534 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4535 | else |
| 4536 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4537 | } |
| 4538 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4539 | // Import the major distinguishing characteristics of an @interface. |
| 4540 | DeclContext *DC, *LexicalDC; |
| 4541 | DeclarationName Name; |
| 4542 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4543 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4544 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4545 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4546 | if (ToD) |
| 4547 | return ToD; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4548 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4549 | // Look for an existing interface with the same name. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4550 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4551 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4552 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4553 | for (auto *FoundDecl : FoundDecls) { |
| 4554 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4555 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4556 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4557 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4558 | break; |
| 4559 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4560 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4561 | // Create an interface declaration, if one does not already exist. |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4562 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4563 | if (!ToIface) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4564 | ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4565 | if (!AtBeginLocOrErr) |
| 4566 | return AtBeginLocOrErr.takeError(); |
| 4567 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4568 | if (GetImportedOrCreateDecl( |
| 4569 | ToIface, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4570 | *AtBeginLocOrErr, Name.getAsIdentifierInfo(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4571 | /*TypeParamList=*/nullptr, |
| 4572 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) |
| 4573 | return ToIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4574 | ToIface->setLexicalDeclContext(LexicalDC); |
| 4575 | LexicalDC->addDeclInternal(ToIface); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4576 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4577 | Importer.MapImported(D, ToIface); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4578 | // Import the type parameter list after MapImported, to avoid |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4579 | // loops when bringing in their DeclContext. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4580 | if (auto ToPListOrErr = |
| 4581 | ImportObjCTypeParamList(D->getTypeParamListAsWritten())) |
| 4582 | ToIface->setTypeParamList(*ToPListOrErr); |
| 4583 | else |
| 4584 | return ToPListOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4585 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4586 | if (D->isThisDeclarationADefinition()) |
| 4587 | if (Error Err = ImportDefinition(D, ToIface)) |
| 4588 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4589 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4590 | return ToIface; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4591 | } |
| 4592 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4593 | ExpectedDecl |
| 4594 | ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 4595 | ObjCCategoryDecl *Category; |
| 4596 | if (Error Err = importInto(Category, D->getCategoryDecl())) |
| 4597 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4598 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4599 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 4600 | if (!ToImpl) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4601 | DeclContext *DC, *LexicalDC; |
| 4602 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4603 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4604 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4605 | SourceLocation ToLocation, ToAtStartLoc, ToCategoryNameLoc; |
| 4606 | if (auto Imp = importSeq( |
| 4607 | D->getLocation(), D->getAtStartLoc(), D->getCategoryNameLoc())) |
| 4608 | std::tie(ToLocation, ToAtStartLoc, ToCategoryNameLoc) = *Imp; |
| 4609 | else |
| 4610 | return Imp.takeError(); |
| 4611 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4612 | if (GetImportedOrCreateDecl( |
| 4613 | ToImpl, D, Importer.getToContext(), DC, |
| 4614 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4615 | ToLocation, ToAtStartLoc, ToCategoryNameLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4616 | return ToImpl; |
| 4617 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4618 | ToImpl->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4619 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4620 | Category->setImplementation(ToImpl); |
| 4621 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4622 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4623 | Importer.MapImported(D, ToImpl); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4624 | if (Error Err = ImportDeclContext(D)) |
| 4625 | return std::move(Err); |
| 4626 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4627 | return ToImpl; |
| 4628 | } |
| 4629 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4630 | ExpectedDecl |
| 4631 | ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4632 | // Find the corresponding interface. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4633 | ObjCInterfaceDecl *Iface; |
| 4634 | if (Error Err = importInto(Iface, D->getClassInterface())) |
| 4635 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4636 | |
| 4637 | // Import the superclass, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4638 | ObjCInterfaceDecl *Super; |
| 4639 | if (Error Err = importInto(Super, D->getSuperClass())) |
| 4640 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4641 | |
| 4642 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 4643 | if (!Impl) { |
| 4644 | // We haven't imported an implementation yet. Create a new @implementation |
| 4645 | // now. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4646 | DeclContext *DC, *LexicalDC; |
| 4647 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4648 | return std::move(Err); |
| 4649 | |
| 4650 | SourceLocation ToLocation, ToAtStartLoc, ToSuperClassLoc; |
| 4651 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; |
| 4652 | if (auto Imp = importSeq( |
| 4653 | D->getLocation(), D->getAtStartLoc(), D->getSuperClassLoc(), |
| 4654 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) |
| 4655 | std::tie( |
| 4656 | ToLocation, ToAtStartLoc, ToSuperClassLoc, |
| 4657 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; |
| 4658 | else |
| 4659 | return Imp.takeError(); |
| 4660 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4661 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4662 | DC, Iface, Super, |
| 4663 | ToLocation, |
| 4664 | ToAtStartLoc, |
| 4665 | ToSuperClassLoc, |
| 4666 | ToIvarLBraceLoc, |
| 4667 | ToIvarRBraceLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4668 | return Impl; |
| 4669 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4670 | Impl->setLexicalDeclContext(LexicalDC); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4671 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4672 | // Associate the implementation with the class it implements. |
| 4673 | Iface->setImplementation(Impl); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4674 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4675 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4676 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4677 | |
| 4678 | // Verify that the existing @implementation has the same superclass. |
| 4679 | if ((Super && !Impl->getSuperClass()) || |
| 4680 | (!Super && Impl->getSuperClass()) || |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4681 | (Super && Impl->getSuperClass() && |
| 4682 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 4683 | Impl->getSuperClass()))) { |
| 4684 | Importer.ToDiag(Impl->getLocation(), |
| 4685 | diag::err_odr_objc_superclass_inconsistent) |
| 4686 | << Iface->getDeclName(); |
| 4687 | // FIXME: It would be nice to have the location of the superclass |
| 4688 | // below. |
| 4689 | if (Impl->getSuperClass()) |
| 4690 | Importer.ToDiag(Impl->getLocation(), |
| 4691 | diag::note_odr_objc_superclass) |
| 4692 | << Impl->getSuperClass()->getDeclName(); |
| 4693 | else |
| 4694 | Importer.ToDiag(Impl->getLocation(), |
| 4695 | diag::note_odr_objc_missing_superclass); |
| 4696 | if (D->getSuperClass()) |
| 4697 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4698 | diag::note_odr_objc_superclass) |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4699 | << D->getSuperClass()->getDeclName(); |
| 4700 | else |
| 4701 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4702 | diag::note_odr_objc_missing_superclass); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4703 | |
| 4704 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4705 | } |
| 4706 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4707 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4708 | // Import all of the members of this @implementation. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4709 | if (Error Err = ImportDeclContext(D)) |
| 4710 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4711 | |
| 4712 | return Impl; |
| 4713 | } |
| 4714 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4715 | ExpectedDecl ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4716 | // Import the major distinguishing characteristics of an @property. |
| 4717 | DeclContext *DC, *LexicalDC; |
| 4718 | DeclarationName Name; |
| 4719 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4720 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4721 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4722 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4723 | if (ToD) |
| 4724 | return ToD; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4725 | |
| 4726 | // Check whether we have already imported this property. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4727 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4728 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4729 | for (auto *FoundDecl : FoundDecls) { |
| 4730 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4731 | // Check property types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4732 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4733 | FoundProp->getType())) { |
| 4734 | Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent) |
| 4735 | << Name << D->getType() << FoundProp->getType(); |
| 4736 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 4737 | << FoundProp->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4738 | |
| 4739 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4740 | } |
| 4741 | |
| 4742 | // FIXME: Check property attributes, getters, setters, etc.? |
| 4743 | |
| 4744 | // Consider these properties to be equivalent. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4745 | Importer.MapImported(D, FoundProp); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4746 | return FoundProp; |
| 4747 | } |
| 4748 | } |
| 4749 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4750 | QualType ToType; |
| 4751 | TypeSourceInfo *ToTypeSourceInfo; |
| 4752 | SourceLocation ToAtLoc, ToLParenLoc; |
| 4753 | if (auto Imp = importSeq( |
| 4754 | D->getType(), D->getTypeSourceInfo(), D->getAtLoc(), D->getLParenLoc())) |
| 4755 | std::tie(ToType, ToTypeSourceInfo, ToAtLoc, ToLParenLoc) = *Imp; |
| 4756 | else |
| 4757 | return Imp.takeError(); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4758 | |
| 4759 | // Create the new property. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4760 | ObjCPropertyDecl *ToProperty; |
| 4761 | if (GetImportedOrCreateDecl( |
| 4762 | ToProperty, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4763 | Name.getAsIdentifierInfo(), ToAtLoc, |
| 4764 | ToLParenLoc, ToType, |
| 4765 | ToTypeSourceInfo, D->getPropertyImplementation())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4766 | return ToProperty; |
| 4767 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4768 | Selector ToGetterName, ToSetterName; |
| 4769 | SourceLocation ToGetterNameLoc, ToSetterNameLoc; |
| 4770 | ObjCMethodDecl *ToGetterMethodDecl, *ToSetterMethodDecl; |
| 4771 | ObjCIvarDecl *ToPropertyIvarDecl; |
| 4772 | if (auto Imp = importSeq( |
| 4773 | D->getGetterName(), D->getSetterName(), |
| 4774 | D->getGetterNameLoc(), D->getSetterNameLoc(), |
| 4775 | D->getGetterMethodDecl(), D->getSetterMethodDecl(), |
| 4776 | D->getPropertyIvarDecl())) |
| 4777 | std::tie( |
| 4778 | ToGetterName, ToSetterName, |
| 4779 | ToGetterNameLoc, ToSetterNameLoc, |
| 4780 | ToGetterMethodDecl, ToSetterMethodDecl, |
| 4781 | ToPropertyIvarDecl) = *Imp; |
| 4782 | else |
| 4783 | return Imp.takeError(); |
| 4784 | |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4785 | ToProperty->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4786 | LexicalDC->addDeclInternal(ToProperty); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4787 | |
| 4788 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 4789 | ToProperty->setPropertyAttributesAsWritten( |
| 4790 | D->getPropertyAttributesAsWritten()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4791 | ToProperty->setGetterName(ToGetterName, ToGetterNameLoc); |
| 4792 | ToProperty->setSetterName(ToSetterName, ToSetterNameLoc); |
| 4793 | ToProperty->setGetterMethodDecl(ToGetterMethodDecl); |
| 4794 | ToProperty->setSetterMethodDecl(ToSetterMethodDecl); |
| 4795 | ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4796 | return ToProperty; |
| 4797 | } |
| 4798 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4799 | ExpectedDecl |
| 4800 | ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 4801 | ObjCPropertyDecl *Property; |
| 4802 | if (Error Err = importInto(Property, D->getPropertyDecl())) |
| 4803 | return std::move(Err); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4804 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4805 | DeclContext *DC, *LexicalDC; |
| 4806 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4807 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4808 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4809 | auto *InImpl = cast<ObjCImplDecl>(LexicalDC); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4810 | |
| 4811 | // Import the ivar (for an @synthesize). |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4812 | ObjCIvarDecl *Ivar = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4813 | if (Error Err = importInto(Ivar, D->getPropertyIvarDecl())) |
| 4814 | return std::move(Err); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4815 | |
| 4816 | ObjCPropertyImplDecl *ToImpl |
Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 4817 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 4818 | Property->getQueryKind()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4819 | if (!ToImpl) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4820 | SourceLocation ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc; |
| 4821 | if (auto Imp = importSeq( |
| 4822 | D->getBeginLoc(), D->getLocation(), D->getPropertyIvarDeclLoc())) |
| 4823 | std::tie(ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc) = *Imp; |
| 4824 | else |
| 4825 | return Imp.takeError(); |
| 4826 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4827 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4828 | ToBeginLoc, |
| 4829 | ToLocation, Property, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4830 | D->getPropertyImplementation(), Ivar, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4831 | ToPropertyIvarDeclLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4832 | return ToImpl; |
| 4833 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4834 | ToImpl->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4835 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4836 | } else { |
| 4837 | // Check that we have the same kind of property implementation (@synthesize |
| 4838 | // vs. @dynamic). |
| 4839 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4840 | Importer.ToDiag(ToImpl->getLocation(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4841 | diag::err_odr_objc_property_impl_kind_inconsistent) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4842 | << Property->getDeclName() |
| 4843 | << (ToImpl->getPropertyImplementation() |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4844 | == ObjCPropertyImplDecl::Dynamic); |
| 4845 | Importer.FromDiag(D->getLocation(), |
| 4846 | diag::note_odr_objc_property_impl_kind) |
| 4847 | << D->getPropertyDecl()->getDeclName() |
| 4848 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4849 | |
| 4850 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4851 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4852 | |
| 4853 | // For @synthesize, check that we have the same |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4854 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 4855 | Ivar != ToImpl->getPropertyIvarDecl()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4856 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4857 | diag::err_odr_objc_synthesize_ivar_inconsistent) |
| 4858 | << Property->getDeclName() |
| 4859 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 4860 | << Ivar->getDeclName(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4861 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4862 | diag::note_odr_objc_synthesize_ivar_here) |
| 4863 | << D->getPropertyIvarDecl()->getDeclName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4864 | |
| 4865 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4866 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4867 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4868 | // Merge the existing implementation with the new implementation. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4869 | Importer.MapImported(D, ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4870 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4871 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4872 | return ToImpl; |
| 4873 | } |
| 4874 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4875 | ExpectedDecl |
| 4876 | ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4877 | // For template arguments, we adopt the translation unit as our declaration |
| 4878 | // context. This context will be fixed when the actual template declaration |
| 4879 | // is created. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4880 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4881 | // FIXME: Import default argument. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4882 | |
| 4883 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 4884 | if (!BeginLocOrErr) |
| 4885 | return BeginLocOrErr.takeError(); |
| 4886 | |
| 4887 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 4888 | if (!LocationOrErr) |
| 4889 | return LocationOrErr.takeError(); |
| 4890 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4891 | TemplateTypeParmDecl *ToD = nullptr; |
| 4892 | (void)GetImportedOrCreateDecl( |
| 4893 | ToD, D, Importer.getToContext(), |
| 4894 | Importer.getToContext().getTranslationUnitDecl(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4895 | *BeginLocOrErr, *LocationOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4896 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), |
| 4897 | D->wasDeclaredWithTypename(), D->isParameterPack()); |
| 4898 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4899 | } |
| 4900 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4901 | ExpectedDecl |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4902 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4903 | DeclarationName ToDeclName; |
| 4904 | SourceLocation ToLocation, ToInnerLocStart; |
| 4905 | QualType ToType; |
| 4906 | TypeSourceInfo *ToTypeSourceInfo; |
| 4907 | if (auto Imp = importSeq( |
| 4908 | D->getDeclName(), D->getLocation(), D->getType(), D->getTypeSourceInfo(), |
| 4909 | D->getInnerLocStart())) |
| 4910 | std::tie( |
| 4911 | ToDeclName, ToLocation, ToType, ToTypeSourceInfo, |
| 4912 | ToInnerLocStart) = *Imp; |
| 4913 | else |
| 4914 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4915 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4916 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4917 | |
| 4918 | NonTypeTemplateParmDecl *ToD = nullptr; |
| 4919 | (void)GetImportedOrCreateDecl( |
| 4920 | ToD, D, Importer.getToContext(), |
| 4921 | Importer.getToContext().getTranslationUnitDecl(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4922 | ToInnerLocStart, ToLocation, D->getDepth(), |
| 4923 | D->getPosition(), ToDeclName.getAsIdentifierInfo(), ToType, |
| 4924 | D->isParameterPack(), ToTypeSourceInfo); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4925 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4926 | } |
| 4927 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4928 | ExpectedDecl |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4929 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 4930 | // Import the name of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4931 | auto NameOrErr = import(D->getDeclName()); |
| 4932 | if (!NameOrErr) |
| 4933 | return NameOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4934 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4935 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4936 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 4937 | if (!LocationOrErr) |
| 4938 | return LocationOrErr.takeError(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4939 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4940 | // Import template parameters. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4941 | auto TemplateParamsOrErr = ImportTemplateParameterList( |
| 4942 | D->getTemplateParameters()); |
| 4943 | if (!TemplateParamsOrErr) |
| 4944 | return TemplateParamsOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4945 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4946 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4947 | |
| 4948 | TemplateTemplateParmDecl *ToD = nullptr; |
| 4949 | (void)GetImportedOrCreateDecl( |
| 4950 | ToD, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4951 | Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr, |
| 4952 | D->getDepth(), D->getPosition(), D->isParameterPack(), |
| 4953 | (*NameOrErr).getAsIdentifierInfo(), |
| 4954 | *TemplateParamsOrErr); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4955 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4956 | } |
| 4957 | |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4958 | // Returns the definition for a (forward) declaration of a ClassTemplateDecl, if |
| 4959 | // it has any definition in the redecl chain. |
| 4960 | static ClassTemplateDecl *getDefinition(ClassTemplateDecl *D) { |
| 4961 | CXXRecordDecl *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); |
| 4962 | if (!ToTemplatedDef) |
| 4963 | return nullptr; |
| 4964 | ClassTemplateDecl *TemplateWithDef = |
| 4965 | ToTemplatedDef->getDescribedClassTemplate(); |
| 4966 | return TemplateWithDef; |
| 4967 | } |
| 4968 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4969 | ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4970 | bool IsFriend = D->getFriendObjectKind() != Decl::FOK_None; |
| 4971 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4972 | // If this record has a definition in the translation unit we're coming from, |
| 4973 | // but this particular declaration is not that definition, import the |
| 4974 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4975 | auto *Definition = |
| 4976 | cast_or_null<CXXRecordDecl>(D->getTemplatedDecl()->getDefinition()); |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4977 | if (Definition && Definition != D->getTemplatedDecl() && !IsFriend) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4978 | if (ExpectedDecl ImportedDefOrErr = import( |
| 4979 | Definition->getDescribedClassTemplate())) |
| 4980 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4981 | else |
| 4982 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4983 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4984 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4985 | // Import the major distinguishing characteristics of this class template. |
| 4986 | DeclContext *DC, *LexicalDC; |
| 4987 | DeclarationName Name; |
| 4988 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4989 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4990 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4991 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4992 | if (ToD) |
| 4993 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4994 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4995 | // We may already have a template of the same name; try to find and match it. |
| 4996 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4997 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4998 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4999 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5000 | for (auto *FoundDecl : FoundDecls) { |
| 5001 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5002 | continue; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5003 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5004 | Decl *Found = FoundDecl; |
| 5005 | if (auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found)) { |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5006 | |
| 5007 | // The class to be imported is a definition. |
| 5008 | if (D->isThisDeclarationADefinition()) { |
| 5009 | // Lookup will find the fwd decl only if that is more recent than the |
| 5010 | // definition. So, try to get the definition if that is available in |
| 5011 | // the redecl chain. |
| 5012 | ClassTemplateDecl *TemplateWithDef = getDefinition(FoundTemplate); |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5013 | if (TemplateWithDef) |
| 5014 | FoundTemplate = TemplateWithDef; |
| 5015 | else |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5016 | continue; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5017 | } |
| 5018 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5019 | if (IsStructuralMatch(D, FoundTemplate)) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5020 | if (!IsFriend) { |
| 5021 | Importer.MapImported(D->getTemplatedDecl(), |
| 5022 | FoundTemplate->getTemplatedDecl()); |
| 5023 | return Importer.MapImported(D, FoundTemplate); |
| 5024 | } |
Aleksei Sidorin | 761c224 | 2018-05-15 11:09:07 +0000 | [diff] [blame] | 5025 | |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5026 | continue; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5027 | } |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5028 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5029 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5030 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5031 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5032 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5033 | if (!ConflictingDecls.empty()) { |
| 5034 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5035 | ConflictingDecls.data(), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5036 | ConflictingDecls.size()); |
| 5037 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5038 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5039 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5040 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5041 | } |
| 5042 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5043 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); |
| 5044 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5045 | // Create the declaration that is being templated. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5046 | CXXRecordDecl *ToTemplated; |
| 5047 | if (Error Err = importInto(ToTemplated, FromTemplated)) |
| 5048 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5049 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5050 | // Create the class template declaration itself. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5051 | auto TemplateParamsOrErr = ImportTemplateParameterList( |
| 5052 | D->getTemplateParameters()); |
| 5053 | if (!TemplateParamsOrErr) |
| 5054 | return TemplateParamsOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5055 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5056 | ClassTemplateDecl *D2; |
| 5057 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5058 | *TemplateParamsOrErr, ToTemplated)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5059 | return D2; |
| 5060 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5061 | ToTemplated->setDescribedClassTemplate(D2); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5062 | |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5063 | if (ToTemplated->getPreviousDecl()) { |
| 5064 | assert( |
| 5065 | ToTemplated->getPreviousDecl()->getDescribedClassTemplate() && |
| 5066 | "Missing described template"); |
| 5067 | D2->setPreviousDecl( |
| 5068 | ToTemplated->getPreviousDecl()->getDescribedClassTemplate()); |
| 5069 | } |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5070 | D2->setAccess(D->getAccess()); |
| 5071 | D2->setLexicalDeclContext(LexicalDC); |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5072 | if (!IsFriend) |
| 5073 | LexicalDC->addDeclInternal(D2); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5074 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5075 | if (FromTemplated->isCompleteDefinition() && |
| 5076 | !ToTemplated->isCompleteDefinition()) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5077 | // FIXME: Import definition! |
| 5078 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5079 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5080 | return D2; |
| 5081 | } |
| 5082 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5083 | ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5084 | ClassTemplateSpecializationDecl *D) { |
| 5085 | // If this record has a definition in the translation unit we're coming from, |
| 5086 | // but this particular declaration is not that definition, import the |
| 5087 | // definition and map to that. |
| 5088 | TagDecl *Definition = D->getDefinition(); |
| 5089 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5090 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 5091 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5092 | else |
| 5093 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5094 | } |
| 5095 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5096 | ClassTemplateDecl *ClassTemplate; |
| 5097 | if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate())) |
| 5098 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5099 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5100 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5101 | DeclContext *DC, *LexicalDC; |
| 5102 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5103 | return std::move(Err); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5104 | |
| 5105 | // Import template arguments. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5106 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5107 | if (Error Err = ImportTemplateArguments( |
| 5108 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5109 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5110 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5111 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5112 | void *InsertPos = nullptr; |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5113 | ClassTemplateSpecializationDecl *D2 = nullptr; |
| 5114 | ClassTemplatePartialSpecializationDecl *PartialSpec = |
| 5115 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D); |
| 5116 | if (PartialSpec) |
| 5117 | D2 = ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos); |
| 5118 | else |
| 5119 | D2 = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
| 5120 | ClassTemplateSpecializationDecl * const PrevDecl = D2; |
| 5121 | RecordDecl *FoundDef = D2 ? D2->getDefinition() : nullptr; |
| 5122 | if (FoundDef) { |
| 5123 | if (!D->isCompleteDefinition()) { |
| 5124 | // The "From" translation unit only had a forward declaration; call it |
| 5125 | // the same declaration. |
| 5126 | // TODO Handle the redecl chain properly! |
| 5127 | return Importer.MapImported(D, FoundDef); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5128 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5129 | |
| 5130 | if (IsStructuralMatch(D, FoundDef)) { |
| 5131 | |
| 5132 | Importer.MapImported(D, FoundDef); |
| 5133 | |
| 5134 | // Import those those default field initializers which have been |
| 5135 | // instantiated in the "From" context, but not in the "To" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5136 | for (auto *FromField : D->fields()) { |
| 5137 | auto ToOrErr = import(FromField); |
| 5138 | if (!ToOrErr) |
| 5139 | // FIXME: return the error? |
| 5140 | consumeError(ToOrErr.takeError()); |
| 5141 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5142 | |
| 5143 | // Import those methods which have been instantiated in the |
| 5144 | // "From" context, but not in the "To" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5145 | for (CXXMethodDecl *FromM : D->methods()) { |
| 5146 | auto ToOrErr = import(FromM); |
| 5147 | if (!ToOrErr) |
| 5148 | // FIXME: return the error? |
| 5149 | consumeError(ToOrErr.takeError()); |
| 5150 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5151 | |
| 5152 | // TODO Import instantiated default arguments. |
| 5153 | // TODO Import instantiated exception specifications. |
| 5154 | // |
| 5155 | // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint what |
| 5156 | // else could be fused during an AST merge. |
| 5157 | |
| 5158 | return FoundDef; |
| 5159 | } |
| 5160 | } else { // We either couldn't find any previous specialization in the "To" |
| 5161 | // context, or we found one but without definition. Let's create a |
| 5162 | // new specialization and register that at the class template. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5163 | |
| 5164 | // Import the location of this declaration. |
| 5165 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5166 | if (!BeginLocOrErr) |
| 5167 | return BeginLocOrErr.takeError(); |
| 5168 | ExpectedSLoc IdLocOrErr = import(D->getLocation()); |
| 5169 | if (!IdLocOrErr) |
| 5170 | return IdLocOrErr.takeError(); |
| 5171 | |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5172 | if (PartialSpec) { |
| 5173 | // Import TemplateArgumentListInfo. |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5174 | TemplateArgumentListInfo ToTAInfo; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5175 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5176 | if (Error Err = ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) |
| 5177 | return std::move(Err); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5178 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5179 | QualType CanonInjType; |
| 5180 | if (Error Err = importInto( |
| 5181 | CanonInjType, PartialSpec->getInjectedSpecializationType())) |
| 5182 | return std::move(Err); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5183 | CanonInjType = CanonInjType.getCanonicalType(); |
| 5184 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5185 | auto ToTPListOrErr = ImportTemplateParameterList( |
| 5186 | PartialSpec->getTemplateParameters()); |
| 5187 | if (!ToTPListOrErr) |
| 5188 | return ToTPListOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5189 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5190 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5191 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| 5192 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, ClassTemplate, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5193 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5194 | ToTAInfo, CanonInjType, |
| 5195 | cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl))) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5196 | return D2; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5197 | |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5198 | // Update InsertPos, because preceding import calls may have invalidated |
| 5199 | // it by adding new specializations. |
| 5200 | if (!ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos)) |
| 5201 | // Add this partial specialization to the class template. |
| 5202 | ClassTemplate->AddPartialSpecialization( |
| 5203 | cast<ClassTemplatePartialSpecializationDecl>(D2), InsertPos); |
| 5204 | |
| 5205 | } else { // Not a partial specialization. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5206 | if (GetImportedOrCreateDecl( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5207 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| 5208 | *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs, |
| 5209 | PrevDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5210 | return D2; |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5211 | |
| 5212 | // Update InsertPos, because preceding import calls may have invalidated |
| 5213 | // it by adding new specializations. |
| 5214 | if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos)) |
| 5215 | // Add this specialization to the class template. |
| 5216 | ClassTemplate->AddSpecialization(D2, InsertPos); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5217 | } |
| 5218 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5219 | D2->setSpecializationKind(D->getSpecializationKind()); |
| 5220 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5221 | // Import the qualifier, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5222 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5223 | D2->setQualifierInfo(*LocOrErr); |
| 5224 | else |
| 5225 | return LocOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5226 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5227 | if (auto *TSI = D->getTypeAsWritten()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5228 | if (auto TInfoOrErr = import(TSI)) |
| 5229 | D2->setTypeAsWritten(*TInfoOrErr); |
| 5230 | else |
| 5231 | return TInfoOrErr.takeError(); |
| 5232 | |
| 5233 | if (auto LocOrErr = import(D->getTemplateKeywordLoc())) |
| 5234 | D2->setTemplateKeywordLoc(*LocOrErr); |
| 5235 | else |
| 5236 | return LocOrErr.takeError(); |
| 5237 | |
| 5238 | if (auto LocOrErr = import(D->getExternLoc())) |
| 5239 | D2->setExternLoc(*LocOrErr); |
| 5240 | else |
| 5241 | return LocOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5242 | } |
| 5243 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5244 | if (D->getPointOfInstantiation().isValid()) { |
| 5245 | if (auto POIOrErr = import(D->getPointOfInstantiation())) |
| 5246 | D2->setPointOfInstantiation(*POIOrErr); |
| 5247 | else |
| 5248 | return POIOrErr.takeError(); |
| 5249 | } |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5250 | |
| 5251 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 5252 | |
Gabor Marton | b14056b | 2018-05-25 11:21:24 +0000 | [diff] [blame] | 5253 | // Set the context of this specialization/instantiation. |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5254 | D2->setLexicalDeclContext(LexicalDC); |
Gabor Marton | b14056b | 2018-05-25 11:21:24 +0000 | [diff] [blame] | 5255 | |
| 5256 | // Add to the DC only if it was an explicit specialization/instantiation. |
| 5257 | if (D2->isExplicitInstantiationOrSpecialization()) { |
| 5258 | LexicalDC->addDeclInternal(D2); |
| 5259 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5260 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5261 | if (D->isCompleteDefinition()) |
| 5262 | if (Error Err = ImportDefinition(D, D2)) |
| 5263 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5264 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5265 | return D2; |
| 5266 | } |
| 5267 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5268 | ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5269 | // If this variable has a definition in the translation unit we're coming |
| 5270 | // from, |
| 5271 | // but this particular declaration is not that definition, import the |
| 5272 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5273 | auto *Definition = |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5274 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); |
| 5275 | if (Definition && Definition != D->getTemplatedDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5276 | if (ExpectedDecl ImportedDefOrErr = import( |
| 5277 | Definition->getDescribedVarTemplate())) |
| 5278 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5279 | else |
| 5280 | return ImportedDefOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5281 | } |
| 5282 | |
| 5283 | // Import the major distinguishing characteristics of this variable template. |
| 5284 | DeclContext *DC, *LexicalDC; |
| 5285 | DeclarationName Name; |
| 5286 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5287 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5288 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5289 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5290 | if (ToD) |
| 5291 | return ToD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5292 | |
| 5293 | // We may already have a template of the same name; try to find and match it. |
| 5294 | assert(!DC->isFunctionOrMethod() && |
| 5295 | "Variable templates cannot be declared at function scope"); |
| 5296 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 5297 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 5298 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5299 | for (auto *FoundDecl : FoundDecls) { |
| 5300 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5301 | continue; |
| 5302 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5303 | Decl *Found = FoundDecl; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5304 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5305 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 5306 | // The variable templates structurally match; call it the same template. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5307 | Importer.MapImported(D->getTemplatedDecl(), |
| 5308 | FoundTemplate->getTemplatedDecl()); |
| 5309 | return Importer.MapImported(D, FoundTemplate); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5310 | } |
| 5311 | } |
| 5312 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5313 | ConflictingDecls.push_back(FoundDecl); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5314 | } |
| 5315 | |
| 5316 | if (!ConflictingDecls.empty()) { |
| 5317 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 5318 | ConflictingDecls.data(), |
| 5319 | ConflictingDecls.size()); |
| 5320 | } |
| 5321 | |
| 5322 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5323 | // FIXME: Is it possible to get other error than name conflict? |
| 5324 | // (Put this `if` into the previous `if`?) |
| 5325 | return make_error<ImportError>(ImportError::NameConflict); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5326 | |
| 5327 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 5328 | |
| 5329 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5330 | // FIXME: Value not used? |
| 5331 | ExpectedType TypeOrErr = import(DTemplated->getType()); |
| 5332 | if (!TypeOrErr) |
| 5333 | return TypeOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5334 | |
| 5335 | // Create the declaration that is being templated. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5336 | VarDecl *ToTemplated; |
| 5337 | if (Error Err = importInto(ToTemplated, DTemplated)) |
| 5338 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5339 | |
| 5340 | // Create the variable template declaration itself. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5341 | auto TemplateParamsOrErr = ImportTemplateParameterList( |
| 5342 | D->getTemplateParameters()); |
| 5343 | if (!TemplateParamsOrErr) |
| 5344 | return TemplateParamsOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5345 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5346 | VarTemplateDecl *ToVarTD; |
| 5347 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5348 | Name, *TemplateParamsOrErr, ToTemplated)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5349 | return ToVarTD; |
| 5350 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5351 | ToTemplated->setDescribedVarTemplate(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5352 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5353 | ToVarTD->setAccess(D->getAccess()); |
| 5354 | ToVarTD->setLexicalDeclContext(LexicalDC); |
| 5355 | LexicalDC->addDeclInternal(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5356 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5357 | if (DTemplated->isThisDeclarationADefinition() && |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5358 | !ToTemplated->isThisDeclarationADefinition()) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5359 | // FIXME: Import definition! |
| 5360 | } |
| 5361 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5362 | return ToVarTD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5363 | } |
| 5364 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5365 | ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5366 | VarTemplateSpecializationDecl *D) { |
| 5367 | // If this record has a definition in the translation unit we're coming from, |
| 5368 | // but this particular declaration is not that definition, import the |
| 5369 | // definition and map to that. |
| 5370 | VarDecl *Definition = D->getDefinition(); |
| 5371 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5372 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 5373 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5374 | else |
| 5375 | return ImportedDefOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5376 | } |
| 5377 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5378 | VarTemplateDecl *VarTemplate; |
| 5379 | if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate())) |
| 5380 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5381 | |
| 5382 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5383 | DeclContext *DC, *LexicalDC; |
| 5384 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5385 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5386 | |
| 5387 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5388 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5389 | if (!BeginLocOrErr) |
| 5390 | return BeginLocOrErr.takeError(); |
| 5391 | |
| 5392 | auto IdLocOrErr = import(D->getLocation()); |
| 5393 | if (!IdLocOrErr) |
| 5394 | return IdLocOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5395 | |
| 5396 | // Import template arguments. |
| 5397 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5398 | if (Error Err = ImportTemplateArguments( |
| 5399 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5400 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5401 | |
| 5402 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5403 | void *InsertPos = nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5404 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 5405 | TemplateArgs, InsertPos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5406 | if (D2) { |
| 5407 | // We already have a variable template specialization with these template |
| 5408 | // arguments. |
| 5409 | |
| 5410 | // FIXME: Check for specialization vs. instantiation errors. |
| 5411 | |
| 5412 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 5413 | if (!D->isThisDeclarationADefinition() || |
| 5414 | IsStructuralMatch(D, FoundDef)) { |
| 5415 | // The record types structurally match, or the "from" translation |
| 5416 | // unit only had a forward declaration anyway; call it the same |
| 5417 | // variable. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5418 | return Importer.MapImported(D, FoundDef); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5419 | } |
| 5420 | } |
| 5421 | } else { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5422 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5423 | QualType T; |
| 5424 | if (Error Err = importInto(T, D->getType())) |
| 5425 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5426 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5427 | auto TInfoOrErr = import(D->getTypeSourceInfo()); |
| 5428 | if (!TInfoOrErr) |
| 5429 | return TInfoOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5430 | |
| 5431 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5432 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5433 | D->getTemplateArgsInfo(), ToTAInfo)) |
| 5434 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5435 | |
| 5436 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5437 | // Create a new specialization. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5438 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { |
| 5439 | // Import TemplateArgumentListInfo |
| 5440 | TemplateArgumentListInfo ArgInfos; |
| 5441 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); |
| 5442 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5443 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5444 | *FromTAArgsAsWritten, ArgInfos)) |
| 5445 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5446 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5447 | auto ToTPListOrErr = ImportTemplateParameterList( |
| 5448 | FromPartial->getTemplateParameters()); |
| 5449 | if (!ToTPListOrErr) |
| 5450 | return ToTPListOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5451 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5452 | PartVarSpecDecl *ToPartial; |
| 5453 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5454 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, |
| 5455 | VarTemplate, T, *TInfoOrErr, |
| 5456 | D->getStorageClass(), TemplateArgs, ArgInfos)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5457 | return ToPartial; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5458 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5459 | if (Expected<PartVarSpecDecl *> ToInstOrErr = import( |
| 5460 | FromPartial->getInstantiatedFromMember())) |
| 5461 | ToPartial->setInstantiatedFromMember(*ToInstOrErr); |
| 5462 | else |
| 5463 | return ToInstOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5464 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5465 | if (FromPartial->isMemberSpecialization()) |
| 5466 | ToPartial->setMemberSpecialization(); |
| 5467 | |
| 5468 | D2 = ToPartial; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5469 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5470 | } else { // Full specialization |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5471 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, |
| 5472 | *BeginLocOrErr, *IdLocOrErr, VarTemplate, |
| 5473 | T, *TInfoOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5474 | D->getStorageClass(), TemplateArgs)) |
| 5475 | return D2; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5476 | } |
| 5477 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5478 | if (D->getPointOfInstantiation().isValid()) { |
| 5479 | if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation())) |
| 5480 | D2->setPointOfInstantiation(*POIOrErr); |
| 5481 | else |
| 5482 | return POIOrErr.takeError(); |
| 5483 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5484 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5485 | D2->setSpecializationKind(D->getSpecializationKind()); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5486 | D2->setTemplateArgsInfo(ToTAInfo); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5487 | |
| 5488 | // Add this specialization to the class template. |
| 5489 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 5490 | |
| 5491 | // Import the qualifier, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5492 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5493 | D2->setQualifierInfo(*LocOrErr); |
| 5494 | else |
| 5495 | return LocOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5496 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5497 | if (D->isConstexpr()) |
| 5498 | D2->setConstexpr(true); |
| 5499 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5500 | // Add the specialization to this context. |
| 5501 | D2->setLexicalDeclContext(LexicalDC); |
| 5502 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5503 | |
| 5504 | D2->setAccess(D->getAccess()); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5505 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5506 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5507 | if (Error Err = ImportInitializer(D, D2)) |
| 5508 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5509 | |
| 5510 | return D2; |
| 5511 | } |
| 5512 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5513 | ExpectedDecl |
| 5514 | ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5515 | DeclContext *DC, *LexicalDC; |
| 5516 | DeclarationName Name; |
| 5517 | SourceLocation Loc; |
| 5518 | NamedDecl *ToD; |
| 5519 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5520 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5521 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5522 | |
| 5523 | if (ToD) |
| 5524 | return ToD; |
| 5525 | |
| 5526 | // Try to find a function in our own ("to") context with the same name, same |
| 5527 | // type, and in the same context as the function we're importing. |
| 5528 | if (!LexicalDC->isFunctionOrMethod()) { |
| 5529 | unsigned IDNS = Decl::IDNS_Ordinary; |
| 5530 | SmallVector<NamedDecl *, 2> FoundDecls; |
| 5531 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5532 | for (auto *FoundDecl : FoundDecls) { |
| 5533 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5534 | continue; |
| 5535 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5536 | if (auto *FoundFunction = |
| 5537 | dyn_cast<FunctionTemplateDecl>(FoundDecl)) { |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5538 | if (FoundFunction->hasExternalFormalLinkage() && |
| 5539 | D->hasExternalFormalLinkage()) { |
| 5540 | if (IsStructuralMatch(D, FoundFunction)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5541 | Importer.MapImported(D, FoundFunction); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5542 | // FIXME: Actually try to merge the body and other attributes. |
| 5543 | return FoundFunction; |
| 5544 | } |
| 5545 | } |
| 5546 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5547 | // TODO: handle conflicting names |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5548 | } |
| 5549 | } |
| 5550 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5551 | auto ParamsOrErr = ImportTemplateParameterList( |
| 5552 | D->getTemplateParameters()); |
| 5553 | if (!ParamsOrErr) |
| 5554 | return ParamsOrErr.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5555 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5556 | FunctionDecl *TemplatedFD; |
| 5557 | if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl())) |
| 5558 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5559 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5560 | FunctionTemplateDecl *ToFunc; |
| 5561 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5562 | *ParamsOrErr, TemplatedFD)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5563 | return ToFunc; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5564 | |
| 5565 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); |
| 5566 | ToFunc->setAccess(D->getAccess()); |
| 5567 | ToFunc->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5568 | |
| 5569 | LexicalDC->addDeclInternal(ToFunc); |
| 5570 | return ToFunc; |
| 5571 | } |
| 5572 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5573 | //---------------------------------------------------------------------------- |
| 5574 | // Import Statements |
| 5575 | //---------------------------------------------------------------------------- |
| 5576 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5577 | ExpectedStmt ASTNodeImporter::VisitStmt(Stmt *S) { |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5578 | Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node) |
| 5579 | << S->getStmtClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5580 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5581 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5582 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5583 | |
| 5584 | ExpectedStmt ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5585 | SmallVector<IdentifierInfo *, 4> Names; |
| 5586 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 5587 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5588 | // ToII is nullptr when no symbolic name is given for output operand |
| 5589 | // see ParseStmtAsm::ParseAsmOperandsOpt |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5590 | Names.push_back(ToII); |
| 5591 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5592 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5593 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 5594 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5595 | // ToII is nullptr when no symbolic name is given for input operand |
| 5596 | // see ParseStmtAsm::ParseAsmOperandsOpt |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5597 | Names.push_back(ToII); |
| 5598 | } |
| 5599 | |
| 5600 | SmallVector<StringLiteral *, 4> Clobbers; |
| 5601 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5602 | if (auto ClobberOrErr = import(S->getClobberStringLiteral(I))) |
| 5603 | Clobbers.push_back(*ClobberOrErr); |
| 5604 | else |
| 5605 | return ClobberOrErr.takeError(); |
| 5606 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5607 | } |
| 5608 | |
| 5609 | SmallVector<StringLiteral *, 4> Constraints; |
| 5610 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5611 | if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I))) |
| 5612 | Constraints.push_back(*OutputOrErr); |
| 5613 | else |
| 5614 | return OutputOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5615 | } |
| 5616 | |
| 5617 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5618 | if (auto InputOrErr = import(S->getInputConstraintLiteral(I))) |
| 5619 | Constraints.push_back(*InputOrErr); |
| 5620 | else |
| 5621 | return InputOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5622 | } |
| 5623 | |
| 5624 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5625 | if (Error Err = ImportContainerChecked(S->outputs(), Exprs)) |
| 5626 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5627 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5628 | if (Error Err = ImportArrayChecked( |
| 5629 | S->inputs(), Exprs.begin() + S->getNumOutputs())) |
| 5630 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5631 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5632 | ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc()); |
| 5633 | if (!AsmLocOrErr) |
| 5634 | return AsmLocOrErr.takeError(); |
| 5635 | auto AsmStrOrErr = import(S->getAsmString()); |
| 5636 | if (!AsmStrOrErr) |
| 5637 | return AsmStrOrErr.takeError(); |
| 5638 | ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc()); |
| 5639 | if (!RParenLocOrErr) |
| 5640 | return RParenLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5641 | |
| 5642 | return new (Importer.getToContext()) GCCAsmStmt( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5643 | Importer.getToContext(), |
| 5644 | *AsmLocOrErr, |
| 5645 | S->isSimple(), |
| 5646 | S->isVolatile(), |
| 5647 | S->getNumOutputs(), |
| 5648 | S->getNumInputs(), |
| 5649 | Names.data(), |
| 5650 | Constraints.data(), |
| 5651 | Exprs.data(), |
| 5652 | *AsmStrOrErr, |
| 5653 | S->getNumClobbers(), |
| 5654 | Clobbers.data(), |
| 5655 | *RParenLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5656 | } |
| 5657 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5658 | ExpectedStmt ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| 5659 | auto Imp = importSeq(S->getDeclGroup(), S->getBeginLoc(), S->getEndLoc()); |
| 5660 | if (!Imp) |
| 5661 | return Imp.takeError(); |
| 5662 | |
| 5663 | DeclGroupRef ToDG; |
| 5664 | SourceLocation ToBeginLoc, ToEndLoc; |
| 5665 | std::tie(ToDG, ToBeginLoc, ToEndLoc) = *Imp; |
| 5666 | |
| 5667 | return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5668 | } |
| 5669 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5670 | ExpectedStmt ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 5671 | ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc()); |
| 5672 | if (!ToSemiLocOrErr) |
| 5673 | return ToSemiLocOrErr.takeError(); |
| 5674 | return new (Importer.getToContext()) NullStmt( |
| 5675 | *ToSemiLocOrErr, S->hasLeadingEmptyMacro()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5676 | } |
| 5677 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5678 | ExpectedStmt ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5679 | SmallVector<Stmt *, 8> ToStmts(S->size()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5680 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5681 | if (Error Err = ImportContainerChecked(S->body(), ToStmts)) |
| 5682 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5683 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5684 | ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc()); |
| 5685 | if (!ToLBracLocOrErr) |
| 5686 | return ToLBracLocOrErr.takeError(); |
| 5687 | |
| 5688 | ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc()); |
| 5689 | if (!ToRBracLocOrErr) |
| 5690 | return ToRBracLocOrErr.takeError(); |
| 5691 | |
| 5692 | return CompoundStmt::Create( |
| 5693 | Importer.getToContext(), ToStmts, |
| 5694 | *ToLBracLocOrErr, *ToRBracLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5695 | } |
| 5696 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5697 | ExpectedStmt ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| 5698 | auto Imp = importSeq( |
| 5699 | S->getLHS(), S->getRHS(), S->getSubStmt(), S->getCaseLoc(), |
| 5700 | S->getEllipsisLoc(), S->getColonLoc()); |
| 5701 | if (!Imp) |
| 5702 | return Imp.takeError(); |
| 5703 | |
| 5704 | Expr *ToLHS, *ToRHS; |
| 5705 | Stmt *ToSubStmt; |
| 5706 | SourceLocation ToCaseLoc, ToEllipsisLoc, ToColonLoc; |
| 5707 | std::tie(ToLHS, ToRHS, ToSubStmt, ToCaseLoc, ToEllipsisLoc, ToColonLoc) = |
| 5708 | *Imp; |
| 5709 | |
Bruno Ricci | 5b3057175 | 2018-10-28 12:30:53 +0000 | [diff] [blame] | 5710 | auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS, |
| 5711 | ToCaseLoc, ToEllipsisLoc, ToColonLoc); |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5712 | ToStmt->setSubStmt(ToSubStmt); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5713 | |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5714 | return ToStmt; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5715 | } |
| 5716 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5717 | ExpectedStmt ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| 5718 | auto Imp = importSeq(S->getDefaultLoc(), S->getColonLoc(), S->getSubStmt()); |
| 5719 | if (!Imp) |
| 5720 | return Imp.takeError(); |
| 5721 | |
| 5722 | SourceLocation ToDefaultLoc, ToColonLoc; |
| 5723 | Stmt *ToSubStmt; |
| 5724 | std::tie(ToDefaultLoc, ToColonLoc, ToSubStmt) = *Imp; |
| 5725 | |
| 5726 | return new (Importer.getToContext()) DefaultStmt( |
| 5727 | ToDefaultLoc, ToColonLoc, ToSubStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5728 | } |
| 5729 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5730 | ExpectedStmt ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| 5731 | auto Imp = importSeq(S->getIdentLoc(), S->getDecl(), S->getSubStmt()); |
| 5732 | if (!Imp) |
| 5733 | return Imp.takeError(); |
| 5734 | |
| 5735 | SourceLocation ToIdentLoc; |
| 5736 | LabelDecl *ToLabelDecl; |
| 5737 | Stmt *ToSubStmt; |
| 5738 | std::tie(ToIdentLoc, ToLabelDecl, ToSubStmt) = *Imp; |
| 5739 | |
| 5740 | return new (Importer.getToContext()) LabelStmt( |
| 5741 | ToIdentLoc, ToLabelDecl, ToSubStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5742 | } |
| 5743 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5744 | ExpectedStmt ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { |
| 5745 | ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc()); |
| 5746 | if (!ToAttrLocOrErr) |
| 5747 | return ToAttrLocOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5748 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 5749 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5750 | if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs)) |
| 5751 | return std::move(Err); |
| 5752 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 5753 | if (!ToSubStmtOrErr) |
| 5754 | return ToSubStmtOrErr.takeError(); |
| 5755 | |
| 5756 | return AttributedStmt::Create( |
| 5757 | Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5758 | } |
| 5759 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5760 | ExpectedStmt ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| 5761 | auto Imp = importSeq( |
| 5762 | S->getIfLoc(), S->getInit(), S->getConditionVariable(), S->getCond(), |
| 5763 | S->getThen(), S->getElseLoc(), S->getElse()); |
| 5764 | if (!Imp) |
| 5765 | return Imp.takeError(); |
| 5766 | |
| 5767 | SourceLocation ToIfLoc, ToElseLoc; |
| 5768 | Stmt *ToInit, *ToThen, *ToElse; |
| 5769 | VarDecl *ToConditionVariable; |
| 5770 | Expr *ToCond; |
| 5771 | std::tie( |
| 5772 | ToIfLoc, ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, ToElse) = |
| 5773 | *Imp; |
| 5774 | |
Bruno Ricci | b1cc94b | 2018-10-27 21:12:20 +0000 | [diff] [blame] | 5775 | return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->isConstexpr(), |
| 5776 | ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, |
| 5777 | ToElse); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5778 | } |
| 5779 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5780 | ExpectedStmt ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
| 5781 | auto Imp = importSeq( |
| 5782 | S->getInit(), S->getConditionVariable(), S->getCond(), |
| 5783 | S->getBody(), S->getSwitchLoc()); |
| 5784 | if (!Imp) |
| 5785 | return Imp.takeError(); |
| 5786 | |
| 5787 | Stmt *ToInit, *ToBody; |
| 5788 | VarDecl *ToConditionVariable; |
| 5789 | Expr *ToCond; |
| 5790 | SourceLocation ToSwitchLoc; |
| 5791 | std::tie(ToInit, ToConditionVariable, ToCond, ToBody, ToSwitchLoc) = *Imp; |
| 5792 | |
Bruno Ricci | e2806f8 | 2018-10-29 16:12:37 +0000 | [diff] [blame^] | 5793 | auto *ToStmt = SwitchStmt::Create(Importer.getToContext(), ToInit, |
| 5794 | ToConditionVariable, ToCond); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5795 | ToStmt->setBody(ToBody); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5796 | ToStmt->setSwitchLoc(ToSwitchLoc); |
| 5797 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5798 | // Now we have to re-chain the cases. |
| 5799 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 5800 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 5801 | SC = SC->getNextSwitchCase()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5802 | Expected<SwitchCase *> ToSCOrErr = import(SC); |
| 5803 | if (!ToSCOrErr) |
| 5804 | return ToSCOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5805 | if (LastChainedSwitchCase) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5806 | LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5807 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5808 | ToStmt->setSwitchCaseList(*ToSCOrErr); |
| 5809 | LastChainedSwitchCase = *ToSCOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5810 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5811 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5812 | return ToStmt; |
| 5813 | } |
| 5814 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5815 | ExpectedStmt ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| 5816 | auto Imp = importSeq( |
| 5817 | S->getConditionVariable(), S->getCond(), S->getBody(), S->getWhileLoc()); |
| 5818 | if (!Imp) |
| 5819 | return Imp.takeError(); |
| 5820 | |
| 5821 | VarDecl *ToConditionVariable; |
| 5822 | Expr *ToCond; |
| 5823 | Stmt *ToBody; |
| 5824 | SourceLocation ToWhileLoc; |
| 5825 | std::tie(ToConditionVariable, ToCond, ToBody, ToWhileLoc) = *Imp; |
| 5826 | |
| 5827 | return new (Importer.getToContext()) WhileStmt( |
| 5828 | Importer.getToContext(), |
| 5829 | ToConditionVariable, ToCond, ToBody, ToWhileLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5830 | } |
| 5831 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5832 | ExpectedStmt ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| 5833 | auto Imp = importSeq( |
| 5834 | S->getBody(), S->getCond(), S->getDoLoc(), S->getWhileLoc(), |
| 5835 | S->getRParenLoc()); |
| 5836 | if (!Imp) |
| 5837 | return Imp.takeError(); |
| 5838 | |
| 5839 | Stmt *ToBody; |
| 5840 | Expr *ToCond; |
| 5841 | SourceLocation ToDoLoc, ToWhileLoc, ToRParenLoc; |
| 5842 | std::tie(ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc) = *Imp; |
| 5843 | |
| 5844 | return new (Importer.getToContext()) DoStmt( |
| 5845 | ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5846 | } |
| 5847 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5848 | ExpectedStmt ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| 5849 | auto Imp = importSeq( |
| 5850 | S->getInit(), S->getCond(), S->getConditionVariable(), S->getInc(), |
| 5851 | S->getBody(), S->getForLoc(), S->getLParenLoc(), S->getRParenLoc()); |
| 5852 | if (!Imp) |
| 5853 | return Imp.takeError(); |
| 5854 | |
| 5855 | Stmt *ToInit; |
| 5856 | Expr *ToCond, *ToInc; |
| 5857 | VarDecl *ToConditionVariable; |
| 5858 | Stmt *ToBody; |
| 5859 | SourceLocation ToForLoc, ToLParenLoc, ToRParenLoc; |
| 5860 | std::tie( |
| 5861 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, |
| 5862 | ToLParenLoc, ToRParenLoc) = *Imp; |
| 5863 | |
| 5864 | return new (Importer.getToContext()) ForStmt( |
| 5865 | Importer.getToContext(), |
| 5866 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc, |
| 5867 | ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5868 | } |
| 5869 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5870 | ExpectedStmt ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| 5871 | auto Imp = importSeq(S->getLabel(), S->getGotoLoc(), S->getLabelLoc()); |
| 5872 | if (!Imp) |
| 5873 | return Imp.takeError(); |
| 5874 | |
| 5875 | LabelDecl *ToLabel; |
| 5876 | SourceLocation ToGotoLoc, ToLabelLoc; |
| 5877 | std::tie(ToLabel, ToGotoLoc, ToLabelLoc) = *Imp; |
| 5878 | |
| 5879 | return new (Importer.getToContext()) GotoStmt( |
| 5880 | ToLabel, ToGotoLoc, ToLabelLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5881 | } |
| 5882 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5883 | ExpectedStmt ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 5884 | auto Imp = importSeq(S->getGotoLoc(), S->getStarLoc(), S->getTarget()); |
| 5885 | if (!Imp) |
| 5886 | return Imp.takeError(); |
| 5887 | |
| 5888 | SourceLocation ToGotoLoc, ToStarLoc; |
| 5889 | Expr *ToTarget; |
| 5890 | std::tie(ToGotoLoc, ToStarLoc, ToTarget) = *Imp; |
| 5891 | |
| 5892 | return new (Importer.getToContext()) IndirectGotoStmt( |
| 5893 | ToGotoLoc, ToStarLoc, ToTarget); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5894 | } |
| 5895 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5896 | ExpectedStmt ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 5897 | ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc()); |
| 5898 | if (!ToContinueLocOrErr) |
| 5899 | return ToContinueLocOrErr.takeError(); |
| 5900 | return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5901 | } |
| 5902 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5903 | ExpectedStmt ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 5904 | auto ToBreakLocOrErr = import(S->getBreakLoc()); |
| 5905 | if (!ToBreakLocOrErr) |
| 5906 | return ToBreakLocOrErr.takeError(); |
| 5907 | return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5908 | } |
| 5909 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5910 | ExpectedStmt ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| 5911 | auto Imp = importSeq( |
| 5912 | S->getReturnLoc(), S->getRetValue(), S->getNRVOCandidate()); |
| 5913 | if (!Imp) |
| 5914 | return Imp.takeError(); |
| 5915 | |
| 5916 | SourceLocation ToReturnLoc; |
| 5917 | Expr *ToRetValue; |
| 5918 | const VarDecl *ToNRVOCandidate; |
| 5919 | std::tie(ToReturnLoc, ToRetValue, ToNRVOCandidate) = *Imp; |
| 5920 | |
| 5921 | return new (Importer.getToContext()) ReturnStmt( |
| 5922 | ToReturnLoc, ToRetValue, ToNRVOCandidate); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5923 | } |
| 5924 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5925 | ExpectedStmt ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| 5926 | auto Imp = importSeq( |
| 5927 | S->getCatchLoc(), S->getExceptionDecl(), S->getHandlerBlock()); |
| 5928 | if (!Imp) |
| 5929 | return Imp.takeError(); |
| 5930 | |
| 5931 | SourceLocation ToCatchLoc; |
| 5932 | VarDecl *ToExceptionDecl; |
| 5933 | Stmt *ToHandlerBlock; |
| 5934 | std::tie(ToCatchLoc, ToExceptionDecl, ToHandlerBlock) = *Imp; |
| 5935 | |
| 5936 | return new (Importer.getToContext()) CXXCatchStmt ( |
| 5937 | ToCatchLoc, ToExceptionDecl, ToHandlerBlock); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5938 | } |
| 5939 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5940 | ExpectedStmt ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 5941 | ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc()); |
| 5942 | if (!ToTryLocOrErr) |
| 5943 | return ToTryLocOrErr.takeError(); |
| 5944 | |
| 5945 | ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock()); |
| 5946 | if (!ToTryBlockOrErr) |
| 5947 | return ToTryBlockOrErr.takeError(); |
| 5948 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5949 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 5950 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 5951 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5952 | if (auto ToHandlerOrErr = import(FromHandler)) |
| 5953 | ToHandlers[HI] = *ToHandlerOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5954 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5955 | return ToHandlerOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5956 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5957 | |
| 5958 | return CXXTryStmt::Create( |
| 5959 | Importer.getToContext(), *ToTryLocOrErr,*ToTryBlockOrErr, ToHandlers); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5960 | } |
| 5961 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5962 | ExpectedStmt ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
| 5963 | auto Imp1 = importSeq( |
| 5964 | S->getInit(), S->getRangeStmt(), S->getBeginStmt(), S->getEndStmt(), |
| 5965 | S->getCond(), S->getInc(), S->getLoopVarStmt(), S->getBody()); |
| 5966 | if (!Imp1) |
| 5967 | return Imp1.takeError(); |
| 5968 | auto Imp2 = importSeq( |
| 5969 | S->getForLoc(), S->getCoawaitLoc(), S->getColonLoc(), S->getRParenLoc()); |
| 5970 | if (!Imp2) |
| 5971 | return Imp2.takeError(); |
| 5972 | |
| 5973 | DeclStmt *ToRangeStmt, *ToBeginStmt, *ToEndStmt, *ToLoopVarStmt; |
| 5974 | Expr *ToCond, *ToInc; |
| 5975 | Stmt *ToInit, *ToBody; |
| 5976 | std::tie( |
| 5977 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 5978 | ToBody) = *Imp1; |
| 5979 | SourceLocation ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc; |
| 5980 | std::tie(ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc) = *Imp2; |
| 5981 | |
| 5982 | return new (Importer.getToContext()) CXXForRangeStmt( |
| 5983 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 5984 | ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5985 | } |
| 5986 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5987 | ExpectedStmt |
| 5988 | ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 5989 | auto Imp = importSeq( |
| 5990 | S->getElement(), S->getCollection(), S->getBody(), |
| 5991 | S->getForLoc(), S->getRParenLoc()); |
| 5992 | if (!Imp) |
| 5993 | return Imp.takeError(); |
| 5994 | |
| 5995 | Stmt *ToElement, *ToBody; |
| 5996 | Expr *ToCollection; |
| 5997 | SourceLocation ToForLoc, ToRParenLoc; |
| 5998 | std::tie(ToElement, ToCollection, ToBody, ToForLoc, ToRParenLoc) = *Imp; |
| 5999 | |
| 6000 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement, |
| 6001 | ToCollection, |
| 6002 | ToBody, |
| 6003 | ToForLoc, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6004 | ToRParenLoc); |
| 6005 | } |
| 6006 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6007 | ExpectedStmt ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 6008 | auto Imp = importSeq( |
| 6009 | S->getAtCatchLoc(), S->getRParenLoc(), S->getCatchParamDecl(), |
| 6010 | S->getCatchBody()); |
| 6011 | if (!Imp) |
| 6012 | return Imp.takeError(); |
| 6013 | |
| 6014 | SourceLocation ToAtCatchLoc, ToRParenLoc; |
| 6015 | VarDecl *ToCatchParamDecl; |
| 6016 | Stmt *ToCatchBody; |
| 6017 | std::tie(ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody) = *Imp; |
| 6018 | |
| 6019 | return new (Importer.getToContext()) ObjCAtCatchStmt ( |
| 6020 | ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6021 | } |
| 6022 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6023 | ExpectedStmt ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 6024 | ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc()); |
| 6025 | if (!ToAtFinallyLocOrErr) |
| 6026 | return ToAtFinallyLocOrErr.takeError(); |
| 6027 | ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody()); |
| 6028 | if (!ToAtFinallyStmtOrErr) |
| 6029 | return ToAtFinallyStmtOrErr.takeError(); |
| 6030 | return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr, |
| 6031 | *ToAtFinallyStmtOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6032 | } |
| 6033 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6034 | ExpectedStmt ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 6035 | auto Imp = importSeq( |
| 6036 | S->getAtTryLoc(), S->getTryBody(), S->getFinallyStmt()); |
| 6037 | if (!Imp) |
| 6038 | return Imp.takeError(); |
| 6039 | |
| 6040 | SourceLocation ToAtTryLoc; |
| 6041 | Stmt *ToTryBody, *ToFinallyStmt; |
| 6042 | std::tie(ToAtTryLoc, ToTryBody, ToFinallyStmt) = *Imp; |
| 6043 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6044 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 6045 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 6046 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6047 | if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt)) |
| 6048 | ToCatchStmts[CI] = *ToCatchStmtOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6049 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6050 | return ToCatchStmtOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6051 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6052 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6053 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6054 | ToAtTryLoc, ToTryBody, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6055 | ToCatchStmts.begin(), ToCatchStmts.size(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6056 | ToFinallyStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6057 | } |
| 6058 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6059 | ExpectedStmt ASTNodeImporter::VisitObjCAtSynchronizedStmt |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6060 | (ObjCAtSynchronizedStmt *S) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6061 | auto Imp = importSeq( |
| 6062 | S->getAtSynchronizedLoc(), S->getSynchExpr(), S->getSynchBody()); |
| 6063 | if (!Imp) |
| 6064 | return Imp.takeError(); |
| 6065 | |
| 6066 | SourceLocation ToAtSynchronizedLoc; |
| 6067 | Expr *ToSynchExpr; |
| 6068 | Stmt *ToSynchBody; |
| 6069 | std::tie(ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody) = *Imp; |
| 6070 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6071 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 6072 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 6073 | } |
| 6074 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6075 | ExpectedStmt ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 6076 | ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc()); |
| 6077 | if (!ToThrowLocOrErr) |
| 6078 | return ToThrowLocOrErr.takeError(); |
| 6079 | ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr()); |
| 6080 | if (!ToThrowExprOrErr) |
| 6081 | return ToThrowExprOrErr.takeError(); |
| 6082 | return new (Importer.getToContext()) ObjCAtThrowStmt( |
| 6083 | *ToThrowLocOrErr, *ToThrowExprOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6084 | } |
| 6085 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6086 | ExpectedStmt ASTNodeImporter::VisitObjCAutoreleasePoolStmt( |
| 6087 | ObjCAutoreleasePoolStmt *S) { |
| 6088 | ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc()); |
| 6089 | if (!ToAtLocOrErr) |
| 6090 | return ToAtLocOrErr.takeError(); |
| 6091 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 6092 | if (!ToSubStmtOrErr) |
| 6093 | return ToSubStmtOrErr.takeError(); |
| 6094 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr, |
| 6095 | *ToSubStmtOrErr); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6096 | } |
| 6097 | |
| 6098 | //---------------------------------------------------------------------------- |
| 6099 | // Import Expressions |
| 6100 | //---------------------------------------------------------------------------- |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6101 | ExpectedStmt ASTNodeImporter::VisitExpr(Expr *E) { |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6102 | Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node) |
| 6103 | << E->getStmtClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6104 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6105 | } |
| 6106 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6107 | ExpectedStmt ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| 6108 | auto Imp = importSeq( |
| 6109 | E->getBuiltinLoc(), E->getSubExpr(), E->getWrittenTypeInfo(), |
| 6110 | E->getRParenLoc(), E->getType()); |
| 6111 | if (!Imp) |
| 6112 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6113 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6114 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6115 | Expr *ToSubExpr; |
| 6116 | TypeSourceInfo *ToWrittenTypeInfo; |
| 6117 | QualType ToType; |
| 6118 | std::tie(ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType) = |
| 6119 | *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6120 | |
| 6121 | return new (Importer.getToContext()) VAArgExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6122 | ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType, |
| 6123 | E->isMicrosoftABI()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6124 | } |
| 6125 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6126 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6127 | ExpectedStmt ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 6128 | ExpectedType TypeOrErr = import(E->getType()); |
| 6129 | if (!TypeOrErr) |
| 6130 | return TypeOrErr.takeError(); |
| 6131 | |
| 6132 | ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc()); |
| 6133 | if (!BeginLocOrErr) |
| 6134 | return BeginLocOrErr.takeError(); |
| 6135 | |
| 6136 | return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6137 | } |
| 6138 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6139 | ExpectedStmt ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { |
| 6140 | auto Imp = importSeq( |
| 6141 | E->getBeginLoc(), E->getType(), E->getFunctionName()); |
| 6142 | if (!Imp) |
| 6143 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6144 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6145 | SourceLocation ToBeginLoc; |
| 6146 | QualType ToType; |
| 6147 | StringLiteral *ToFunctionName; |
| 6148 | std::tie(ToBeginLoc, ToType, ToFunctionName) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6149 | |
Bruno Ricci | 17ff026 | 2018-10-27 19:21:19 +0000 | [diff] [blame] | 6150 | return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType, |
| 6151 | E->getIdentKind(), ToFunctionName); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6152 | } |
| 6153 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6154 | ExpectedStmt ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
| 6155 | auto Imp = importSeq( |
| 6156 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDecl(), |
| 6157 | E->getLocation(), E->getType()); |
| 6158 | if (!Imp) |
| 6159 | return Imp.takeError(); |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6160 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6161 | NestedNameSpecifierLoc ToQualifierLoc; |
| 6162 | SourceLocation ToTemplateKeywordLoc, ToLocation; |
| 6163 | ValueDecl *ToDecl; |
| 6164 | QualType ToType; |
| 6165 | std::tie(ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, ToLocation, ToType) = |
| 6166 | *Imp; |
| 6167 | |
| 6168 | NamedDecl *ToFoundD = nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6169 | if (E->getDecl() != E->getFoundDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6170 | auto FoundDOrErr = import(E->getFoundDecl()); |
| 6171 | if (!FoundDOrErr) |
| 6172 | return FoundDOrErr.takeError(); |
| 6173 | ToFoundD = *FoundDOrErr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6174 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6175 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6176 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6177 | TemplateArgumentListInfo *ToResInfo = nullptr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6178 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6179 | if (Error Err = |
| 6180 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 6181 | return std::move(Err); |
| 6182 | ToResInfo = &ToTAInfo; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6183 | } |
| 6184 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6185 | auto *ToE = DeclRefExpr::Create( |
| 6186 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, |
| 6187 | E->refersToEnclosingVariableOrCapture(), ToLocation, ToType, |
| 6188 | E->getValueKind(), ToFoundD, ToResInfo); |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 6189 | if (E->hadMultipleCandidates()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6190 | ToE->setHadMultipleCandidates(true); |
| 6191 | return ToE; |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 6192 | } |
| 6193 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6194 | ExpectedStmt ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 6195 | ExpectedType TypeOrErr = import(E->getType()); |
| 6196 | if (!TypeOrErr) |
| 6197 | return TypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6198 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6199 | return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6200 | } |
| 6201 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6202 | ExpectedStmt ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { |
| 6203 | ExpectedExpr ToInitOrErr = import(E->getInit()); |
| 6204 | if (!ToInitOrErr) |
| 6205 | return ToInitOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6206 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6207 | ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc()); |
| 6208 | if (!ToEqualOrColonLocOrErr) |
| 6209 | return ToEqualOrColonLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6210 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6211 | SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6212 | // List elements from the second, the first is Init itself |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6213 | for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) { |
| 6214 | if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I))) |
| 6215 | ToIndexExprs[I - 1] = *ToArgOrErr; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6216 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6217 | return ToArgOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6218 | } |
| 6219 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6220 | SmallVector<Designator, 4> ToDesignators(E->size()); |
| 6221 | if (Error Err = ImportContainerChecked(E->designators(), ToDesignators)) |
| 6222 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6223 | |
| 6224 | return DesignatedInitExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6225 | Importer.getToContext(), ToDesignators, |
| 6226 | ToIndexExprs, *ToEqualOrColonLocOrErr, |
| 6227 | E->usesGNUSyntax(), *ToInitOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6228 | } |
| 6229 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6230 | ExpectedStmt |
| 6231 | ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 6232 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6233 | if (!ToTypeOrErr) |
| 6234 | return ToTypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6235 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6236 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6237 | if (!ToLocationOrErr) |
| 6238 | return ToLocationOrErr.takeError(); |
| 6239 | |
| 6240 | return new (Importer.getToContext()) CXXNullPtrLiteralExpr( |
| 6241 | *ToTypeOrErr, *ToLocationOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6242 | } |
| 6243 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6244 | ExpectedStmt ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 6245 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6246 | if (!ToTypeOrErr) |
| 6247 | return ToTypeOrErr.takeError(); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6248 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6249 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6250 | if (!ToLocationOrErr) |
| 6251 | return ToLocationOrErr.takeError(); |
| 6252 | |
| 6253 | return IntegerLiteral::Create( |
| 6254 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6255 | } |
| 6256 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6257 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6258 | ExpectedStmt ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 6259 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6260 | if (!ToTypeOrErr) |
| 6261 | return ToTypeOrErr.takeError(); |
| 6262 | |
| 6263 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6264 | if (!ToLocationOrErr) |
| 6265 | return ToLocationOrErr.takeError(); |
| 6266 | |
| 6267 | return FloatingLiteral::Create( |
| 6268 | Importer.getToContext(), E->getValue(), E->isExact(), |
| 6269 | *ToTypeOrErr, *ToLocationOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6270 | } |
| 6271 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6272 | ExpectedStmt ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) { |
| 6273 | auto ToTypeOrErr = import(E->getType()); |
| 6274 | if (!ToTypeOrErr) |
| 6275 | return ToTypeOrErr.takeError(); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6276 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6277 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6278 | if (!ToSubExprOrErr) |
| 6279 | return ToSubExprOrErr.takeError(); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6280 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6281 | return new (Importer.getToContext()) ImaginaryLiteral( |
| 6282 | *ToSubExprOrErr, *ToTypeOrErr); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6283 | } |
| 6284 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6285 | ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 6286 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6287 | if (!ToTypeOrErr) |
| 6288 | return ToTypeOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6289 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6290 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6291 | if (!ToLocationOrErr) |
| 6292 | return ToLocationOrErr.takeError(); |
| 6293 | |
| 6294 | return new (Importer.getToContext()) CharacterLiteral( |
| 6295 | E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr); |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 6296 | } |
| 6297 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6298 | ExpectedStmt ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 6299 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6300 | if (!ToTypeOrErr) |
| 6301 | return ToTypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6302 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6303 | SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated()); |
| 6304 | if (Error Err = ImportArrayChecked( |
| 6305 | E->tokloc_begin(), E->tokloc_end(), ToLocations.begin())) |
| 6306 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6307 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6308 | return StringLiteral::Create( |
| 6309 | Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(), |
| 6310 | *ToTypeOrErr, ToLocations.data(), ToLocations.size()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6311 | } |
| 6312 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6313 | ExpectedStmt ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 6314 | auto Imp = importSeq( |
| 6315 | E->getLParenLoc(), E->getTypeSourceInfo(), E->getType(), |
| 6316 | E->getInitializer()); |
| 6317 | if (!Imp) |
| 6318 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6319 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6320 | SourceLocation ToLParenLoc; |
| 6321 | TypeSourceInfo *ToTypeSourceInfo; |
| 6322 | QualType ToType; |
| 6323 | Expr *ToInitializer; |
| 6324 | std::tie(ToLParenLoc, ToTypeSourceInfo, ToType, ToInitializer) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6325 | |
| 6326 | return new (Importer.getToContext()) CompoundLiteralExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6327 | ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(), |
| 6328 | ToInitializer, E->isFileScope()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6329 | } |
| 6330 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6331 | ExpectedStmt ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { |
| 6332 | auto Imp = importSeq( |
| 6333 | E->getBuiltinLoc(), E->getType(), E->getRParenLoc()); |
| 6334 | if (!Imp) |
| 6335 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6336 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6337 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6338 | QualType ToType; |
| 6339 | std::tie(ToBuiltinLoc, ToType, ToRParenLoc) = *Imp; |
| 6340 | |
| 6341 | SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs()); |
| 6342 | if (Error Err = ImportArrayChecked( |
| 6343 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 6344 | ToExprs.begin())) |
| 6345 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6346 | |
| 6347 | return new (Importer.getToContext()) AtomicExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6348 | ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6349 | } |
| 6350 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6351 | ExpectedStmt ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 6352 | auto Imp = importSeq( |
| 6353 | E->getAmpAmpLoc(), E->getLabelLoc(), E->getLabel(), E->getType()); |
| 6354 | if (!Imp) |
| 6355 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6356 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6357 | SourceLocation ToAmpAmpLoc, ToLabelLoc; |
| 6358 | LabelDecl *ToLabel; |
| 6359 | QualType ToType; |
| 6360 | std::tie(ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6361 | |
| 6362 | return new (Importer.getToContext()) AddrLabelExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6363 | ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6364 | } |
| 6365 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6366 | ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| 6367 | auto Imp = importSeq(E->getLParen(), E->getRParen(), E->getSubExpr()); |
| 6368 | if (!Imp) |
| 6369 | return Imp.takeError(); |
| 6370 | |
| 6371 | SourceLocation ToLParen, ToRParen; |
| 6372 | Expr *ToSubExpr; |
| 6373 | std::tie(ToLParen, ToRParen, ToSubExpr) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6374 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6375 | return new (Importer.getToContext()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6376 | ParenExpr(ToLParen, ToRParen, ToSubExpr); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6377 | } |
| 6378 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6379 | ExpectedStmt ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 6380 | SmallVector<Expr *, 4> ToExprs(E->getNumExprs()); |
| 6381 | if (Error Err = ImportContainerChecked(E->exprs(), ToExprs)) |
| 6382 | return std::move(Err); |
| 6383 | |
| 6384 | ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc()); |
| 6385 | if (!ToLParenLocOrErr) |
| 6386 | return ToLParenLocOrErr.takeError(); |
| 6387 | |
| 6388 | ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc()); |
| 6389 | if (!ToRParenLocOrErr) |
| 6390 | return ToRParenLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6391 | |
| 6392 | return new (Importer.getToContext()) ParenListExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6393 | Importer.getToContext(), *ToLParenLocOrErr, ToExprs, *ToRParenLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6394 | } |
| 6395 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6396 | ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| 6397 | auto Imp = importSeq( |
| 6398 | E->getSubStmt(), E->getType(), E->getLParenLoc(), E->getRParenLoc()); |
| 6399 | if (!Imp) |
| 6400 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6401 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6402 | CompoundStmt *ToSubStmt; |
| 6403 | QualType ToType; |
| 6404 | SourceLocation ToLParenLoc, ToRParenLoc; |
| 6405 | std::tie(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6406 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6407 | return new (Importer.getToContext()) StmtExpr( |
| 6408 | ToSubStmt, ToType, ToLParenLoc, ToRParenLoc); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6409 | } |
| 6410 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6411 | ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| 6412 | auto Imp = importSeq( |
| 6413 | E->getSubExpr(), E->getType(), E->getOperatorLoc()); |
| 6414 | if (!Imp) |
| 6415 | return Imp.takeError(); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6416 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6417 | Expr *ToSubExpr; |
| 6418 | QualType ToType; |
| 6419 | SourceLocation ToOperatorLoc; |
| 6420 | std::tie(ToSubExpr, ToType, ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6421 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6422 | return new (Importer.getToContext()) UnaryOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6423 | ToSubExpr, E->getOpcode(), ToType, E->getValueKind(), E->getObjectKind(), |
| 6424 | ToOperatorLoc, E->canOverflow()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6425 | } |
| 6426 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6427 | ExpectedStmt |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6428 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6429 | auto Imp = importSeq(E->getType(), E->getOperatorLoc(), E->getRParenLoc()); |
| 6430 | if (!Imp) |
| 6431 | return Imp.takeError(); |
| 6432 | |
| 6433 | QualType ToType; |
| 6434 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 6435 | std::tie(ToType, ToOperatorLoc, ToRParenLoc) = *Imp; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6436 | |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6437 | if (E->isArgumentType()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6438 | Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr = |
| 6439 | import(E->getArgumentTypeInfo()); |
| 6440 | if (!ToArgumentTypeInfoOrErr) |
| 6441 | return ToArgumentTypeInfoOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6442 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6443 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6444 | E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc, |
| 6445 | ToRParenLoc); |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6446 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6447 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6448 | ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr()); |
| 6449 | if (!ToArgumentExprOrErr) |
| 6450 | return ToArgumentExprOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6451 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6452 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6453 | E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc); |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6454 | } |
| 6455 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6456 | ExpectedStmt ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| 6457 | auto Imp = importSeq( |
| 6458 | E->getLHS(), E->getRHS(), E->getType(), E->getOperatorLoc()); |
| 6459 | if (!Imp) |
| 6460 | return Imp.takeError(); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6461 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6462 | Expr *ToLHS, *ToRHS; |
| 6463 | QualType ToType; |
| 6464 | SourceLocation ToOperatorLoc; |
| 6465 | std::tie(ToLHS, ToRHS, ToType, ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6466 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6467 | return new (Importer.getToContext()) BinaryOperator( |
| 6468 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6469 | E->getObjectKind(), ToOperatorLoc, E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6470 | } |
| 6471 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6472 | ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| 6473 | auto Imp = importSeq( |
| 6474 | E->getCond(), E->getQuestionLoc(), E->getLHS(), E->getColonLoc(), |
| 6475 | E->getRHS(), E->getType()); |
| 6476 | if (!Imp) |
| 6477 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6478 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6479 | Expr *ToCond, *ToLHS, *ToRHS; |
| 6480 | SourceLocation ToQuestionLoc, ToColonLoc; |
| 6481 | QualType ToType; |
| 6482 | std::tie(ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6483 | |
| 6484 | return new (Importer.getToContext()) ConditionalOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6485 | ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType, |
| 6486 | E->getValueKind(), E->getObjectKind()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6487 | } |
| 6488 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6489 | ExpectedStmt ASTNodeImporter::VisitBinaryConditionalOperator( |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6490 | BinaryConditionalOperator *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6491 | auto Imp = importSeq( |
| 6492 | E->getCommon(), E->getOpaqueValue(), E->getCond(), E->getTrueExpr(), |
| 6493 | E->getFalseExpr(), E->getQuestionLoc(), E->getColonLoc(), E->getType()); |
| 6494 | if (!Imp) |
| 6495 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6496 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6497 | Expr *ToCommon, *ToCond, *ToTrueExpr, *ToFalseExpr; |
| 6498 | OpaqueValueExpr *ToOpaqueValue; |
| 6499 | SourceLocation ToQuestionLoc, ToColonLoc; |
| 6500 | QualType ToType; |
| 6501 | std::tie( |
| 6502 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, ToQuestionLoc, |
| 6503 | ToColonLoc, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6504 | |
| 6505 | return new (Importer.getToContext()) BinaryConditionalOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6506 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, |
| 6507 | ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(), |
| 6508 | E->getObjectKind()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6509 | } |
| 6510 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6511 | ExpectedStmt ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 6512 | auto Imp = importSeq( |
| 6513 | E->getBeginLoc(), E->getQueriedTypeSourceInfo(), |
| 6514 | E->getDimensionExpression(), E->getEndLoc(), E->getType()); |
| 6515 | if (!Imp) |
| 6516 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6517 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6518 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6519 | TypeSourceInfo *ToQueriedTypeSourceInfo; |
| 6520 | Expr *ToDimensionExpression; |
| 6521 | QualType ToType; |
| 6522 | std::tie( |
| 6523 | ToBeginLoc, ToQueriedTypeSourceInfo, ToDimensionExpression, ToEndLoc, |
| 6524 | ToType) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6525 | |
| 6526 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6527 | ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(), |
| 6528 | ToDimensionExpression, ToEndLoc, ToType); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6529 | } |
| 6530 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6531 | ExpectedStmt ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 6532 | auto Imp = importSeq( |
| 6533 | E->getBeginLoc(), E->getQueriedExpression(), E->getEndLoc(), E->getType()); |
| 6534 | if (!Imp) |
| 6535 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6536 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6537 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6538 | Expr *ToQueriedExpression; |
| 6539 | QualType ToType; |
| 6540 | std::tie(ToBeginLoc, ToQueriedExpression, ToEndLoc, ToType) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6541 | |
| 6542 | return new (Importer.getToContext()) ExpressionTraitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6543 | ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(), |
| 6544 | ToEndLoc, ToType); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6545 | } |
| 6546 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6547 | ExpectedStmt ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| 6548 | auto Imp = importSeq( |
| 6549 | E->getLocation(), E->getType(), E->getSourceExpr()); |
| 6550 | if (!Imp) |
| 6551 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6552 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6553 | SourceLocation ToLocation; |
| 6554 | QualType ToType; |
| 6555 | Expr *ToSourceExpr; |
| 6556 | std::tie(ToLocation, ToType, ToSourceExpr) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6557 | |
| 6558 | return new (Importer.getToContext()) OpaqueValueExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6559 | ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6560 | } |
| 6561 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6562 | ExpectedStmt ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 6563 | auto Imp = importSeq( |
| 6564 | E->getLHS(), E->getRHS(), E->getType(), E->getRBracketLoc()); |
| 6565 | if (!Imp) |
| 6566 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6567 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6568 | Expr *ToLHS, *ToRHS; |
| 6569 | SourceLocation ToRBracketLoc; |
| 6570 | QualType ToType; |
| 6571 | std::tie(ToLHS, ToRHS, ToType, ToRBracketLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6572 | |
| 6573 | return new (Importer.getToContext()) ArraySubscriptExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6574 | ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(), |
| 6575 | ToRBracketLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6576 | } |
| 6577 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6578 | ExpectedStmt |
| 6579 | ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 6580 | auto Imp = importSeq( |
| 6581 | E->getLHS(), E->getRHS(), E->getType(), E->getComputationLHSType(), |
| 6582 | E->getComputationResultType(), E->getOperatorLoc()); |
| 6583 | if (!Imp) |
| 6584 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6585 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6586 | Expr *ToLHS, *ToRHS; |
| 6587 | QualType ToType, ToComputationLHSType, ToComputationResultType; |
| 6588 | SourceLocation ToOperatorLoc; |
| 6589 | std::tie(ToLHS, ToRHS, ToType, ToComputationLHSType, ToComputationResultType, |
| 6590 | ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6591 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6592 | return new (Importer.getToContext()) CompoundAssignOperator( |
| 6593 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6594 | E->getObjectKind(), ToComputationLHSType, ToComputationResultType, |
| 6595 | ToOperatorLoc, E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6596 | } |
| 6597 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6598 | Expected<CXXCastPath> |
| 6599 | ASTNodeImporter::ImportCastPath(CastExpr *CE) { |
| 6600 | CXXCastPath Path; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6601 | 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] | 6602 | if (auto SpecOrErr = import(*I)) |
| 6603 | Path.push_back(*SpecOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6604 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6605 | return SpecOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6606 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6607 | return Path; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6608 | } |
| 6609 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6610 | ExpectedStmt ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 6611 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6612 | if (!ToTypeOrErr) |
| 6613 | return ToTypeOrErr.takeError(); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6614 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6615 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6616 | if (!ToSubExprOrErr) |
| 6617 | return ToSubExprOrErr.takeError(); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6618 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6619 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6620 | if (!ToBasePathOrErr) |
| 6621 | return ToBasePathOrErr.takeError(); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6622 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6623 | return ImplicitCastExpr::Create( |
| 6624 | Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr, |
| 6625 | &(*ToBasePathOrErr), E->getValueKind()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6626 | } |
| 6627 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6628 | ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
| 6629 | auto Imp1 = importSeq( |
| 6630 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten()); |
| 6631 | if (!Imp1) |
| 6632 | return Imp1.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6633 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6634 | QualType ToType; |
| 6635 | Expr *ToSubExpr; |
| 6636 | TypeSourceInfo *ToTypeInfoAsWritten; |
| 6637 | std::tie(ToType, ToSubExpr, ToTypeInfoAsWritten) = *Imp1; |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +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(); |
| 6642 | CXXCastPath *ToBasePath = &(*ToBasePathOrErr); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6643 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6644 | switch (E->getStmtClass()) { |
| 6645 | case Stmt::CStyleCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6646 | auto *CCE = cast<CStyleCastExpr>(E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6647 | ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc()); |
| 6648 | if (!ToLParenLocOrErr) |
| 6649 | return ToLParenLocOrErr.takeError(); |
| 6650 | ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc()); |
| 6651 | if (!ToRParenLocOrErr) |
| 6652 | return ToRParenLocOrErr.takeError(); |
| 6653 | return CStyleCastExpr::Create( |
| 6654 | Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(), |
| 6655 | ToSubExpr, ToBasePath, ToTypeInfoAsWritten, *ToLParenLocOrErr, |
| 6656 | *ToRParenLocOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6657 | } |
| 6658 | |
| 6659 | case Stmt::CXXFunctionalCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6660 | auto *FCE = cast<CXXFunctionalCastExpr>(E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6661 | ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc()); |
| 6662 | if (!ToLParenLocOrErr) |
| 6663 | return ToLParenLocOrErr.takeError(); |
| 6664 | ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc()); |
| 6665 | if (!ToRParenLocOrErr) |
| 6666 | return ToRParenLocOrErr.takeError(); |
| 6667 | return CXXFunctionalCastExpr::Create( |
| 6668 | Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten, |
| 6669 | E->getCastKind(), ToSubExpr, ToBasePath, *ToLParenLocOrErr, |
| 6670 | *ToRParenLocOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6671 | } |
| 6672 | |
| 6673 | case Stmt::ObjCBridgedCastExprClass: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6674 | auto *OCE = cast<ObjCBridgedCastExpr>(E); |
| 6675 | ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc()); |
| 6676 | if (!ToLParenLocOrErr) |
| 6677 | return ToLParenLocOrErr.takeError(); |
| 6678 | ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc()); |
| 6679 | if (!ToBridgeKeywordLocOrErr) |
| 6680 | return ToBridgeKeywordLocOrErr.takeError(); |
| 6681 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 6682 | *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), |
| 6683 | *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6684 | } |
| 6685 | default: |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6686 | llvm_unreachable("Cast expression of unsupported type!"); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6687 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6688 | } |
| 6689 | } |
| 6690 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6691 | ExpectedStmt ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *E) { |
| 6692 | SmallVector<OffsetOfNode, 4> ToNodes; |
| 6693 | for (int I = 0, N = E->getNumComponents(); I < N; ++I) { |
| 6694 | const OffsetOfNode &FromNode = E->getComponent(I); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6695 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6696 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6697 | if (FromNode.getKind() != OffsetOfNode::Base) { |
| 6698 | auto Imp = importSeq(FromNode.getBeginLoc(), FromNode.getEndLoc()); |
| 6699 | if (!Imp) |
| 6700 | return Imp.takeError(); |
| 6701 | std::tie(ToBeginLoc, ToEndLoc) = *Imp; |
| 6702 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6703 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6704 | switch (FromNode.getKind()) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6705 | case OffsetOfNode::Array: |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6706 | ToNodes.push_back( |
| 6707 | OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6708 | break; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6709 | case OffsetOfNode::Base: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6710 | auto ToBSOrErr = import(FromNode.getBase()); |
| 6711 | if (!ToBSOrErr) |
| 6712 | return ToBSOrErr.takeError(); |
| 6713 | ToNodes.push_back(OffsetOfNode(*ToBSOrErr)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6714 | break; |
| 6715 | } |
| 6716 | case OffsetOfNode::Field: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6717 | auto ToFieldOrErr = import(FromNode.getField()); |
| 6718 | if (!ToFieldOrErr) |
| 6719 | return ToFieldOrErr.takeError(); |
| 6720 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6721 | break; |
| 6722 | } |
| 6723 | case OffsetOfNode::Identifier: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6724 | IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName()); |
| 6725 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6726 | break; |
| 6727 | } |
| 6728 | } |
| 6729 | } |
| 6730 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6731 | SmallVector<Expr *, 4> ToExprs(E->getNumExpressions()); |
| 6732 | for (int I = 0, N = E->getNumExpressions(); I < N; ++I) { |
| 6733 | ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I)); |
| 6734 | if (!ToIndexExprOrErr) |
| 6735 | return ToIndexExprOrErr.takeError(); |
| 6736 | ToExprs[I] = *ToIndexExprOrErr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6737 | } |
| 6738 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6739 | auto Imp = importSeq( |
| 6740 | E->getType(), E->getTypeSourceInfo(), E->getOperatorLoc(), |
| 6741 | E->getRParenLoc()); |
| 6742 | if (!Imp) |
| 6743 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6744 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6745 | QualType ToType; |
| 6746 | TypeSourceInfo *ToTypeSourceInfo; |
| 6747 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 6748 | std::tie(ToType, ToTypeSourceInfo, ToOperatorLoc, ToRParenLoc) = *Imp; |
| 6749 | |
| 6750 | return OffsetOfExpr::Create( |
| 6751 | Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes, |
| 6752 | ToExprs, ToRParenLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6753 | } |
| 6754 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6755 | ExpectedStmt ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 6756 | auto Imp = importSeq( |
| 6757 | E->getType(), E->getOperand(), E->getBeginLoc(), E->getEndLoc()); |
| 6758 | if (!Imp) |
| 6759 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6760 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6761 | QualType ToType; |
| 6762 | Expr *ToOperand; |
| 6763 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6764 | std::tie(ToType, ToOperand, ToBeginLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6765 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6766 | CanThrowResult ToCanThrow; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6767 | if (E->isValueDependent()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6768 | ToCanThrow = CT_Dependent; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6769 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6770 | ToCanThrow = E->getValue() ? CT_Can : CT_Cannot; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6771 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6772 | return new (Importer.getToContext()) CXXNoexceptExpr( |
| 6773 | ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6774 | } |
| 6775 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6776 | ExpectedStmt ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| 6777 | auto Imp = importSeq(E->getSubExpr(), E->getType(), E->getThrowLoc()); |
| 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 | Expr *ToSubExpr; |
| 6782 | QualType ToType; |
| 6783 | SourceLocation ToThrowLoc; |
| 6784 | std::tie(ToSubExpr, ToType, ToThrowLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6785 | |
| 6786 | return new (Importer.getToContext()) CXXThrowExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6787 | ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6788 | } |
| 6789 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6790 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| 6791 | ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation()); |
| 6792 | if (!ToUsedLocOrErr) |
| 6793 | return ToUsedLocOrErr.takeError(); |
| 6794 | |
| 6795 | auto ToParamOrErr = import(E->getParam()); |
| 6796 | if (!ToParamOrErr) |
| 6797 | return ToParamOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6798 | |
| 6799 | return CXXDefaultArgExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6800 | Importer.getToContext(), *ToUsedLocOrErr, *ToParamOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6801 | } |
| 6802 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6803 | ExpectedStmt |
| 6804 | ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| 6805 | auto Imp = importSeq( |
| 6806 | E->getType(), E->getTypeSourceInfo(), E->getRParenLoc()); |
| 6807 | if (!Imp) |
| 6808 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6809 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6810 | QualType ToType; |
| 6811 | TypeSourceInfo *ToTypeSourceInfo; |
| 6812 | SourceLocation ToRParenLoc; |
| 6813 | std::tie(ToType, ToTypeSourceInfo, ToRParenLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6814 | |
| 6815 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6816 | ToType, ToTypeSourceInfo, ToRParenLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6817 | } |
| 6818 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6819 | ExpectedStmt |
| 6820 | ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 6821 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6822 | if (!ToSubExprOrErr) |
| 6823 | return ToSubExprOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6824 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6825 | auto ToDtorOrErr = import(E->getTemporary()->getDestructor()); |
| 6826 | if (!ToDtorOrErr) |
| 6827 | return ToDtorOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6828 | |
| 6829 | ASTContext &ToCtx = Importer.getToContext(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6830 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr); |
| 6831 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6832 | } |
| 6833 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6834 | ExpectedStmt |
| 6835 | ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { |
| 6836 | auto Imp = importSeq( |
| 6837 | E->getConstructor(), E->getType(), E->getTypeSourceInfo(), |
| 6838 | E->getParenOrBraceRange()); |
| 6839 | if (!Imp) |
| 6840 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6841 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6842 | CXXConstructorDecl *ToConstructor; |
| 6843 | QualType ToType; |
| 6844 | TypeSourceInfo *ToTypeSourceInfo; |
| 6845 | SourceRange ToParenOrBraceRange; |
| 6846 | std::tie(ToConstructor, ToType, ToTypeSourceInfo, ToParenOrBraceRange) = *Imp; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6847 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6848 | SmallVector<Expr *, 8> ToArgs(E->getNumArgs()); |
| 6849 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 6850 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6851 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6852 | return new (Importer.getToContext()) CXXTemporaryObjectExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6853 | Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs, |
| 6854 | ToParenOrBraceRange, E->hadMultipleCandidates(), |
| 6855 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 6856 | E->requiresZeroInitialization()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6857 | } |
| 6858 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6859 | ExpectedStmt |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6860 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6861 | auto Imp = importSeq( |
| 6862 | E->getType(), E->GetTemporaryExpr(), E->getExtendingDecl()); |
| 6863 | if (!Imp) |
| 6864 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6865 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6866 | QualType ToType; |
| 6867 | Expr *ToTemporaryExpr; |
| 6868 | const ValueDecl *ToExtendingDecl; |
| 6869 | std::tie(ToType, ToTemporaryExpr, ToExtendingDecl) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6870 | |
| 6871 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6872 | ToType, ToTemporaryExpr, E->isBoundToLvalueReference()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6873 | |
| 6874 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6875 | ToMTE->setExtendingDecl(ToExtendingDecl, E->getManglingNumber()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6876 | return ToMTE; |
| 6877 | } |
| 6878 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6879 | ExpectedStmt ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { |
| 6880 | auto Imp = importSeq( |
| 6881 | E->getType(), E->getPattern(), E->getEllipsisLoc()); |
| 6882 | if (!Imp) |
| 6883 | return Imp.takeError(); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6884 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6885 | QualType ToType; |
| 6886 | Expr *ToPattern; |
| 6887 | SourceLocation ToEllipsisLoc; |
| 6888 | std::tie(ToType, ToPattern, ToEllipsisLoc) = *Imp; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6889 | |
| 6890 | return new (Importer.getToContext()) PackExpansionExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6891 | ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions()); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6892 | } |
| 6893 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6894 | ExpectedStmt ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { |
| 6895 | auto Imp = importSeq( |
| 6896 | E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc()); |
| 6897 | if (!Imp) |
| 6898 | return Imp.takeError(); |
| 6899 | |
| 6900 | SourceLocation ToOperatorLoc, ToPackLoc, ToRParenLoc; |
| 6901 | NamedDecl *ToPack; |
| 6902 | std::tie(ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc) = *Imp; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6903 | |
| 6904 | Optional<unsigned> Length; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6905 | if (!E->isValueDependent()) |
| 6906 | Length = E->getPackLength(); |
| 6907 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6908 | SmallVector<TemplateArgument, 8> ToPartialArguments; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6909 | if (E->isPartiallySubstituted()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6910 | if (Error Err = ImportTemplateArguments( |
| 6911 | E->getPartialArguments().data(), |
| 6912 | E->getPartialArguments().size(), |
| 6913 | ToPartialArguments)) |
| 6914 | return std::move(Err); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6915 | } |
| 6916 | |
| 6917 | return SizeOfPackExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6918 | Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc, |
| 6919 | Length, ToPartialArguments); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6920 | } |
| 6921 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6922 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6923 | ExpectedStmt ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) { |
| 6924 | auto Imp = importSeq( |
| 6925 | E->getOperatorNew(), E->getOperatorDelete(), E->getTypeIdParens(), |
| 6926 | E->getArraySize(), E->getInitializer(), E->getType(), |
| 6927 | E->getAllocatedTypeSourceInfo(), E->getSourceRange(), |
| 6928 | E->getDirectInitRange()); |
| 6929 | if (!Imp) |
| 6930 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6931 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6932 | FunctionDecl *ToOperatorNew, *ToOperatorDelete; |
| 6933 | SourceRange ToTypeIdParens, ToSourceRange, ToDirectInitRange; |
| 6934 | Expr *ToArraySize, *ToInitializer; |
| 6935 | QualType ToType; |
| 6936 | TypeSourceInfo *ToAllocatedTypeSourceInfo; |
| 6937 | std::tie( |
| 6938 | ToOperatorNew, ToOperatorDelete, ToTypeIdParens, ToArraySize, ToInitializer, |
| 6939 | ToType, ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6940 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6941 | SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs()); |
| 6942 | if (Error Err = |
| 6943 | ImportContainerChecked(E->placement_arguments(), ToPlacementArgs)) |
| 6944 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6945 | |
| 6946 | return new (Importer.getToContext()) CXXNewExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6947 | Importer.getToContext(), E->isGlobalNew(), ToOperatorNew, |
| 6948 | ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(), |
| 6949 | ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(), |
| 6950 | ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange, |
| 6951 | ToDirectInitRange); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6952 | } |
| 6953 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6954 | ExpectedStmt ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 6955 | auto Imp = importSeq( |
| 6956 | E->getType(), E->getOperatorDelete(), E->getArgument(), E->getBeginLoc()); |
| 6957 | if (!Imp) |
| 6958 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6959 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6960 | QualType ToType; |
| 6961 | FunctionDecl *ToOperatorDelete; |
| 6962 | Expr *ToArgument; |
| 6963 | SourceLocation ToBeginLoc; |
| 6964 | std::tie(ToType, ToOperatorDelete, ToArgument, ToBeginLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6965 | |
| 6966 | return new (Importer.getToContext()) CXXDeleteExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6967 | ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(), |
| 6968 | E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument, |
| 6969 | ToBeginLoc); |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6970 | } |
| 6971 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6972 | ExpectedStmt ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| 6973 | auto Imp = importSeq( |
| 6974 | E->getType(), E->getLocation(), E->getConstructor(), |
| 6975 | E->getParenOrBraceRange()); |
| 6976 | if (!Imp) |
| 6977 | return Imp.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6978 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6979 | QualType ToType; |
| 6980 | SourceLocation ToLocation; |
| 6981 | CXXConstructorDecl *ToConstructor; |
| 6982 | SourceRange ToParenOrBraceRange; |
| 6983 | std::tie(ToType, ToLocation, ToConstructor, ToParenOrBraceRange) = *Imp; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6984 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6985 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6986 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 6987 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6988 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6989 | return CXXConstructExpr::Create( |
| 6990 | Importer.getToContext(), ToType, ToLocation, ToConstructor, |
| 6991 | E->isElidable(), ToArgs, E->hadMultipleCandidates(), |
| 6992 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 6993 | E->requiresZeroInitialization(), E->getConstructionKind(), |
| 6994 | ToParenOrBraceRange); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6995 | } |
| 6996 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6997 | ExpectedStmt ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *E) { |
| 6998 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6999 | if (!ToSubExprOrErr) |
| 7000 | return ToSubExprOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7001 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7002 | SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects()); |
| 7003 | if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects)) |
| 7004 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7005 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7006 | return ExprWithCleanups::Create( |
| 7007 | Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(), |
| 7008 | ToObjects); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7009 | } |
| 7010 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7011 | ExpectedStmt ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 7012 | auto Imp = importSeq( |
| 7013 | E->getCallee(), E->getType(), E->getRParenLoc()); |
| 7014 | if (!Imp) |
| 7015 | return Imp.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7016 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7017 | Expr *ToCallee; |
| 7018 | QualType ToType; |
| 7019 | SourceLocation ToRParenLoc; |
| 7020 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7021 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7022 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7023 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7024 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7025 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7026 | return new (Importer.getToContext()) CXXMemberCallExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7027 | Importer.getToContext(), ToCallee, ToArgs, ToType, E->getValueKind(), |
| 7028 | ToRParenLoc); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7029 | } |
| 7030 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7031 | ExpectedStmt ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 7032 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7033 | if (!ToTypeOrErr) |
| 7034 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7035 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7036 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7037 | if (!ToLocationOrErr) |
| 7038 | return ToLocationOrErr.takeError(); |
| 7039 | |
| 7040 | return new (Importer.getToContext()) CXXThisExpr( |
| 7041 | *ToLocationOrErr, *ToTypeOrErr, E->isImplicit()); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7042 | } |
| 7043 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7044 | ExpectedStmt ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 7045 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7046 | if (!ToTypeOrErr) |
| 7047 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7048 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7049 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7050 | if (!ToLocationOrErr) |
| 7051 | return ToLocationOrErr.takeError(); |
| 7052 | |
| 7053 | return new (Importer.getToContext()) CXXBoolLiteralExpr( |
| 7054 | E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7055 | } |
| 7056 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7057 | ExpectedStmt ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| 7058 | auto Imp1 = importSeq( |
| 7059 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7060 | E->getTemplateKeywordLoc(), E->getMemberDecl(), E->getType()); |
| 7061 | if (!Imp1) |
| 7062 | return Imp1.takeError(); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7063 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7064 | Expr *ToBase; |
| 7065 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7066 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7067 | ValueDecl *ToMemberDecl; |
| 7068 | QualType ToType; |
| 7069 | std::tie( |
| 7070 | ToBase, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, |
| 7071 | ToType) = *Imp1; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7072 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7073 | auto Imp2 = importSeq( |
| 7074 | E->getFoundDecl().getDecl(), E->getMemberNameInfo().getName(), |
| 7075 | E->getMemberNameInfo().getLoc(), E->getLAngleLoc(), E->getRAngleLoc()); |
| 7076 | if (!Imp2) |
| 7077 | return Imp2.takeError(); |
| 7078 | NamedDecl *ToDecl; |
| 7079 | DeclarationName ToName; |
| 7080 | SourceLocation ToLoc, ToLAngleLoc, ToRAngleLoc; |
| 7081 | std::tie(ToDecl, ToName, ToLoc, ToLAngleLoc, ToRAngleLoc) = *Imp2; |
Peter Szecsi | ef97252 | 2018-05-02 11:52:54 +0000 | [diff] [blame] | 7082 | |
| 7083 | DeclAccessPair ToFoundDecl = |
| 7084 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7085 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7086 | DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7087 | |
| 7088 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7089 | // FIXME: handle template arguments |
| 7090 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7091 | } |
| 7092 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7093 | return MemberExpr::Create( |
| 7094 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, |
| 7095 | ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, ToFoundDecl, |
| 7096 | ToMemberNameInfo, nullptr, ToType, E->getValueKind(), E->getObjectKind()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7097 | } |
| 7098 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7099 | ExpectedStmt |
| 7100 | ASTNodeImporter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { |
| 7101 | auto Imp = importSeq( |
| 7102 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7103 | E->getScopeTypeInfo(), E->getColonColonLoc(), E->getTildeLoc()); |
| 7104 | if (!Imp) |
| 7105 | return Imp.takeError(); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7106 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7107 | Expr *ToBase; |
| 7108 | SourceLocation ToOperatorLoc, ToColonColonLoc, ToTildeLoc; |
| 7109 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7110 | TypeSourceInfo *ToScopeTypeInfo; |
| 7111 | std::tie( |
| 7112 | ToBase, ToOperatorLoc, ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, |
| 7113 | ToTildeLoc) = *Imp; |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7114 | |
| 7115 | PseudoDestructorTypeStorage Storage; |
| 7116 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { |
| 7117 | IdentifierInfo *ToII = Importer.Import(FromII); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7118 | ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc()); |
| 7119 | if (!ToDestroyedTypeLocOrErr) |
| 7120 | return ToDestroyedTypeLocOrErr.takeError(); |
| 7121 | Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7122 | } else { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7123 | if (auto ToTIOrErr = import(E->getDestroyedTypeInfo())) |
| 7124 | Storage = PseudoDestructorTypeStorage(*ToTIOrErr); |
| 7125 | else |
| 7126 | return ToTIOrErr.takeError(); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7127 | } |
| 7128 | |
| 7129 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7130 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, |
| 7131 | ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7132 | } |
| 7133 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7134 | ExpectedStmt ASTNodeImporter::VisitCXXDependentScopeMemberExpr( |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7135 | CXXDependentScopeMemberExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7136 | auto Imp = importSeq( |
| 7137 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7138 | E->getTemplateKeywordLoc(), E->getFirstQualifierFoundInScope()); |
| 7139 | if (!Imp) |
| 7140 | return Imp.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7141 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7142 | QualType ToType; |
| 7143 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7144 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7145 | NamedDecl *ToFirstQualifierFoundInScope; |
| 7146 | std::tie( |
| 7147 | ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7148 | ToFirstQualifierFoundInScope) = *Imp; |
| 7149 | |
| 7150 | Expr *ToBase = nullptr; |
| 7151 | if (!E->isImplicitAccess()) { |
| 7152 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7153 | ToBase = *ToBaseOrErr; |
| 7154 | else |
| 7155 | return ToBaseOrErr.takeError(); |
| 7156 | } |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7157 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7158 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7159 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7160 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7161 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7162 | ToTAInfo)) |
| 7163 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7164 | ResInfo = &ToTAInfo; |
| 7165 | } |
| 7166 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7167 | auto ToMemberNameInfoOrErr = importSeq(E->getMember(), E->getMemberLoc()); |
| 7168 | if (!ToMemberNameInfoOrErr) |
| 7169 | return ToMemberNameInfoOrErr.takeError(); |
| 7170 | DeclarationNameInfo ToMemberNameInfo( |
| 7171 | std::get<0>(*ToMemberNameInfoOrErr), std::get<1>(*ToMemberNameInfoOrErr)); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7172 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7173 | if (Error Err = ImportDeclarationNameLoc( |
| 7174 | E->getMemberNameInfo(), ToMemberNameInfo)) |
| 7175 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7176 | |
| 7177 | return CXXDependentScopeMemberExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7178 | Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc, |
| 7179 | ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope, |
| 7180 | ToMemberNameInfo, ResInfo); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7181 | } |
| 7182 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7183 | ExpectedStmt |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7184 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7185 | auto Imp = importSeq( |
| 7186 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDeclName(), |
| 7187 | E->getExprLoc(), E->getLAngleLoc(), E->getRAngleLoc()); |
| 7188 | if (!Imp) |
| 7189 | return Imp.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7190 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7191 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7192 | SourceLocation ToTemplateKeywordLoc, ToExprLoc, ToLAngleLoc, ToRAngleLoc; |
| 7193 | DeclarationName ToDeclName; |
| 7194 | std::tie( |
| 7195 | ToQualifierLoc, ToTemplateKeywordLoc, ToDeclName, ToExprLoc, |
| 7196 | ToLAngleLoc, ToRAngleLoc) = *Imp; |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7197 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7198 | DeclarationNameInfo ToNameInfo(ToDeclName, ToExprLoc); |
| 7199 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7200 | return std::move(Err); |
| 7201 | |
| 7202 | TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7203 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7204 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7205 | if (Error Err = |
| 7206 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 7207 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7208 | ResInfo = &ToTAInfo; |
| 7209 | } |
| 7210 | |
| 7211 | return DependentScopeDeclRefExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7212 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, |
| 7213 | ToNameInfo, ResInfo); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7214 | } |
| 7215 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7216 | ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr( |
| 7217 | CXXUnresolvedConstructExpr *E) { |
| 7218 | auto Imp = importSeq( |
| 7219 | E->getLParenLoc(), E->getRParenLoc(), E->getTypeSourceInfo()); |
| 7220 | if (!Imp) |
| 7221 | return Imp.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7222 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7223 | SourceLocation ToLParenLoc, ToRParenLoc; |
| 7224 | TypeSourceInfo *ToTypeSourceInfo; |
| 7225 | std::tie(ToLParenLoc, ToRParenLoc, ToTypeSourceInfo) = *Imp; |
| 7226 | |
| 7227 | SmallVector<Expr *, 8> ToArgs(E->arg_size()); |
| 7228 | if (Error Err = |
| 7229 | ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin())) |
| 7230 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7231 | |
| 7232 | return CXXUnresolvedConstructExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7233 | Importer.getToContext(), ToTypeSourceInfo, ToLParenLoc, |
| 7234 | llvm::makeArrayRef(ToArgs), ToRParenLoc); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7235 | } |
| 7236 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7237 | ExpectedStmt |
| 7238 | ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { |
| 7239 | Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass()); |
| 7240 | if (!ToNamingClassOrErr) |
| 7241 | return ToNamingClassOrErr.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 | auto ToQualifierLocOrErr = import(E->getQualifierLoc()); |
| 7244 | if (!ToQualifierLocOrErr) |
| 7245 | return ToQualifierLocOrErr.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7246 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7247 | auto ToNameInfoOrErr = importSeq(E->getName(), E->getNameLoc()); |
| 7248 | if (!ToNameInfoOrErr) |
| 7249 | return ToNameInfoOrErr.takeError(); |
| 7250 | DeclarationNameInfo ToNameInfo( |
| 7251 | std::get<0>(*ToNameInfoOrErr), std::get<1>(*ToNameInfoOrErr)); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7252 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7253 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7254 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7255 | |
| 7256 | UnresolvedSet<8> ToDecls; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7257 | for (auto *D : E->decls()) |
| 7258 | if (auto ToDOrErr = import(D)) |
| 7259 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7260 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7261 | return ToDOrErr.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 | if (E->hasExplicitTemplateArgs() && E->getTemplateKeywordLoc().isValid()) { |
| 7264 | TemplateArgumentListInfo ToTAInfo; |
| 7265 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7266 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7267 | ToTAInfo)) |
| 7268 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7269 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7270 | ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc()); |
| 7271 | if (!ToTemplateKeywordLocOrErr) |
| 7272 | return ToTemplateKeywordLocOrErr.takeError(); |
| 7273 | |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7274 | return UnresolvedLookupExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7275 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7276 | *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo, |
| 7277 | ToDecls.begin(), ToDecls.end()); |
| 7278 | } |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7279 | |
| 7280 | return UnresolvedLookupExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7281 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7282 | ToNameInfo, E->requiresADL(), E->isOverloaded(), ToDecls.begin(), |
| 7283 | ToDecls.end()); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7284 | } |
| 7285 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7286 | ExpectedStmt |
| 7287 | ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { |
| 7288 | auto Imp1 = importSeq( |
| 7289 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7290 | E->getTemplateKeywordLoc()); |
| 7291 | if (!Imp1) |
| 7292 | return Imp1.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7293 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7294 | QualType ToType; |
| 7295 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7296 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7297 | std::tie(ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc) = *Imp1; |
| 7298 | |
| 7299 | auto Imp2 = importSeq(E->getName(), E->getNameLoc()); |
| 7300 | if (!Imp2) |
| 7301 | return Imp2.takeError(); |
| 7302 | DeclarationNameInfo ToNameInfo(std::get<0>(*Imp2), std::get<1>(*Imp2)); |
| 7303 | // Import additional name location/type info. |
| 7304 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7305 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7306 | |
| 7307 | UnresolvedSet<8> ToDecls; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7308 | for (Decl *D : E->decls()) |
| 7309 | if (auto ToDOrErr = import(D)) |
| 7310 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7311 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7312 | return ToDOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7313 | |
| 7314 | TemplateArgumentListInfo ToTAInfo; |
| 7315 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7316 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7317 | if (Error Err = |
| 7318 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 7319 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7320 | ResInfo = &ToTAInfo; |
| 7321 | } |
| 7322 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7323 | Expr *ToBase = nullptr; |
| 7324 | if (!E->isImplicitAccess()) { |
| 7325 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7326 | ToBase = *ToBaseOrErr; |
| 7327 | else |
| 7328 | return ToBaseOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7329 | } |
| 7330 | |
| 7331 | return UnresolvedMemberExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7332 | Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType, |
| 7333 | E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7334 | ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end()); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7335 | } |
| 7336 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7337 | ExpectedStmt ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| 7338 | auto Imp = importSeq(E->getCallee(), E->getType(), E->getRParenLoc()); |
| 7339 | if (!Imp) |
| 7340 | return Imp.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7341 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7342 | Expr *ToCallee; |
| 7343 | QualType ToType; |
| 7344 | SourceLocation ToRParenLoc; |
| 7345 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7346 | |
| 7347 | unsigned NumArgs = E->getNumArgs(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7348 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); |
| 7349 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7350 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7351 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7352 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { |
| 7353 | return new (Importer.getToContext()) CXXOperatorCallExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7354 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType, |
| 7355 | OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures()); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7356 | } |
| 7357 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7358 | return new (Importer.getToContext()) CallExpr( |
| 7359 | Importer.getToContext(), ToCallee, ToArgs, ToType, E->getValueKind(), |
| 7360 | ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7361 | } |
| 7362 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7363 | ExpectedStmt ASTNodeImporter::VisitLambdaExpr(LambdaExpr *E) { |
| 7364 | CXXRecordDecl *FromClass = E->getLambdaClass(); |
| 7365 | auto ToClassOrErr = import(FromClass); |
| 7366 | if (!ToClassOrErr) |
| 7367 | return ToClassOrErr.takeError(); |
| 7368 | CXXRecordDecl *ToClass = *ToClassOrErr; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7369 | |
| 7370 | // NOTE: lambda classes are created with BeingDefined flag set up. |
| 7371 | // It means that ImportDefinition doesn't work for them and we should fill it |
| 7372 | // manually. |
| 7373 | if (ToClass->isBeingDefined()) { |
| 7374 | for (auto FromField : FromClass->fields()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7375 | auto ToFieldOrErr = import(FromField); |
| 7376 | if (!ToFieldOrErr) |
| 7377 | return ToFieldOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7378 | } |
| 7379 | } |
| 7380 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7381 | auto ToCallOpOrErr = import(E->getCallOperator()); |
| 7382 | if (!ToCallOpOrErr) |
| 7383 | return ToCallOpOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7384 | |
| 7385 | ToClass->completeDefinition(); |
| 7386 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7387 | SmallVector<LambdaCapture, 8> ToCaptures; |
| 7388 | ToCaptures.reserve(E->capture_size()); |
| 7389 | for (const auto &FromCapture : E->captures()) { |
| 7390 | if (auto ToCaptureOrErr = import(FromCapture)) |
| 7391 | ToCaptures.push_back(*ToCaptureOrErr); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7392 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7393 | return ToCaptureOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7394 | } |
| 7395 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7396 | SmallVector<Expr *, 8> ToCaptureInits(E->capture_size()); |
| 7397 | if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits)) |
| 7398 | return std::move(Err); |
| 7399 | |
| 7400 | auto Imp = importSeq( |
| 7401 | E->getIntroducerRange(), E->getCaptureDefaultLoc(), E->getEndLoc()); |
| 7402 | if (!Imp) |
| 7403 | return Imp.takeError(); |
| 7404 | |
| 7405 | SourceRange ToIntroducerRange; |
| 7406 | SourceLocation ToCaptureDefaultLoc, ToEndLoc; |
| 7407 | std::tie(ToIntroducerRange, ToCaptureDefaultLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7408 | |
Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 7409 | return LambdaExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7410 | Importer.getToContext(), ToClass, ToIntroducerRange, |
| 7411 | E->getCaptureDefault(), ToCaptureDefaultLoc, ToCaptures, |
| 7412 | E->hasExplicitParameters(), E->hasExplicitResultType(), ToCaptureInits, |
| 7413 | ToEndLoc, E->containsUnexpandedParameterPack()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7414 | } |
| 7415 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7416 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7417 | ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) { |
| 7418 | auto Imp = importSeq(E->getLBraceLoc(), E->getRBraceLoc(), E->getType()); |
| 7419 | if (!Imp) |
| 7420 | return Imp.takeError(); |
| 7421 | |
| 7422 | SourceLocation ToLBraceLoc, ToRBraceLoc; |
| 7423 | QualType ToType; |
| 7424 | std::tie(ToLBraceLoc, ToRBraceLoc, ToType) = *Imp; |
| 7425 | |
| 7426 | SmallVector<Expr *, 4> ToExprs(E->getNumInits()); |
| 7427 | if (Error Err = ImportContainerChecked(E->inits(), ToExprs)) |
| 7428 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7429 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7430 | ASTContext &ToCtx = Importer.getToContext(); |
| 7431 | InitListExpr *To = new (ToCtx) InitListExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7432 | ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc); |
| 7433 | To->setType(ToType); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7434 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7435 | if (E->hasArrayFiller()) { |
| 7436 | if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller())) |
| 7437 | To->setArrayFiller(*ToFillerOrErr); |
| 7438 | else |
| 7439 | return ToFillerOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7440 | } |
| 7441 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7442 | if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) { |
| 7443 | if (auto ToFDOrErr = import(FromFD)) |
| 7444 | To->setInitializedFieldInUnion(*ToFDOrErr); |
| 7445 | else |
| 7446 | return ToFDOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7447 | } |
| 7448 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7449 | if (InitListExpr *SyntForm = E->getSyntacticForm()) { |
| 7450 | if (auto ToSyntFormOrErr = import(SyntForm)) |
| 7451 | To->setSyntacticForm(*ToSyntFormOrErr); |
| 7452 | else |
| 7453 | return ToSyntFormOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7454 | } |
| 7455 | |
Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7456 | // Copy InitListExprBitfields, which are not handled in the ctor of |
| 7457 | // InitListExpr. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7458 | To->sawArrayRangeDesignator(E->hadArrayRangeDesignator()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7459 | |
| 7460 | return To; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7461 | } |
| 7462 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7463 | ExpectedStmt ASTNodeImporter::VisitCXXStdInitializerListExpr( |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7464 | CXXStdInitializerListExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7465 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7466 | if (!ToTypeOrErr) |
| 7467 | return ToTypeOrErr.takeError(); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7468 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7469 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7470 | if (!ToSubExprOrErr) |
| 7471 | return ToSubExprOrErr.takeError(); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7472 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7473 | return new (Importer.getToContext()) CXXStdInitializerListExpr( |
| 7474 | *ToTypeOrErr, *ToSubExprOrErr); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7475 | } |
| 7476 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7477 | ExpectedStmt ASTNodeImporter::VisitCXXInheritedCtorInitExpr( |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7478 | CXXInheritedCtorInitExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7479 | auto Imp = importSeq(E->getLocation(), E->getType(), E->getConstructor()); |
| 7480 | if (!Imp) |
| 7481 | return Imp.takeError(); |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7482 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7483 | SourceLocation ToLocation; |
| 7484 | QualType ToType; |
| 7485 | CXXConstructorDecl *ToConstructor; |
| 7486 | std::tie(ToLocation, ToType, ToConstructor) = *Imp; |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7487 | |
| 7488 | return new (Importer.getToContext()) CXXInheritedCtorInitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7489 | ToLocation, ToType, ToConstructor, E->constructsVBase(), |
| 7490 | E->inheritedFromVBase()); |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7491 | } |
| 7492 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7493 | ExpectedStmt ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 7494 | auto Imp = importSeq(E->getType(), E->getCommonExpr(), E->getSubExpr()); |
| 7495 | if (!Imp) |
| 7496 | return Imp.takeError(); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7497 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7498 | QualType ToType; |
| 7499 | Expr *ToCommonExpr, *ToSubExpr; |
| 7500 | std::tie(ToType, ToCommonExpr, ToSubExpr) = *Imp; |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7501 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7502 | return new (Importer.getToContext()) ArrayInitLoopExpr( |
| 7503 | ToType, ToCommonExpr, ToSubExpr); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7504 | } |
| 7505 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7506 | ExpectedStmt ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 7507 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7508 | if (!ToTypeOrErr) |
| 7509 | return ToTypeOrErr.takeError(); |
| 7510 | return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7511 | } |
| 7512 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7513 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 7514 | ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc()); |
| 7515 | if (!ToBeginLocOrErr) |
| 7516 | return ToBeginLocOrErr.takeError(); |
| 7517 | |
| 7518 | auto ToFieldOrErr = import(E->getField()); |
| 7519 | if (!ToFieldOrErr) |
| 7520 | return ToFieldOrErr.takeError(); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7521 | |
| 7522 | return CXXDefaultInitExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7523 | Importer.getToContext(), *ToBeginLocOrErr, *ToFieldOrErr); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7524 | } |
| 7525 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7526 | ExpectedStmt ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 7527 | auto Imp = importSeq( |
| 7528 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten(), |
| 7529 | E->getOperatorLoc(), E->getRParenLoc(), E->getAngleBrackets()); |
| 7530 | if (!Imp) |
| 7531 | return Imp.takeError(); |
| 7532 | |
| 7533 | QualType ToType; |
| 7534 | Expr *ToSubExpr; |
| 7535 | TypeSourceInfo *ToTypeInfoAsWritten; |
| 7536 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 7537 | SourceRange ToAngleBrackets; |
| 7538 | std::tie( |
| 7539 | ToType, ToSubExpr, ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, |
| 7540 | ToAngleBrackets) = *Imp; |
| 7541 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7542 | ExprValueKind VK = E->getValueKind(); |
| 7543 | CastKind CK = E->getCastKind(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7544 | auto ToBasePathOrErr = ImportCastPath(E); |
| 7545 | if (!ToBasePathOrErr) |
| 7546 | return ToBasePathOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7547 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7548 | if (isa<CXXStaticCastExpr>(E)) { |
| 7549 | return CXXStaticCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7550 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7551 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7552 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 7553 | return CXXDynamicCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7554 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7555 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7556 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 7557 | return CXXReinterpretCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7558 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7559 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Raphael Isemann | c705bb8 | 2018-08-20 16:20:01 +0000 | [diff] [blame] | 7560 | } else if (isa<CXXConstCastExpr>(E)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7561 | return CXXConstCastExpr::Create( |
| 7562 | Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten, |
| 7563 | ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7564 | } else { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7565 | llvm_unreachable("Unknown cast type"); |
| 7566 | return make_error<ImportError>(); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7567 | } |
| 7568 | } |
| 7569 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7570 | ExpectedStmt ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7571 | SubstNonTypeTemplateParmExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7572 | auto Imp = importSeq( |
| 7573 | E->getType(), E->getExprLoc(), E->getParameter(), E->getReplacement()); |
| 7574 | if (!Imp) |
| 7575 | return Imp.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7576 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7577 | QualType ToType; |
| 7578 | SourceLocation ToExprLoc; |
| 7579 | NonTypeTemplateParmDecl *ToParameter; |
| 7580 | Expr *ToReplacement; |
| 7581 | std::tie(ToType, ToExprLoc, ToParameter, ToReplacement) = *Imp; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7582 | |
| 7583 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7584 | ToType, E->getValueKind(), ToExprLoc, ToParameter, ToReplacement); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7585 | } |
| 7586 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7587 | ExpectedStmt ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { |
| 7588 | auto Imp = importSeq( |
| 7589 | E->getType(), E->getBeginLoc(), E->getEndLoc()); |
| 7590 | if (!Imp) |
| 7591 | return Imp.takeError(); |
| 7592 | |
| 7593 | QualType ToType; |
| 7594 | SourceLocation ToBeginLoc, ToEndLoc; |
| 7595 | std::tie(ToType, ToBeginLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7596 | |
| 7597 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7598 | if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs)) |
| 7599 | return std::move(Err); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7600 | |
| 7601 | // According to Sema::BuildTypeTrait(), if E is value-dependent, |
| 7602 | // Value is always false. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7603 | bool ToValue = (E->isValueDependent() ? false : E->getValue()); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7604 | |
| 7605 | return TypeTraitExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7606 | Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs, |
| 7607 | ToEndLoc, ToValue); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7608 | } |
| 7609 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7610 | ExpectedStmt ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { |
| 7611 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7612 | if (!ToTypeOrErr) |
| 7613 | return ToTypeOrErr.takeError(); |
| 7614 | |
| 7615 | auto ToSourceRangeOrErr = import(E->getSourceRange()); |
| 7616 | if (!ToSourceRangeOrErr) |
| 7617 | return ToSourceRangeOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7618 | |
| 7619 | if (E->isTypeOperand()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7620 | if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo())) |
| 7621 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7622 | *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr); |
| 7623 | else |
| 7624 | return ToTSIOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7625 | } |
| 7626 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7627 | ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand()); |
| 7628 | if (!ToExprOperandOrErr) |
| 7629 | return ToExprOperandOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7630 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7631 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7632 | *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7633 | } |
| 7634 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7635 | void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod, |
| 7636 | CXXMethodDecl *FromMethod) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7637 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) { |
| 7638 | if (auto ImportedOrErr = import(FromOverriddenMethod)) |
| 7639 | ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>( |
| 7640 | (*ImportedOrErr)->getCanonicalDecl())); |
| 7641 | else |
| 7642 | consumeError(ImportedOrErr.takeError()); |
| 7643 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7644 | } |
| 7645 | |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7646 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7647 | ASTContext &FromContext, FileManager &FromFileManager, |
| 7648 | bool MinimalImport) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7649 | : ToContext(ToContext), FromContext(FromContext), |
| 7650 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
| 7651 | Minimal(MinimalImport) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7652 | ImportedDecls[FromContext.getTranslationUnitDecl()] |
| 7653 | = ToContext.getTranslationUnitDecl(); |
| 7654 | } |
| 7655 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7656 | ASTImporter::~ASTImporter() = default; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7657 | |
| 7658 | QualType ASTImporter::Import(QualType FromT) { |
| 7659 | if (FromT.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7660 | return {}; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7661 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7662 | const Type *FromTy = FromT.getTypePtr(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7663 | |
| 7664 | // Check whether we've already imported this type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7665 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7666 | = ImportedTypes.find(FromTy); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7667 | if (Pos != ImportedTypes.end()) |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7668 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7669 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7670 | // Import the type |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7671 | ASTNodeImporter Importer(*this); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7672 | ExpectedType ToTOrErr = Importer.Visit(FromTy); |
| 7673 | if (!ToTOrErr) { |
| 7674 | llvm::consumeError(ToTOrErr.takeError()); |
| 7675 | return {}; |
| 7676 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7677 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7678 | // Record the imported type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7679 | ImportedTypes[FromTy] = (*ToTOrErr).getTypePtr(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7680 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7681 | return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7682 | } |
| 7683 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7684 | TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) { |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7685 | if (!FromTSI) |
| 7686 | return FromTSI; |
| 7687 | |
| 7688 | // FIXME: For now we just create a "trivial" type source info based |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 7689 | // 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] | 7690 | QualType T = Import(FromTSI->getType()); |
| 7691 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7692 | return nullptr; |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7693 | |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7694 | return ToContext.getTrivialTypeSourceInfo( |
| 7695 | T, Import(FromTSI->getTypeLoc().getBeginLoc())); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7696 | } |
| 7697 | |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 7698 | Attr *ASTImporter::Import(const Attr *FromAttr) { |
| 7699 | Attr *ToAttr = FromAttr->clone(ToContext); |
| 7700 | ToAttr->setRange(Import(FromAttr->getRange())); |
| 7701 | return ToAttr; |
| 7702 | } |
| 7703 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7704 | Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) { |
| 7705 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD); |
| 7706 | if (Pos != ImportedDecls.end()) { |
| 7707 | Decl *ToD = Pos->second; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7708 | // FIXME: move this call to ImportDeclParts(). |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7709 | if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(FromD, ToD)) |
| 7710 | llvm::consumeError(std::move(Err)); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7711 | return ToD; |
| 7712 | } else { |
| 7713 | return nullptr; |
| 7714 | } |
| 7715 | } |
| 7716 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7717 | Decl *ASTImporter::Import(Decl *FromD) { |
| 7718 | if (!FromD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7719 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7720 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7721 | ASTNodeImporter Importer(*this); |
| 7722 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7723 | // Check whether we've already imported this declaration. |
| 7724 | Decl *ToD = GetAlreadyImportedOrNull(FromD); |
| 7725 | if (ToD) { |
| 7726 | // If FromD has some updated flags after last import, apply it |
| 7727 | updateFlags(FromD, ToD); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7728 | return ToD; |
| 7729 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7730 | |
| 7731 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7732 | ExpectedDecl ToDOrErr = Importer.Visit(FromD); |
| 7733 | if (!ToDOrErr) { |
| 7734 | llvm::consumeError(ToDOrErr.takeError()); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7735 | return nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7736 | } |
| 7737 | ToD = *ToDOrErr; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7738 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7739 | // Notify subclasses. |
| 7740 | Imported(FromD, ToD); |
| 7741 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 7742 | updateFlags(FromD, ToD); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7743 | return ToD; |
| 7744 | } |
| 7745 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7746 | Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7747 | if (!FromDC) |
| 7748 | return FromDC; |
| 7749 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7750 | auto *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC))); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7751 | if (!ToDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7752 | return nullptr; |
| 7753 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7754 | // 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] | 7755 | // need it to have a definition. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7756 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
| 7757 | auto *FromRecord = cast<RecordDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7758 | if (ToRecord->isCompleteDefinition()) { |
| 7759 | // Do nothing. |
| 7760 | } else if (FromRecord->isCompleteDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7761 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7762 | FromRecord, ToRecord, ASTNodeImporter::IDK_Basic)) |
| 7763 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7764 | } else { |
| 7765 | CompleteDecl(ToRecord); |
| 7766 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7767 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 7768 | auto *FromEnum = cast<EnumDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7769 | if (ToEnum->isCompleteDefinition()) { |
| 7770 | // Do nothing. |
| 7771 | } else if (FromEnum->isCompleteDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7772 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7773 | FromEnum, ToEnum, ASTNodeImporter::IDK_Basic)) |
| 7774 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7775 | } else { |
| 7776 | CompleteDecl(ToEnum); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7777 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7778 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 7779 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7780 | if (ToClass->getDefinition()) { |
| 7781 | // Do nothing. |
| 7782 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7783 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7784 | FromDef, ToClass, ASTNodeImporter::IDK_Basic)) |
| 7785 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7786 | } else { |
| 7787 | CompleteDecl(ToClass); |
| 7788 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7789 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 7790 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7791 | if (ToProto->getDefinition()) { |
| 7792 | // Do nothing. |
| 7793 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7794 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7795 | FromDef, ToProto, ASTNodeImporter::IDK_Basic)) |
| 7796 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7797 | } else { |
| 7798 | CompleteDecl(ToProto); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7799 | } |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7800 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7801 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7802 | return ToDC; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7803 | } |
| 7804 | |
| 7805 | Expr *ASTImporter::Import(Expr *FromE) { |
| 7806 | if (!FromE) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7807 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7808 | |
| 7809 | return cast_or_null<Expr>(Import(cast<Stmt>(FromE))); |
| 7810 | } |
| 7811 | |
| 7812 | Stmt *ASTImporter::Import(Stmt *FromS) { |
| 7813 | if (!FromS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7814 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7815 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7816 | // Check whether we've already imported this declaration. |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7817 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 7818 | if (Pos != ImportedStmts.end()) |
| 7819 | return Pos->second; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7820 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7821 | // Import the statement. |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7822 | ASTNodeImporter Importer(*this); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7823 | ExpectedStmt ToSOrErr = Importer.Visit(FromS); |
| 7824 | if (!ToSOrErr) { |
| 7825 | llvm::consumeError(ToSOrErr.takeError()); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7826 | return nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7827 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7828 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7829 | if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) { |
Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7830 | auto *FromE = cast<Expr>(FromS); |
| 7831 | // Copy ExprBitfields, which may not be handled in Expr subclasses |
| 7832 | // constructors. |
| 7833 | ToE->setValueKind(FromE->getValueKind()); |
| 7834 | ToE->setObjectKind(FromE->getObjectKind()); |
| 7835 | ToE->setTypeDependent(FromE->isTypeDependent()); |
| 7836 | ToE->setValueDependent(FromE->isValueDependent()); |
| 7837 | ToE->setInstantiationDependent(FromE->isInstantiationDependent()); |
| 7838 | ToE->setContainsUnexpandedParameterPack( |
| 7839 | FromE->containsUnexpandedParameterPack()); |
| 7840 | } |
| 7841 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7842 | // Record the imported declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7843 | ImportedStmts[FromS] = *ToSOrErr; |
| 7844 | return *ToSOrErr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7845 | } |
| 7846 | |
| 7847 | NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) { |
| 7848 | if (!FromNNS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7849 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7850 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7851 | NestedNameSpecifier *prefix = Import(FromNNS->getPrefix()); |
| 7852 | |
| 7853 | switch (FromNNS->getKind()) { |
| 7854 | case NestedNameSpecifier::Identifier: |
| 7855 | if (IdentifierInfo *II = Import(FromNNS->getAsIdentifier())) { |
| 7856 | return NestedNameSpecifier::Create(ToContext, prefix, II); |
| 7857 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7858 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7859 | |
| 7860 | case NestedNameSpecifier::Namespace: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7861 | if (auto *NS = |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7862 | cast_or_null<NamespaceDecl>(Import(FromNNS->getAsNamespace()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7863 | return NestedNameSpecifier::Create(ToContext, prefix, NS); |
| 7864 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7865 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7866 | |
| 7867 | case NestedNameSpecifier::NamespaceAlias: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7868 | if (auto *NSAD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7869 | cast_or_null<NamespaceAliasDecl>(Import(FromNNS->getAsNamespaceAlias()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7870 | return NestedNameSpecifier::Create(ToContext, prefix, NSAD); |
| 7871 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7872 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7873 | |
| 7874 | case NestedNameSpecifier::Global: |
| 7875 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 7876 | |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7877 | case NestedNameSpecifier::Super: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7878 | if (auto *RD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7879 | cast_or_null<CXXRecordDecl>(Import(FromNNS->getAsRecordDecl()))) { |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7880 | return NestedNameSpecifier::SuperSpecifier(ToContext, RD); |
| 7881 | } |
| 7882 | return nullptr; |
| 7883 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7884 | case NestedNameSpecifier::TypeSpec: |
| 7885 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 7886 | QualType T = Import(QualType(FromNNS->getAsType(), 0u)); |
| 7887 | if (!T.isNull()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7888 | bool bTemplate = FromNNS->getKind() == |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7889 | NestedNameSpecifier::TypeSpecWithTemplate; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7890 | return NestedNameSpecifier::Create(ToContext, prefix, |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7891 | bTemplate, T.getTypePtr()); |
| 7892 | } |
| 7893 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7894 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7895 | } |
| 7896 | |
| 7897 | llvm_unreachable("Invalid nested name specifier kind"); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7898 | } |
| 7899 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 7900 | NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7901 | // Copied from NestedNameSpecifier mostly. |
| 7902 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 7903 | NestedNameSpecifierLoc NNS = FromNNS; |
| 7904 | |
| 7905 | // Push each of the nested-name-specifiers's onto a stack for |
| 7906 | // serialization in reverse order. |
| 7907 | while (NNS) { |
| 7908 | NestedNames.push_back(NNS); |
| 7909 | NNS = NNS.getPrefix(); |
| 7910 | } |
| 7911 | |
| 7912 | NestedNameSpecifierLocBuilder Builder; |
| 7913 | |
| 7914 | while (!NestedNames.empty()) { |
| 7915 | NNS = NestedNames.pop_back_val(); |
| 7916 | NestedNameSpecifier *Spec = Import(NNS.getNestedNameSpecifier()); |
| 7917 | if (!Spec) |
| 7918 | return NestedNameSpecifierLoc(); |
| 7919 | |
| 7920 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
| 7921 | switch (Kind) { |
| 7922 | case NestedNameSpecifier::Identifier: |
| 7923 | Builder.Extend(getToContext(), |
| 7924 | Spec->getAsIdentifier(), |
| 7925 | Import(NNS.getLocalBeginLoc()), |
| 7926 | Import(NNS.getLocalEndLoc())); |
| 7927 | break; |
| 7928 | |
| 7929 | case NestedNameSpecifier::Namespace: |
| 7930 | Builder.Extend(getToContext(), |
| 7931 | Spec->getAsNamespace(), |
| 7932 | Import(NNS.getLocalBeginLoc()), |
| 7933 | Import(NNS.getLocalEndLoc())); |
| 7934 | break; |
| 7935 | |
| 7936 | case NestedNameSpecifier::NamespaceAlias: |
| 7937 | Builder.Extend(getToContext(), |
| 7938 | Spec->getAsNamespaceAlias(), |
| 7939 | Import(NNS.getLocalBeginLoc()), |
| 7940 | Import(NNS.getLocalEndLoc())); |
| 7941 | break; |
| 7942 | |
| 7943 | case NestedNameSpecifier::TypeSpec: |
| 7944 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 7945 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
| 7946 | QualType(Spec->getAsType(), 0)); |
| 7947 | Builder.Extend(getToContext(), |
| 7948 | Import(NNS.getLocalBeginLoc()), |
| 7949 | TSI->getTypeLoc(), |
| 7950 | Import(NNS.getLocalEndLoc())); |
| 7951 | break; |
| 7952 | } |
| 7953 | |
| 7954 | case NestedNameSpecifier::Global: |
| 7955 | Builder.MakeGlobal(getToContext(), Import(NNS.getLocalBeginLoc())); |
| 7956 | break; |
| 7957 | |
| 7958 | case NestedNameSpecifier::Super: { |
| 7959 | SourceRange ToRange = Import(NNS.getSourceRange()); |
| 7960 | Builder.MakeSuper(getToContext(), |
| 7961 | Spec->getAsRecordDecl(), |
| 7962 | ToRange.getBegin(), |
| 7963 | ToRange.getEnd()); |
| 7964 | } |
| 7965 | } |
| 7966 | } |
| 7967 | |
| 7968 | return Builder.getWithLocInContext(getToContext()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 7969 | } |
| 7970 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7971 | TemplateName ASTImporter::Import(TemplateName From) { |
| 7972 | switch (From.getKind()) { |
| 7973 | case TemplateName::Template: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7974 | if (auto *ToTemplate = |
| 7975 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7976 | return TemplateName(ToTemplate); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7977 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7978 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7979 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7980 | case TemplateName::OverloadedTemplate: { |
| 7981 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 7982 | UnresolvedSet<2> ToTemplates; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7983 | for (auto *I : *FromStorage) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7984 | if (auto *To = cast_or_null<NamedDecl>(Import(I))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7985 | ToTemplates.addDecl(To); |
| 7986 | else |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7987 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7988 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7989 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7990 | ToTemplates.end()); |
| 7991 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7992 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7993 | case TemplateName::QualifiedTemplate: { |
| 7994 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
| 7995 | NestedNameSpecifier *Qualifier = Import(QTN->getQualifier()); |
| 7996 | if (!Qualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7997 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7998 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7999 | if (auto *ToTemplate = |
| 8000 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8001 | return ToContext.getQualifiedTemplateName(Qualifier, |
| 8002 | QTN->hasTemplateKeyword(), |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8003 | ToTemplate); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8004 | |
| 8005 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8006 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8007 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8008 | case TemplateName::DependentTemplate: { |
| 8009 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
| 8010 | NestedNameSpecifier *Qualifier = Import(DTN->getQualifier()); |
| 8011 | if (!Qualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8012 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8013 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8014 | if (DTN->isIdentifier()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8015 | return ToContext.getDependentTemplateName(Qualifier, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8016 | Import(DTN->getIdentifier())); |
| 8017 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8018 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8019 | return ToContext.getDependentTemplateName(Qualifier, DTN->getOperator()); |
| 8020 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8021 | |
| 8022 | case TemplateName::SubstTemplateTemplateParm: { |
| 8023 | SubstTemplateTemplateParmStorage *subst |
| 8024 | = From.getAsSubstTemplateTemplateParm(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8025 | auto *param = |
| 8026 | cast_or_null<TemplateTemplateParmDecl>(Import(subst->getParameter())); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8027 | if (!param) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8028 | return {}; |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8029 | |
| 8030 | TemplateName replacement = Import(subst->getReplacement()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8031 | if (replacement.isNull()) |
| 8032 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8033 | |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8034 | return ToContext.getSubstTemplateTemplateParm(param, replacement); |
| 8035 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8036 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8037 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 8038 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 8039 | = From.getAsSubstTemplateTemplateParmPack(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8040 | auto *Param = |
| 8041 | cast_or_null<TemplateTemplateParmDecl>( |
| 8042 | Import(SubstPack->getParameterPack())); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8043 | if (!Param) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8044 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8045 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8046 | ASTNodeImporter Importer(*this); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8047 | Expected<TemplateArgument> ArgPack |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8048 | = Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8049 | if (!ArgPack) { |
| 8050 | llvm::consumeError(ArgPack.takeError()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8051 | return {}; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8052 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8053 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8054 | return ToContext.getSubstTemplateTemplateParmPack(Param, *ArgPack); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8055 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8056 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8057 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8058 | llvm_unreachable("Invalid template name kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8059 | } |
| 8060 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8061 | SourceLocation ASTImporter::Import(SourceLocation FromLoc) { |
| 8062 | if (FromLoc.isInvalid()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8063 | return {}; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8064 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8065 | SourceManager &FromSM = FromContext.getSourceManager(); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8066 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8067 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
Sean Callanan | 238d897 | 2014-12-10 01:26:39 +0000 | [diff] [blame] | 8068 | FileID ToFileID = Import(Decomposed.first); |
| 8069 | if (ToFileID.isInvalid()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8070 | return {}; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8071 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 8072 | return ToSM.getComposedLoc(ToFileID, Decomposed.second); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8073 | } |
| 8074 | |
| 8075 | SourceRange ASTImporter::Import(SourceRange FromRange) { |
| 8076 | return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd())); |
| 8077 | } |
| 8078 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8079 | FileID ASTImporter::Import(FileID FromID) { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8080 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8081 | if (Pos != ImportedFileIDs.end()) |
| 8082 | return Pos->second; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8083 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8084 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 8085 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 8086 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8087 | |
| 8088 | // Map the FromID to the "to" source manager. |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8089 | FileID ToID; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8090 | if (FromSLoc.isExpansion()) { |
| 8091 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); |
| 8092 | SourceLocation ToSpLoc = Import(FromEx.getSpellingLoc()); |
| 8093 | SourceLocation ToExLocS = Import(FromEx.getExpansionLocStart()); |
| 8094 | unsigned TokenLen = FromSM.getFileIDSize(FromID); |
| 8095 | SourceLocation MLoc; |
| 8096 | if (FromEx.isMacroArgExpansion()) { |
| 8097 | MLoc = ToSM.createMacroArgExpansionLoc(ToSpLoc, ToExLocS, TokenLen); |
| 8098 | } else { |
| 8099 | SourceLocation ToExLocE = Import(FromEx.getExpansionLocEnd()); |
| 8100 | MLoc = ToSM.createExpansionLoc(ToSpLoc, ToExLocS, ToExLocE, TokenLen, |
| 8101 | FromEx.isExpansionTokenRange()); |
| 8102 | } |
| 8103 | ToID = ToSM.getFileID(MLoc); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8104 | } else { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8105 | // Include location of this file. |
| 8106 | SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); |
| 8107 | |
| 8108 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
| 8109 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
| 8110 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 8111 | // disk again |
| 8112 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 8113 | // than mmap the files several times. |
| 8114 | const FileEntry *Entry = |
| 8115 | ToFileManager.getFile(Cache->OrigEntry->getName()); |
| 8116 | if (!Entry) |
| 8117 | return {}; |
| 8118 | ToID = ToSM.createFileID(Entry, ToIncludeLoc, |
| 8119 | FromSLoc.getFile().getFileCharacteristic()); |
| 8120 | } else { |
| 8121 | // FIXME: We want to re-use the existing MemoryBuffer! |
| 8122 | const llvm::MemoryBuffer *FromBuf = |
| 8123 | Cache->getBuffer(FromContext.getDiagnostics(), FromSM); |
| 8124 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = |
| 8125 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
| 8126 | FromBuf->getBufferIdentifier()); |
| 8127 | ToID = ToSM.createFileID(std::move(ToBuf), |
| 8128 | FromSLoc.getFile().getFileCharacteristic()); |
| 8129 | } |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8130 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8131 | |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 8132 | ImportedFileIDs[FromID] = ToID; |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8133 | return ToID; |
| 8134 | } |
| 8135 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8136 | CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) { |
| 8137 | Expr *ToExpr = Import(From->getInit()); |
| 8138 | if (!ToExpr && From->getInit()) |
| 8139 | return nullptr; |
| 8140 | |
| 8141 | if (From->isBaseInitializer()) { |
| 8142 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 8143 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 8144 | return nullptr; |
| 8145 | |
| 8146 | return new (ToContext) CXXCtorInitializer( |
| 8147 | ToContext, ToTInfo, From->isBaseVirtual(), Import(From->getLParenLoc()), |
| 8148 | ToExpr, Import(From->getRParenLoc()), |
| 8149 | From->isPackExpansion() ? Import(From->getEllipsisLoc()) |
| 8150 | : SourceLocation()); |
| 8151 | } else if (From->isMemberInitializer()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8152 | auto *ToField = cast_or_null<FieldDecl>(Import(From->getMember())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8153 | if (!ToField && From->getMember()) |
| 8154 | return nullptr; |
| 8155 | |
| 8156 | return new (ToContext) CXXCtorInitializer( |
| 8157 | ToContext, ToField, Import(From->getMemberLocation()), |
| 8158 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 8159 | } else if (From->isIndirectMemberInitializer()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8160 | auto *ToIField = cast_or_null<IndirectFieldDecl>( |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8161 | Import(From->getIndirectMember())); |
| 8162 | if (!ToIField && From->getIndirectMember()) |
| 8163 | return nullptr; |
| 8164 | |
| 8165 | return new (ToContext) CXXCtorInitializer( |
| 8166 | ToContext, ToIField, Import(From->getMemberLocation()), |
| 8167 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 8168 | } else if (From->isDelegatingInitializer()) { |
| 8169 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 8170 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 8171 | return nullptr; |
| 8172 | |
| 8173 | return new (ToContext) |
| 8174 | CXXCtorInitializer(ToContext, ToTInfo, Import(From->getLParenLoc()), |
| 8175 | ToExpr, Import(From->getRParenLoc())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8176 | } else { |
| 8177 | return nullptr; |
| 8178 | } |
| 8179 | } |
| 8180 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8181 | CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { |
| 8182 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 8183 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 8184 | return Pos->second; |
| 8185 | |
| 8186 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
| 8187 | Import(BaseSpec->getSourceRange()), |
| 8188 | BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 8189 | BaseSpec->getAccessSpecifierAsWritten(), |
| 8190 | Import(BaseSpec->getTypeSourceInfo()), |
| 8191 | Import(BaseSpec->getEllipsisLoc())); |
| 8192 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 8193 | return Imported; |
| 8194 | } |
| 8195 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8196 | Error ASTImporter::ImportDefinition_New(Decl *From) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8197 | Decl *To = Import(From); |
| 8198 | if (!To) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8199 | return llvm::make_error<ImportError>(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8200 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8201 | if (auto *FromDC = cast<DeclContext>(From)) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8202 | ASTNodeImporter Importer(*this); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8203 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8204 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 8205 | if (!ToRecord->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8206 | return Importer.ImportDefinition( |
| 8207 | cast<RecordDecl>(FromDC), ToRecord, |
| 8208 | ASTNodeImporter::IDK_Everything); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8209 | } |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 8210 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8211 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8212 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8213 | if (!ToEnum->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8214 | return Importer.ImportDefinition( |
| 8215 | cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8216 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8217 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8218 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8219 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 8220 | if (!ToIFace->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8221 | return Importer.ImportDefinition( |
| 8222 | cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
| 8223 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 8224 | } |
| 8225 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8226 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8227 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 8228 | if (!ToProto->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8229 | return Importer.ImportDefinition( |
| 8230 | cast<ObjCProtocolDecl>(FromDC), ToProto, |
| 8231 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 8232 | } |
| 8233 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8234 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8235 | return Importer.ImportDeclContext(FromDC, true); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8236 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8237 | |
| 8238 | return Error::success(); |
| 8239 | } |
| 8240 | |
| 8241 | void ASTImporter::ImportDefinition(Decl *From) { |
| 8242 | Error Err = ImportDefinition_New(From); |
| 8243 | llvm::consumeError(std::move(Err)); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8244 | } |
| 8245 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8246 | DeclarationName ASTImporter::Import(DeclarationName FromName) { |
| 8247 | if (!FromName) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8248 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8249 | |
| 8250 | switch (FromName.getNameKind()) { |
| 8251 | case DeclarationName::Identifier: |
| 8252 | return Import(FromName.getAsIdentifierInfo()); |
| 8253 | |
| 8254 | case DeclarationName::ObjCZeroArgSelector: |
| 8255 | case DeclarationName::ObjCOneArgSelector: |
| 8256 | case DeclarationName::ObjCMultiArgSelector: |
| 8257 | return Import(FromName.getObjCSelector()); |
| 8258 | |
| 8259 | case DeclarationName::CXXConstructorName: { |
| 8260 | QualType T = Import(FromName.getCXXNameType()); |
| 8261 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8262 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8263 | |
| 8264 | return ToContext.DeclarationNames.getCXXConstructorName( |
| 8265 | ToContext.getCanonicalType(T)); |
| 8266 | } |
| 8267 | |
| 8268 | case DeclarationName::CXXDestructorName: { |
| 8269 | QualType T = Import(FromName.getCXXNameType()); |
| 8270 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8271 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8272 | |
| 8273 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 8274 | ToContext.getCanonicalType(T)); |
| 8275 | } |
| 8276 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8277 | case DeclarationName::CXXDeductionGuideName: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8278 | auto *Template = cast_or_null<TemplateDecl>( |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8279 | Import(FromName.getCXXDeductionGuideTemplate())); |
| 8280 | if (!Template) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8281 | return {}; |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8282 | return ToContext.DeclarationNames.getCXXDeductionGuideName(Template); |
| 8283 | } |
| 8284 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8285 | case DeclarationName::CXXConversionFunctionName: { |
| 8286 | QualType T = Import(FromName.getCXXNameType()); |
| 8287 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8288 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8289 | |
| 8290 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 8291 | ToContext.getCanonicalType(T)); |
| 8292 | } |
| 8293 | |
| 8294 | case DeclarationName::CXXOperatorName: |
| 8295 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 8296 | FromName.getCXXOverloadedOperator()); |
| 8297 | |
| 8298 | case DeclarationName::CXXLiteralOperatorName: |
| 8299 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
| 8300 | Import(FromName.getCXXLiteralIdentifier())); |
| 8301 | |
| 8302 | case DeclarationName::CXXUsingDirective: |
| 8303 | // FIXME: STATICS! |
| 8304 | return DeclarationName::getUsingDirectiveName(); |
| 8305 | } |
| 8306 | |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 8307 | llvm_unreachable("Invalid DeclarationName Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8308 | } |
| 8309 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8310 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8311 | if (!FromId) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8312 | return nullptr; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8313 | |
Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 8314 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 8315 | |
| 8316 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 8317 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 8318 | |
| 8319 | return ToId; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8320 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8321 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8322 | Selector ASTImporter::Import(Selector FromSel) { |
| 8323 | if (FromSel.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8324 | return {}; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8325 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 8326 | SmallVector<IdentifierInfo *, 4> Idents; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8327 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 8328 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 8329 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 8330 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 8331 | } |
| 8332 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8333 | DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, |
| 8334 | DeclContext *DC, |
| 8335 | unsigned IDNS, |
| 8336 | NamedDecl **Decls, |
| 8337 | unsigned NumDecls) { |
| 8338 | return Name; |
| 8339 | } |
| 8340 | |
| 8341 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8342 | if (LastDiagFromFrom) |
| 8343 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8344 | FromContext.getDiagnostics()); |
| 8345 | LastDiagFromFrom = false; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8346 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8347 | } |
| 8348 | |
| 8349 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8350 | if (!LastDiagFromFrom) |
| 8351 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8352 | ToContext.getDiagnostics()); |
| 8353 | LastDiagFromFrom = true; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8354 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8355 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8356 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8357 | void ASTImporter::CompleteDecl (Decl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8358 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8359 | if (!ID->getDefinition()) |
| 8360 | ID->startDefinition(); |
| 8361 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8362 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8363 | if (!PD->getDefinition()) |
| 8364 | PD->startDefinition(); |
| 8365 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8366 | else if (auto *TD = dyn_cast<TagDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8367 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 8368 | TD->startDefinition(); |
| 8369 | TD->setCompleteDefinition(true); |
| 8370 | } |
| 8371 | } |
| 8372 | else { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8373 | assert(0 && "CompleteDecl called on a Decl that can't be completed"); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8374 | } |
| 8375 | } |
| 8376 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8377 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { |
| 8378 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); |
| 8379 | assert((Pos == ImportedDecls.end() || Pos->second == To) && |
| 8380 | "Try to import an already imported Decl"); |
| 8381 | if (Pos != ImportedDecls.end()) |
| 8382 | return Pos->second; |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8383 | ImportedDecls[From] = To; |
| 8384 | return To; |
Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 8385 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8386 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8387 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 8388 | bool Complain) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 8389 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8390 | = ImportedTypes.find(From.getTypePtr()); |
| 8391 | if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To)) |
| 8392 | return true; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 8393 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8394 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8395 | getStructuralEquivalenceKind(*this), false, |
| 8396 | Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 8397 | return Ctx.IsEquivalent(From, To); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8398 | } |