Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1 | //===- ASTImporter.cpp - Importing ASTs from other Contexts ---------------===// |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file defines the ASTImporter class which imports AST nodes from one |
| 10 | // context into another context. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 13 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 14 | #include "clang/AST/ASTImporter.h" |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTImporterLookupTable.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); |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 125 | if (auto *TD = dyn_cast<TagDecl>(D)) |
| 126 | return getCanonicalForwardRedeclChain<TagDecl>(TD); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 127 | llvm_unreachable("Bad declaration kind"); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 130 | void updateFlags(const Decl *From, Decl *To) { |
| 131 | // Check if some flags or attrs are new in 'From' and copy into 'To'. |
| 132 | // FIXME: Other flags or attrs? |
| 133 | if (From->isUsed(false) && !To->isUsed(false)) |
| 134 | To->setIsUsed(); |
| 135 | } |
| 136 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 137 | // FIXME: Temporary until every import returns Expected. |
| 138 | template <> |
| 139 | LLVM_NODISCARD Error |
| 140 | ASTImporter::importInto(SourceLocation &To, const SourceLocation &From) { |
| 141 | To = Import(From); |
| 142 | if (From.isValid() && To.isInvalid()) |
| 143 | return llvm::make_error<ImportError>(); |
| 144 | return Error::success(); |
| 145 | } |
| 146 | // FIXME: Temporary until every import returns Expected. |
| 147 | template <> |
| 148 | LLVM_NODISCARD Error |
| 149 | ASTImporter::importInto(QualType &To, const QualType &From) { |
| 150 | To = Import(From); |
| 151 | if (!From.isNull() && To.isNull()) |
| 152 | return llvm::make_error<ImportError>(); |
| 153 | return Error::success(); |
| 154 | } |
| 155 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 156 | class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>, |
| 157 | public DeclVisitor<ASTNodeImporter, ExpectedDecl>, |
| 158 | public StmtVisitor<ASTNodeImporter, ExpectedStmt> { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 159 | ASTImporter &Importer; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 160 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 161 | // Use this instead of Importer.importInto . |
| 162 | template <typename ImportT> |
| 163 | LLVM_NODISCARD Error importInto(ImportT &To, const ImportT &From) { |
| 164 | return Importer.importInto(To, From); |
| 165 | } |
| 166 | |
| 167 | // Use this to import pointers of specific type. |
| 168 | template <typename ImportT> |
| 169 | LLVM_NODISCARD Error importInto(ImportT *&To, ImportT *From) { |
| 170 | auto ToI = Importer.Import(From); |
| 171 | if (!ToI && From) |
| 172 | return make_error<ImportError>(); |
| 173 | To = cast_or_null<ImportT>(ToI); |
| 174 | return Error::success(); |
| 175 | // FIXME: This should be the final code. |
| 176 | //auto ToOrErr = Importer.Import(From); |
| 177 | //if (ToOrErr) { |
| 178 | // To = cast_or_null<ImportT>(*ToOrErr); |
| 179 | //} |
| 180 | //return ToOrErr.takeError(); |
| 181 | } |
| 182 | |
| 183 | // Call the import function of ASTImporter for a baseclass of type `T` and |
| 184 | // cast the return value to `T`. |
| 185 | template <typename T> |
| 186 | Expected<T *> import(T *From) { |
| 187 | auto *To = Importer.Import(From); |
| 188 | if (!To && From) |
| 189 | return make_error<ImportError>(); |
| 190 | return cast_or_null<T>(To); |
| 191 | // FIXME: This should be the final code. |
| 192 | //auto ToOrErr = Importer.Import(From); |
| 193 | //if (!ToOrErr) |
| 194 | // return ToOrErr.takeError(); |
| 195 | //return cast_or_null<T>(*ToOrErr); |
| 196 | } |
| 197 | |
| 198 | template <typename T> |
| 199 | Expected<T *> import(const T *From) { |
| 200 | return import(const_cast<T *>(From)); |
| 201 | } |
| 202 | |
| 203 | // Call the import function of ASTImporter for type `T`. |
| 204 | template <typename T> |
| 205 | Expected<T> import(const T &From) { |
| 206 | T To = Importer.Import(From); |
| 207 | T DefaultT; |
| 208 | if (To == DefaultT && !(From == DefaultT)) |
| 209 | return make_error<ImportError>(); |
| 210 | return To; |
| 211 | // FIXME: This should be the final code. |
| 212 | //return Importer.Import(From); |
| 213 | } |
| 214 | |
| 215 | template <class T> |
| 216 | Expected<std::tuple<T>> |
| 217 | importSeq(const T &From) { |
| 218 | Expected<T> ToOrErr = import(From); |
| 219 | if (!ToOrErr) |
| 220 | return ToOrErr.takeError(); |
| 221 | return std::make_tuple<T>(std::move(*ToOrErr)); |
| 222 | } |
| 223 | |
| 224 | // Import multiple objects with a single function call. |
| 225 | // This should work for every type for which a variant of `import` exists. |
| 226 | // The arguments are processed from left to right and import is stopped on |
| 227 | // first error. |
| 228 | template <class THead, class... TTail> |
| 229 | Expected<std::tuple<THead, TTail...>> |
| 230 | importSeq(const THead &FromHead, const TTail &...FromTail) { |
| 231 | Expected<std::tuple<THead>> ToHeadOrErr = importSeq(FromHead); |
| 232 | if (!ToHeadOrErr) |
| 233 | return ToHeadOrErr.takeError(); |
| 234 | Expected<std::tuple<TTail...>> ToTailOrErr = importSeq(FromTail...); |
| 235 | if (!ToTailOrErr) |
| 236 | return ToTailOrErr.takeError(); |
| 237 | return std::tuple_cat(*ToHeadOrErr, *ToTailOrErr); |
| 238 | } |
| 239 | |
| 240 | // Wrapper for an overload set. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 241 | template <typename ToDeclT> struct CallOverloadedCreateFun { |
| 242 | template <typename... Args> |
| 243 | auto operator()(Args &&... args) |
| 244 | -> decltype(ToDeclT::Create(std::forward<Args>(args)...)) { |
| 245 | return ToDeclT::Create(std::forward<Args>(args)...); |
| 246 | } |
| 247 | }; |
| 248 | |
| 249 | // Always use these functions to create a Decl during import. There are |
| 250 | // certain tasks which must be done after the Decl was created, e.g. we |
| 251 | // must immediately register that as an imported Decl. The parameter `ToD` |
| 252 | // will be set to the newly created Decl or if had been imported before |
| 253 | // then to the already imported Decl. Returns a bool value set to true if |
| 254 | // the `FromD` had been imported before. |
| 255 | template <typename ToDeclT, typename FromDeclT, typename... Args> |
| 256 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, |
| 257 | Args &&... args) { |
| 258 | // There may be several overloads of ToDeclT::Create. We must make sure |
| 259 | // to call the one which would be chosen by the arguments, thus we use a |
| 260 | // wrapper for the overload set. |
| 261 | CallOverloadedCreateFun<ToDeclT> OC; |
| 262 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, |
| 263 | std::forward<Args>(args)...); |
| 264 | } |
| 265 | // Use this overload if a special Type is needed to be created. E.g if we |
| 266 | // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl` |
| 267 | // then: |
| 268 | // TypedefNameDecl *ToTypedef; |
| 269 | // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...); |
| 270 | template <typename NewDeclT, typename ToDeclT, typename FromDeclT, |
| 271 | typename... Args> |
| 272 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, |
| 273 | Args &&... args) { |
| 274 | CallOverloadedCreateFun<NewDeclT> OC; |
| 275 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, |
| 276 | std::forward<Args>(args)...); |
| 277 | } |
| 278 | // Use this version if a special create function must be |
| 279 | // used, e.g. CXXRecordDecl::CreateLambda . |
| 280 | template <typename ToDeclT, typename CreateFunT, typename FromDeclT, |
| 281 | typename... Args> |
| 282 | LLVM_NODISCARD bool |
| 283 | GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun, |
| 284 | FromDeclT *FromD, Args &&... args) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 285 | // FIXME: This code is needed later. |
| 286 | //if (Importer.getImportDeclErrorIfAny(FromD)) { |
| 287 | // ToD = nullptr; |
| 288 | // return true; // Already imported but with error. |
| 289 | //} |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 290 | ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD)); |
| 291 | if (ToD) |
| 292 | return true; // Already imported. |
| 293 | ToD = CreateFun(std::forward<Args>(args)...); |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 294 | // Keep track of imported Decls. |
| 295 | Importer.MapImported(FromD, ToD); |
| 296 | Importer.AddToLookupTable(ToD); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 297 | InitializeImportedDecl(FromD, ToD); |
| 298 | return false; // A new Decl is created. |
| 299 | } |
| 300 | |
| 301 | void InitializeImportedDecl(Decl *FromD, Decl *ToD) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 302 | ToD->IdentifierNamespace = FromD->IdentifierNamespace; |
| 303 | if (FromD->hasAttrs()) |
| 304 | for (const Attr *FromAttr : FromD->getAttrs()) |
| 305 | ToD->addAttr(Importer.Import(FromAttr)); |
| 306 | if (FromD->isUsed()) |
| 307 | ToD->setIsUsed(); |
| 308 | if (FromD->isImplicit()) |
| 309 | ToD->setImplicit(); |
| 310 | } |
| 311 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 312 | public: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 313 | explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {} |
Gabor Marton | 344b099 | 2018-05-16 11:48:11 +0000 | [diff] [blame] | 314 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 315 | using TypeVisitor<ASTNodeImporter, ExpectedType>::Visit; |
| 316 | using DeclVisitor<ASTNodeImporter, ExpectedDecl>::Visit; |
| 317 | using StmtVisitor<ASTNodeImporter, ExpectedStmt>::Visit; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 318 | |
| 319 | // Importing types |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 320 | ExpectedType VisitType(const Type *T); |
| 321 | ExpectedType VisitAtomicType(const AtomicType *T); |
| 322 | ExpectedType VisitBuiltinType(const BuiltinType *T); |
| 323 | ExpectedType VisitDecayedType(const DecayedType *T); |
| 324 | ExpectedType VisitComplexType(const ComplexType *T); |
| 325 | ExpectedType VisitPointerType(const PointerType *T); |
| 326 | ExpectedType VisitBlockPointerType(const BlockPointerType *T); |
| 327 | ExpectedType VisitLValueReferenceType(const LValueReferenceType *T); |
| 328 | ExpectedType VisitRValueReferenceType(const RValueReferenceType *T); |
| 329 | ExpectedType VisitMemberPointerType(const MemberPointerType *T); |
| 330 | ExpectedType VisitConstantArrayType(const ConstantArrayType *T); |
| 331 | ExpectedType VisitIncompleteArrayType(const IncompleteArrayType *T); |
| 332 | ExpectedType VisitVariableArrayType(const VariableArrayType *T); |
| 333 | ExpectedType VisitDependentSizedArrayType(const DependentSizedArrayType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 334 | // FIXME: DependentSizedExtVectorType |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 335 | ExpectedType VisitVectorType(const VectorType *T); |
| 336 | ExpectedType VisitExtVectorType(const ExtVectorType *T); |
| 337 | ExpectedType VisitFunctionNoProtoType(const FunctionNoProtoType *T); |
| 338 | ExpectedType VisitFunctionProtoType(const FunctionProtoType *T); |
| 339 | ExpectedType VisitUnresolvedUsingType(const UnresolvedUsingType *T); |
| 340 | ExpectedType VisitParenType(const ParenType *T); |
| 341 | ExpectedType VisitTypedefType(const TypedefType *T); |
| 342 | ExpectedType VisitTypeOfExprType(const TypeOfExprType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 343 | // FIXME: DependentTypeOfExprType |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 344 | ExpectedType VisitTypeOfType(const TypeOfType *T); |
| 345 | ExpectedType VisitDecltypeType(const DecltypeType *T); |
| 346 | ExpectedType VisitUnaryTransformType(const UnaryTransformType *T); |
| 347 | ExpectedType VisitAutoType(const AutoType *T); |
| 348 | ExpectedType VisitInjectedClassNameType(const InjectedClassNameType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 349 | // FIXME: DependentDecltypeType |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 350 | ExpectedType VisitRecordType(const RecordType *T); |
| 351 | ExpectedType VisitEnumType(const EnumType *T); |
| 352 | ExpectedType VisitAttributedType(const AttributedType *T); |
| 353 | ExpectedType VisitTemplateTypeParmType(const TemplateTypeParmType *T); |
| 354 | ExpectedType VisitSubstTemplateTypeParmType( |
| 355 | const SubstTemplateTypeParmType *T); |
| 356 | ExpectedType VisitTemplateSpecializationType( |
| 357 | const TemplateSpecializationType *T); |
| 358 | ExpectedType VisitElaboratedType(const ElaboratedType *T); |
| 359 | ExpectedType VisitDependentNameType(const DependentNameType *T); |
| 360 | ExpectedType VisitPackExpansionType(const PackExpansionType *T); |
| 361 | ExpectedType VisitDependentTemplateSpecializationType( |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 362 | const DependentTemplateSpecializationType *T); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 363 | ExpectedType VisitObjCInterfaceType(const ObjCInterfaceType *T); |
| 364 | ExpectedType VisitObjCObjectType(const ObjCObjectType *T); |
| 365 | ExpectedType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); |
Rafael Stahl | df55620 | 2018-05-29 08:12:15 +0000 | [diff] [blame] | 366 | |
| 367 | // Importing declarations |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 368 | Error ImportDeclParts( |
| 369 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, |
| 370 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc); |
| 371 | Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr); |
| 372 | Error ImportDeclarationNameLoc( |
| 373 | const DeclarationNameInfo &From, DeclarationNameInfo &To); |
| 374 | Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); |
| 375 | Error ImportDeclContext( |
| 376 | Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC); |
| 377 | Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 378 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 379 | Expected<CXXCastPath> ImportCastPath(CastExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 380 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 381 | using Designator = DesignatedInitExpr::Designator; |
| 382 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 383 | /// What we should import from the definition. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 384 | enum ImportDefinitionKind { |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 385 | /// Import the default subset of the definition, which might be |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 386 | /// nothing (if minimal import is set) or might be everything (if minimal |
| 387 | /// import is not set). |
| 388 | IDK_Default, |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 389 | /// Import everything. |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 390 | IDK_Everything, |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 391 | /// Import only the bare bones needed to establish a valid |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 392 | /// DeclContext. |
| 393 | IDK_Basic |
| 394 | }; |
| 395 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 396 | bool shouldForceImportDeclContext(ImportDefinitionKind IDK) { |
| 397 | return IDK == IDK_Everything || |
| 398 | (IDK == IDK_Default && !Importer.isMinimalImport()); |
| 399 | } |
| 400 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 401 | Error ImportInitializer(VarDecl *From, VarDecl *To); |
| 402 | Error ImportDefinition( |
| 403 | RecordDecl *From, RecordDecl *To, |
| 404 | ImportDefinitionKind Kind = IDK_Default); |
| 405 | Error ImportDefinition( |
| 406 | EnumDecl *From, EnumDecl *To, |
| 407 | ImportDefinitionKind Kind = IDK_Default); |
| 408 | Error ImportDefinition( |
| 409 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, |
| 410 | ImportDefinitionKind Kind = IDK_Default); |
| 411 | Error ImportDefinition( |
| 412 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, |
| 413 | ImportDefinitionKind Kind = IDK_Default); |
| 414 | Expected<TemplateParameterList *> ImportTemplateParameterList( |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 415 | TemplateParameterList *Params); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 416 | Error ImportTemplateArguments( |
| 417 | const TemplateArgument *FromArgs, unsigned NumFromArgs, |
| 418 | SmallVectorImpl<TemplateArgument> &ToArgs); |
| 419 | Expected<TemplateArgument> |
| 420 | ImportTemplateArgument(const TemplateArgument &From); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 421 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 422 | template <typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 423 | Error ImportTemplateArgumentListInfo( |
| 424 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 425 | |
| 426 | template<typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 427 | Error ImportTemplateArgumentListInfo( |
| 428 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 429 | const InContainerTy &Container, TemplateArgumentListInfo &Result); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 430 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 431 | using TemplateArgsTy = SmallVector<TemplateArgument, 8>; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 432 | using FunctionTemplateAndArgsTy = |
| 433 | std::tuple<FunctionTemplateDecl *, TemplateArgsTy>; |
| 434 | Expected<FunctionTemplateAndArgsTy> |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 435 | ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 436 | FunctionDecl *FromFD); |
| 437 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 438 | Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 439 | |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 440 | Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD); |
| 441 | |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 442 | bool IsStructuralMatch(Decl *From, Decl *To, bool Complain); |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 443 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, |
| 444 | bool Complain = true); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 445 | bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 446 | bool Complain = true); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 447 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 448 | bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 449 | bool IsStructuralMatch(FunctionTemplateDecl *From, |
| 450 | FunctionTemplateDecl *To); |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 451 | bool IsStructuralMatch(FunctionDecl *From, FunctionDecl *To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 452 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 453 | bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 454 | ExpectedDecl VisitDecl(Decl *D); |
| 455 | ExpectedDecl VisitImportDecl(ImportDecl *D); |
| 456 | ExpectedDecl VisitEmptyDecl(EmptyDecl *D); |
| 457 | ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D); |
| 458 | ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D); |
| 459 | ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D); |
| 460 | ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D); |
| 461 | ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
| 462 | ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); |
| 463 | ExpectedDecl VisitTypedefDecl(TypedefDecl *D); |
| 464 | ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D); |
| 465 | ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); |
| 466 | ExpectedDecl VisitLabelDecl(LabelDecl *D); |
| 467 | ExpectedDecl VisitEnumDecl(EnumDecl *D); |
| 468 | ExpectedDecl VisitRecordDecl(RecordDecl *D); |
| 469 | ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D); |
| 470 | ExpectedDecl VisitFunctionDecl(FunctionDecl *D); |
| 471 | ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D); |
| 472 | ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 473 | ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 474 | ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D); |
| 475 | ExpectedDecl VisitFieldDecl(FieldDecl *D); |
| 476 | ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D); |
| 477 | ExpectedDecl VisitFriendDecl(FriendDecl *D); |
| 478 | ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D); |
| 479 | ExpectedDecl VisitVarDecl(VarDecl *D); |
| 480 | ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D); |
| 481 | ExpectedDecl VisitParmVarDecl(ParmVarDecl *D); |
| 482 | ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D); |
| 483 | ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
| 484 | ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| 485 | ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| 486 | ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D); |
| 487 | ExpectedDecl VisitUsingDecl(UsingDecl *D); |
| 488 | ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D); |
| 489 | ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 490 | ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
| 491 | ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 492 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 493 | Expected<ObjCTypeParamList *> |
| 494 | ImportObjCTypeParamList(ObjCTypeParamList *list); |
| 495 | |
| 496 | ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
| 497 | ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| 498 | ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| 499 | ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| 500 | ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
| 501 | ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
| 502 | ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 503 | ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
| 504 | ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D); |
| 505 | ExpectedDecl VisitClassTemplateSpecializationDecl( |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 506 | ClassTemplateSpecializationDecl *D); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 507 | ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D); |
| 508 | ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); |
| 509 | ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 510 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 511 | // Importing statements |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 512 | ExpectedStmt VisitStmt(Stmt *S); |
| 513 | ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S); |
| 514 | ExpectedStmt VisitDeclStmt(DeclStmt *S); |
| 515 | ExpectedStmt VisitNullStmt(NullStmt *S); |
| 516 | ExpectedStmt VisitCompoundStmt(CompoundStmt *S); |
| 517 | ExpectedStmt VisitCaseStmt(CaseStmt *S); |
| 518 | ExpectedStmt VisitDefaultStmt(DefaultStmt *S); |
| 519 | ExpectedStmt VisitLabelStmt(LabelStmt *S); |
| 520 | ExpectedStmt VisitAttributedStmt(AttributedStmt *S); |
| 521 | ExpectedStmt VisitIfStmt(IfStmt *S); |
| 522 | ExpectedStmt VisitSwitchStmt(SwitchStmt *S); |
| 523 | ExpectedStmt VisitWhileStmt(WhileStmt *S); |
| 524 | ExpectedStmt VisitDoStmt(DoStmt *S); |
| 525 | ExpectedStmt VisitForStmt(ForStmt *S); |
| 526 | ExpectedStmt VisitGotoStmt(GotoStmt *S); |
| 527 | ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S); |
| 528 | ExpectedStmt VisitContinueStmt(ContinueStmt *S); |
| 529 | ExpectedStmt VisitBreakStmt(BreakStmt *S); |
| 530 | ExpectedStmt VisitReturnStmt(ReturnStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 531 | // FIXME: MSAsmStmt |
| 532 | // FIXME: SEHExceptStmt |
| 533 | // FIXME: SEHFinallyStmt |
| 534 | // FIXME: SEHTryStmt |
| 535 | // FIXME: SEHLeaveStmt |
| 536 | // FIXME: CapturedStmt |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 537 | ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S); |
| 538 | ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S); |
| 539 | ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 540 | // FIXME: MSDependentExistsStmt |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 541 | ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); |
| 542 | ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); |
| 543 | ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); |
| 544 | ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S); |
| 545 | ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); |
| 546 | ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); |
| 547 | ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 548 | |
| 549 | // Importing expressions |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 550 | ExpectedStmt VisitExpr(Expr *E); |
| 551 | ExpectedStmt VisitVAArgExpr(VAArgExpr *E); |
| 552 | ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E); |
| 553 | ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E); |
| 554 | ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E); |
| 555 | ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E); |
| 556 | ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E); |
| 557 | ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); |
| 558 | ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E); |
| 559 | ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E); |
| 560 | ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E); |
| 561 | ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E); |
| 562 | ExpectedStmt VisitStringLiteral(StringLiteral *E); |
| 563 | ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
| 564 | ExpectedStmt VisitAtomicExpr(AtomicExpr *E); |
| 565 | ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E); |
Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 566 | ExpectedStmt VisitConstantExpr(ConstantExpr *E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 567 | ExpectedStmt VisitParenExpr(ParenExpr *E); |
| 568 | ExpectedStmt VisitParenListExpr(ParenListExpr *E); |
| 569 | ExpectedStmt VisitStmtExpr(StmtExpr *E); |
| 570 | ExpectedStmt VisitUnaryOperator(UnaryOperator *E); |
| 571 | ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); |
| 572 | ExpectedStmt VisitBinaryOperator(BinaryOperator *E); |
| 573 | ExpectedStmt VisitConditionalOperator(ConditionalOperator *E); |
| 574 | ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E); |
| 575 | ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E); |
| 576 | ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); |
| 577 | ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E); |
| 578 | ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
| 579 | ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E); |
| 580 | ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E); |
| 581 | ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 582 | ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE); |
| 583 | ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E); |
| 584 | ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E); |
| 585 | ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); |
| 586 | ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); |
| 587 | ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); |
| 588 | ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E); |
| 589 | ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); |
| 590 | ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E); |
| 591 | ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E); |
| 592 | ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E); |
| 593 | ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E); |
| 594 | ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E); |
| 595 | ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E); |
| 596 | ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); |
| 597 | ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E); |
| 598 | ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E); |
| 599 | ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); |
| 600 | ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E); |
| 601 | ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E); |
| 602 | ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E); |
| 603 | ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); |
| 604 | ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); |
| 605 | ExpectedStmt VisitMemberExpr(MemberExpr *E); |
| 606 | ExpectedStmt VisitCallExpr(CallExpr *E); |
| 607 | ExpectedStmt VisitLambdaExpr(LambdaExpr *LE); |
| 608 | ExpectedStmt VisitInitListExpr(InitListExpr *E); |
| 609 | ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E); |
| 610 | ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E); |
| 611 | ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); |
| 612 | ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); |
| 613 | ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); |
| 614 | ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E); |
| 615 | ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); |
| 616 | ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E); |
| 617 | ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 618 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 619 | template<typename IIter, typename OIter> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 620 | Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 621 | using ItemT = typename std::remove_reference<decltype(*Obegin)>::type; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 622 | for (; Ibegin != Iend; ++Ibegin, ++Obegin) { |
| 623 | Expected<ItemT> ToOrErr = import(*Ibegin); |
| 624 | if (!ToOrErr) |
| 625 | return ToOrErr.takeError(); |
| 626 | *Obegin = *ToOrErr; |
| 627 | } |
| 628 | return Error::success(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 629 | } |
| 630 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 631 | // Import every item from a container structure into an output container. |
| 632 | // If error occurs, stops at first error and returns the error. |
| 633 | // The output container should have space for all needed elements (it is not |
| 634 | // expanded, new items are put into from the beginning). |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 635 | template<typename InContainerTy, typename OutContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 636 | Error ImportContainerChecked( |
| 637 | const InContainerTy &InContainer, OutContainerTy &OutContainer) { |
| 638 | return ImportArrayChecked( |
| 639 | InContainer.begin(), InContainer.end(), OutContainer.begin()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | template<typename InContainerTy, typename OIter> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 643 | Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 644 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); |
| 645 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 646 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 647 | void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 648 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 649 | Expected<FunctionDecl *> FindFunctionTemplateSpecialization( |
| 650 | FunctionDecl *FromFD); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 651 | }; |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 652 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 653 | // FIXME: Temporary until every import returns Expected. |
| 654 | template <> |
| 655 | Expected<TemplateName> ASTNodeImporter::import(const TemplateName &From) { |
| 656 | TemplateName To = Importer.Import(From); |
| 657 | if (To.isNull() && !From.isNull()) |
| 658 | return make_error<ImportError>(); |
| 659 | return To; |
| 660 | } |
| 661 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 662 | template <typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 663 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 664 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 665 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 666 | auto ToLAngleLocOrErr = import(FromLAngleLoc); |
| 667 | if (!ToLAngleLocOrErr) |
| 668 | return ToLAngleLocOrErr.takeError(); |
| 669 | auto ToRAngleLocOrErr = import(FromRAngleLoc); |
| 670 | if (!ToRAngleLocOrErr) |
| 671 | return ToRAngleLocOrErr.takeError(); |
| 672 | |
| 673 | TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr); |
| 674 | if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo)) |
| 675 | return Err; |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 676 | Result = ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 677 | return Error::success(); |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 678 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 679 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 680 | template <> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 681 | Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 682 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { |
| 683 | return ImportTemplateArgumentListInfo( |
| 684 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); |
| 685 | } |
| 686 | |
| 687 | template <> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 688 | Error ASTNodeImporter::ImportTemplateArgumentListInfo< |
| 689 | ASTTemplateArgumentListInfo>( |
| 690 | const ASTTemplateArgumentListInfo &From, |
| 691 | TemplateArgumentListInfo &Result) { |
| 692 | return ImportTemplateArgumentListInfo( |
| 693 | From.LAngleLoc, From.RAngleLoc, From.arguments(), Result); |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 694 | } |
| 695 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 696 | Expected<ASTNodeImporter::FunctionTemplateAndArgsTy> |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 697 | ASTNodeImporter::ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 698 | FunctionDecl *FromFD) { |
| 699 | assert(FromFD->getTemplatedKind() == |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 700 | FunctionDecl::TK_FunctionTemplateSpecialization); |
| 701 | |
| 702 | FunctionTemplateAndArgsTy Result; |
| 703 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 704 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 705 | if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate())) |
| 706 | return std::move(Err); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 707 | |
| 708 | // Import template arguments. |
| 709 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 710 | if (Error Err = ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), |
| 711 | std::get<1>(Result))) |
| 712 | return std::move(Err); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 713 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 714 | return Result; |
| 715 | } |
| 716 | |
| 717 | template <> |
| 718 | Expected<TemplateParameterList *> |
| 719 | ASTNodeImporter::import(TemplateParameterList *From) { |
| 720 | SmallVector<NamedDecl *, 4> To(From->size()); |
| 721 | if (Error Err = ImportContainerChecked(*From, To)) |
| 722 | return std::move(Err); |
| 723 | |
| 724 | ExpectedExpr ToRequiresClause = import(From->getRequiresClause()); |
| 725 | if (!ToRequiresClause) |
| 726 | return ToRequiresClause.takeError(); |
| 727 | |
| 728 | auto ToTemplateLocOrErr = import(From->getTemplateLoc()); |
| 729 | if (!ToTemplateLocOrErr) |
| 730 | return ToTemplateLocOrErr.takeError(); |
| 731 | auto ToLAngleLocOrErr = import(From->getLAngleLoc()); |
| 732 | if (!ToLAngleLocOrErr) |
| 733 | return ToLAngleLocOrErr.takeError(); |
| 734 | auto ToRAngleLocOrErr = import(From->getRAngleLoc()); |
| 735 | if (!ToRAngleLocOrErr) |
| 736 | return ToRAngleLocOrErr.takeError(); |
| 737 | |
| 738 | return TemplateParameterList::Create( |
| 739 | Importer.getToContext(), |
| 740 | *ToTemplateLocOrErr, |
| 741 | *ToLAngleLocOrErr, |
| 742 | To, |
| 743 | *ToRAngleLocOrErr, |
| 744 | *ToRequiresClause); |
| 745 | } |
| 746 | |
| 747 | template <> |
| 748 | Expected<TemplateArgument> |
| 749 | ASTNodeImporter::import(const TemplateArgument &From) { |
| 750 | switch (From.getKind()) { |
| 751 | case TemplateArgument::Null: |
| 752 | return TemplateArgument(); |
| 753 | |
| 754 | case TemplateArgument::Type: { |
| 755 | ExpectedType ToTypeOrErr = import(From.getAsType()); |
| 756 | if (!ToTypeOrErr) |
| 757 | return ToTypeOrErr.takeError(); |
| 758 | return TemplateArgument(*ToTypeOrErr); |
| 759 | } |
| 760 | |
| 761 | case TemplateArgument::Integral: { |
| 762 | ExpectedType ToTypeOrErr = import(From.getIntegralType()); |
| 763 | if (!ToTypeOrErr) |
| 764 | return ToTypeOrErr.takeError(); |
| 765 | return TemplateArgument(From, *ToTypeOrErr); |
| 766 | } |
| 767 | |
| 768 | case TemplateArgument::Declaration: { |
| 769 | Expected<ValueDecl *> ToOrErr = import(From.getAsDecl()); |
| 770 | if (!ToOrErr) |
| 771 | return ToOrErr.takeError(); |
| 772 | ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl()); |
| 773 | if (!ToTypeOrErr) |
| 774 | return ToTypeOrErr.takeError(); |
| 775 | return TemplateArgument(*ToOrErr, *ToTypeOrErr); |
| 776 | } |
| 777 | |
| 778 | case TemplateArgument::NullPtr: { |
| 779 | ExpectedType ToTypeOrErr = import(From.getNullPtrType()); |
| 780 | if (!ToTypeOrErr) |
| 781 | return ToTypeOrErr.takeError(); |
| 782 | return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true); |
| 783 | } |
| 784 | |
| 785 | case TemplateArgument::Template: { |
| 786 | Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate()); |
| 787 | if (!ToTemplateOrErr) |
| 788 | return ToTemplateOrErr.takeError(); |
| 789 | |
| 790 | return TemplateArgument(*ToTemplateOrErr); |
| 791 | } |
| 792 | |
| 793 | case TemplateArgument::TemplateExpansion: { |
| 794 | Expected<TemplateName> ToTemplateOrErr = |
| 795 | import(From.getAsTemplateOrTemplatePattern()); |
| 796 | if (!ToTemplateOrErr) |
| 797 | return ToTemplateOrErr.takeError(); |
| 798 | |
| 799 | return TemplateArgument( |
| 800 | *ToTemplateOrErr, From.getNumTemplateExpansions()); |
| 801 | } |
| 802 | |
| 803 | case TemplateArgument::Expression: |
| 804 | if (ExpectedExpr ToExpr = import(From.getAsExpr())) |
| 805 | return TemplateArgument(*ToExpr); |
| 806 | else |
| 807 | return ToExpr.takeError(); |
| 808 | |
| 809 | case TemplateArgument::Pack: { |
| 810 | SmallVector<TemplateArgument, 2> ToPack; |
| 811 | ToPack.reserve(From.pack_size()); |
| 812 | if (Error Err = ImportTemplateArguments( |
| 813 | From.pack_begin(), From.pack_size(), ToPack)) |
| 814 | return std::move(Err); |
| 815 | |
| 816 | return TemplateArgument( |
| 817 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); |
| 818 | } |
| 819 | } |
| 820 | |
| 821 | llvm_unreachable("Invalid template argument kind"); |
| 822 | } |
| 823 | |
| 824 | template <> |
| 825 | Expected<TemplateArgumentLoc> |
| 826 | ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) { |
| 827 | Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument()); |
| 828 | if (!ArgOrErr) |
| 829 | return ArgOrErr.takeError(); |
| 830 | TemplateArgument Arg = *ArgOrErr; |
| 831 | |
| 832 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); |
| 833 | |
| 834 | TemplateArgumentLocInfo ToInfo; |
| 835 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 836 | ExpectedExpr E = import(FromInfo.getAsExpr()); |
| 837 | if (!E) |
| 838 | return E.takeError(); |
| 839 | ToInfo = TemplateArgumentLocInfo(*E); |
| 840 | } else if (Arg.getKind() == TemplateArgument::Type) { |
| 841 | if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo())) |
| 842 | ToInfo = TemplateArgumentLocInfo(*TSIOrErr); |
| 843 | else |
| 844 | return TSIOrErr.takeError(); |
| 845 | } else { |
| 846 | auto ToTemplateQualifierLocOrErr = |
| 847 | import(FromInfo.getTemplateQualifierLoc()); |
| 848 | if (!ToTemplateQualifierLocOrErr) |
| 849 | return ToTemplateQualifierLocOrErr.takeError(); |
| 850 | auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc()); |
| 851 | if (!ToTemplateNameLocOrErr) |
| 852 | return ToTemplateNameLocOrErr.takeError(); |
| 853 | auto ToTemplateEllipsisLocOrErr = |
| 854 | import(FromInfo.getTemplateEllipsisLoc()); |
| 855 | if (!ToTemplateEllipsisLocOrErr) |
| 856 | return ToTemplateEllipsisLocOrErr.takeError(); |
| 857 | |
| 858 | ToInfo = TemplateArgumentLocInfo( |
| 859 | *ToTemplateQualifierLocOrErr, |
| 860 | *ToTemplateNameLocOrErr, |
| 861 | *ToTemplateEllipsisLocOrErr); |
| 862 | } |
| 863 | |
| 864 | return TemplateArgumentLoc(Arg, ToInfo); |
| 865 | } |
| 866 | |
| 867 | template <> |
| 868 | Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) { |
| 869 | if (DG.isNull()) |
| 870 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); |
| 871 | size_t NumDecls = DG.end() - DG.begin(); |
| 872 | SmallVector<Decl *, 1> ToDecls; |
| 873 | ToDecls.reserve(NumDecls); |
| 874 | for (Decl *FromD : DG) { |
| 875 | if (auto ToDOrErr = import(FromD)) |
| 876 | ToDecls.push_back(*ToDOrErr); |
| 877 | else |
| 878 | return ToDOrErr.takeError(); |
| 879 | } |
| 880 | return DeclGroupRef::Create(Importer.getToContext(), |
| 881 | ToDecls.begin(), |
| 882 | NumDecls); |
| 883 | } |
| 884 | |
| 885 | template <> |
| 886 | Expected<ASTNodeImporter::Designator> |
| 887 | ASTNodeImporter::import(const Designator &D) { |
| 888 | if (D.isFieldDesignator()) { |
| 889 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); |
| 890 | |
| 891 | ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc()); |
| 892 | if (!ToDotLocOrErr) |
| 893 | return ToDotLocOrErr.takeError(); |
| 894 | |
| 895 | ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc()); |
| 896 | if (!ToFieldLocOrErr) |
| 897 | return ToFieldLocOrErr.takeError(); |
| 898 | |
| 899 | return Designator(ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr); |
| 900 | } |
| 901 | |
| 902 | ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc()); |
| 903 | if (!ToLBracketLocOrErr) |
| 904 | return ToLBracketLocOrErr.takeError(); |
| 905 | |
| 906 | ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc()); |
| 907 | if (!ToRBracketLocOrErr) |
| 908 | return ToRBracketLocOrErr.takeError(); |
| 909 | |
| 910 | if (D.isArrayDesignator()) |
| 911 | return Designator(D.getFirstExprIndex(), |
| 912 | *ToLBracketLocOrErr, *ToRBracketLocOrErr); |
| 913 | |
| 914 | ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc()); |
| 915 | if (!ToEllipsisLocOrErr) |
| 916 | return ToEllipsisLocOrErr.takeError(); |
| 917 | |
| 918 | assert(D.isArrayRangeDesignator()); |
| 919 | return Designator( |
| 920 | D.getFirstExprIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr, |
| 921 | *ToRBracketLocOrErr); |
| 922 | } |
| 923 | |
| 924 | template <> |
| 925 | Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) { |
| 926 | VarDecl *Var = nullptr; |
| 927 | if (From.capturesVariable()) { |
| 928 | if (auto VarOrErr = import(From.getCapturedVar())) |
| 929 | Var = *VarOrErr; |
| 930 | else |
| 931 | return VarOrErr.takeError(); |
| 932 | } |
| 933 | |
| 934 | auto LocationOrErr = import(From.getLocation()); |
| 935 | if (!LocationOrErr) |
| 936 | return LocationOrErr.takeError(); |
| 937 | |
| 938 | SourceLocation EllipsisLoc; |
| 939 | if (From.isPackExpansion()) |
| 940 | if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc())) |
| 941 | return std::move(Err); |
| 942 | |
| 943 | return LambdaCapture( |
| 944 | *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var, |
| 945 | EllipsisLoc); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 946 | } |
| 947 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 948 | } // namespace clang |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 949 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 950 | //---------------------------------------------------------------------------- |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 951 | // Import Types |
| 952 | //---------------------------------------------------------------------------- |
| 953 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 954 | using namespace clang; |
| 955 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 956 | ExpectedType ASTNodeImporter::VisitType(const Type *T) { |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 957 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) |
| 958 | << T->getTypeClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 959 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 960 | } |
| 961 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 962 | ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ |
| 963 | ExpectedType UnderlyingTypeOrErr = import(T->getValueType()); |
| 964 | if (!UnderlyingTypeOrErr) |
| 965 | return UnderlyingTypeOrErr.takeError(); |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 966 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 967 | return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr); |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 968 | } |
| 969 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 970 | ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 971 | switch (T->getKind()) { |
Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 972 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 973 | case BuiltinType::Id: \ |
| 974 | return Importer.getToContext().SingletonId; |
Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 975 | #include "clang/Basic/OpenCLImageTypes.def" |
Andrew Savonichev | 3fee351 | 2018-11-08 11:25:41 +0000 | [diff] [blame] | 976 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ |
| 977 | case BuiltinType::Id: \ |
| 978 | return Importer.getToContext().Id##Ty; |
| 979 | #include "clang/Basic/OpenCLExtensionTypes.def" |
John McCall | e314e27 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 980 | #define SHARED_SINGLETON_TYPE(Expansion) |
| 981 | #define BUILTIN_TYPE(Id, SingletonId) \ |
| 982 | case BuiltinType::Id: return Importer.getToContext().SingletonId; |
| 983 | #include "clang/AST/BuiltinTypes.def" |
| 984 | |
| 985 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" |
| 986 | // context supports C++. |
| 987 | |
| 988 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" |
| 989 | // context supports ObjC. |
| 990 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 991 | case BuiltinType::Char_U: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 992 | // The context we're importing from has an unsigned 'char'. If we're |
| 993 | // importing into a context with a signed 'char', translate to |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 994 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 995 | if (Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 996 | return Importer.getToContext().UnsignedCharTy; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 997 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 998 | return Importer.getToContext().CharTy; |
| 999 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1000 | case BuiltinType::Char_S: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1001 | // The context we're importing from has an unsigned 'char'. If we're |
| 1002 | // importing into a context with a signed 'char', translate to |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1003 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1004 | if (!Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1005 | return Importer.getToContext().SignedCharTy; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1006 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1007 | return Importer.getToContext().CharTy; |
| 1008 | |
Chris Lattner | ad3467e | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 1009 | case BuiltinType::WChar_S: |
| 1010 | case BuiltinType::WChar_U: |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1011 | // FIXME: If not in C++, shall we translate to the C equivalent of |
| 1012 | // wchar_t? |
| 1013 | return Importer.getToContext().WCharTy; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1014 | } |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 1015 | |
| 1016 | llvm_unreachable("Invalid BuiltinType Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1019 | ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { |
| 1020 | ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType()); |
| 1021 | if (!ToOriginalTypeOrErr) |
| 1022 | return ToOriginalTypeOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1023 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1024 | return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1027 | ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) { |
| 1028 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1029 | if (!ToElementTypeOrErr) |
| 1030 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1031 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1032 | return Importer.getToContext().getComplexType(*ToElementTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1033 | } |
| 1034 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1035 | ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) { |
| 1036 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1037 | if (!ToPointeeTypeOrErr) |
| 1038 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1039 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1040 | return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1043 | ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1044 | // FIXME: Check for blocks support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1045 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1046 | if (!ToPointeeTypeOrErr) |
| 1047 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1048 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1049 | return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1052 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1053 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1054 | // FIXME: Check for C++ support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1055 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); |
| 1056 | if (!ToPointeeTypeOrErr) |
| 1057 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1058 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1059 | return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1060 | } |
| 1061 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1062 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1063 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1064 | // FIXME: Check for C++0x support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1065 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); |
| 1066 | if (!ToPointeeTypeOrErr) |
| 1067 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1068 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1069 | return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1070 | } |
| 1071 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1072 | ExpectedType |
| 1073 | ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1074 | // FIXME: Check for C++ support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1075 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1076 | if (!ToPointeeTypeOrErr) |
| 1077 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1078 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1079 | ExpectedType ClassTypeOrErr = import(QualType(T->getClass(), 0)); |
| 1080 | if (!ClassTypeOrErr) |
| 1081 | return ClassTypeOrErr.takeError(); |
| 1082 | |
| 1083 | return Importer.getToContext().getMemberPointerType( |
| 1084 | *ToPointeeTypeOrErr, (*ClassTypeOrErr).getTypePtr()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1087 | ExpectedType |
| 1088 | ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { |
| 1089 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1090 | if (!ToElementTypeOrErr) |
| 1091 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1092 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1093 | return Importer.getToContext().getConstantArrayType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1094 | T->getSize(), |
| 1095 | T->getSizeModifier(), |
| 1096 | T->getIndexTypeCVRQualifiers()); |
| 1097 | } |
| 1098 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1099 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1100 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1101 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1102 | if (!ToElementTypeOrErr) |
| 1103 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1104 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1105 | return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1106 | T->getSizeModifier(), |
| 1107 | T->getIndexTypeCVRQualifiers()); |
| 1108 | } |
| 1109 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1110 | ExpectedType |
| 1111 | ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { |
| 1112 | QualType ToElementType; |
| 1113 | Expr *ToSizeExpr; |
| 1114 | SourceRange ToBracketsRange; |
| 1115 | if (auto Imp = importSeq( |
| 1116 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) |
| 1117 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; |
| 1118 | else |
| 1119 | return Imp.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1120 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1121 | return Importer.getToContext().getVariableArrayType( |
| 1122 | ToElementType, ToSizeExpr, T->getSizeModifier(), |
| 1123 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1124 | } |
| 1125 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1126 | ExpectedType ASTNodeImporter::VisitDependentSizedArrayType( |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1127 | const DependentSizedArrayType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1128 | QualType ToElementType; |
| 1129 | Expr *ToSizeExpr; |
| 1130 | SourceRange ToBracketsRange; |
| 1131 | if (auto Imp = importSeq( |
| 1132 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) |
| 1133 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; |
| 1134 | else |
| 1135 | return Imp.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1136 | // SizeExpr may be null if size is not specified directly. |
| 1137 | // For example, 'int a[]'. |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1138 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1139 | return Importer.getToContext().getDependentSizedArrayType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1140 | ToElementType, ToSizeExpr, T->getSizeModifier(), |
| 1141 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1144 | ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) { |
| 1145 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1146 | if (!ToElementTypeOrErr) |
| 1147 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1148 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1149 | return Importer.getToContext().getVectorType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1150 | T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 1151 | T->getVectorKind()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1154 | ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { |
| 1155 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1156 | if (!ToElementTypeOrErr) |
| 1157 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1158 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1159 | return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1160 | T->getNumElements()); |
| 1161 | } |
| 1162 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1163 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1164 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1165 | // FIXME: What happens if we're importing a function without a prototype |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1166 | // into C++? Should we make it variadic? |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1167 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); |
| 1168 | if (!ToReturnTypeOrErr) |
| 1169 | return ToReturnTypeOrErr.takeError(); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1170 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1171 | return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr, |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1172 | T->getExtInfo()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1173 | } |
| 1174 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1175 | ExpectedType |
| 1176 | ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { |
| 1177 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); |
| 1178 | if (!ToReturnTypeOrErr) |
| 1179 | return ToReturnTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1180 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1181 | // Import argument types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1182 | SmallVector<QualType, 4> ArgTypes; |
Aaron Ballman | 40bd0aa | 2014-03-17 15:23:01 +0000 | [diff] [blame] | 1183 | for (const auto &A : T->param_types()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1184 | ExpectedType TyOrErr = import(A); |
| 1185 | if (!TyOrErr) |
| 1186 | return TyOrErr.takeError(); |
| 1187 | ArgTypes.push_back(*TyOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1188 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1189 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1190 | // Import exception types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1191 | SmallVector<QualType, 4> ExceptionTypes; |
Aaron Ballman | b088fbe | 2014-03-17 15:38:09 +0000 | [diff] [blame] | 1192 | for (const auto &E : T->exceptions()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1193 | ExpectedType TyOrErr = import(E); |
| 1194 | if (!TyOrErr) |
| 1195 | return TyOrErr.takeError(); |
| 1196 | ExceptionTypes.push_back(*TyOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1197 | } |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 1198 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1199 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); |
| 1200 | FunctionProtoType::ExtProtoInfo ToEPI; |
| 1201 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1202 | auto Imp = importSeq( |
| 1203 | FromEPI.ExceptionSpec.NoexceptExpr, |
| 1204 | FromEPI.ExceptionSpec.SourceDecl, |
| 1205 | FromEPI.ExceptionSpec.SourceTemplate); |
| 1206 | if (!Imp) |
| 1207 | return Imp.takeError(); |
| 1208 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1209 | ToEPI.ExtInfo = FromEPI.ExtInfo; |
| 1210 | ToEPI.Variadic = FromEPI.Variadic; |
| 1211 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; |
| 1212 | ToEPI.TypeQuals = FromEPI.TypeQuals; |
| 1213 | ToEPI.RefQualifier = FromEPI.RefQualifier; |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 1214 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; |
| 1215 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1216 | std::tie( |
| 1217 | ToEPI.ExceptionSpec.NoexceptExpr, |
| 1218 | ToEPI.ExceptionSpec.SourceDecl, |
| 1219 | ToEPI.ExceptionSpec.SourceTemplate) = *Imp; |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1220 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1221 | return Importer.getToContext().getFunctionType( |
| 1222 | *ToReturnTypeOrErr, ArgTypes, ToEPI); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1223 | } |
| 1224 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1225 | ExpectedType ASTNodeImporter::VisitUnresolvedUsingType( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1226 | const UnresolvedUsingType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1227 | UnresolvedUsingTypenameDecl *ToD; |
| 1228 | Decl *ToPrevD; |
| 1229 | if (auto Imp = importSeq(T->getDecl(), T->getDecl()->getPreviousDecl())) |
| 1230 | std::tie(ToD, ToPrevD) = *Imp; |
| 1231 | else |
| 1232 | return Imp.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1233 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1234 | return Importer.getToContext().getTypeDeclType( |
| 1235 | ToD, cast_or_null<TypeDecl>(ToPrevD)); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1238 | ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) { |
| 1239 | ExpectedType ToInnerTypeOrErr = import(T->getInnerType()); |
| 1240 | if (!ToInnerTypeOrErr) |
| 1241 | return ToInnerTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1242 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1243 | return Importer.getToContext().getParenType(*ToInnerTypeOrErr); |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 1244 | } |
| 1245 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1246 | ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { |
| 1247 | Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1248 | if (!ToDeclOrErr) |
| 1249 | return ToDeclOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1250 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1251 | return Importer.getToContext().getTypeDeclType(*ToDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1252 | } |
| 1253 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1254 | ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { |
| 1255 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); |
| 1256 | if (!ToExprOrErr) |
| 1257 | return ToExprOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1258 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1259 | return Importer.getToContext().getTypeOfExprType(*ToExprOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1260 | } |
| 1261 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1262 | ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { |
| 1263 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1264 | if (!ToUnderlyingTypeOrErr) |
| 1265 | return ToUnderlyingTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1266 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1267 | return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1268 | } |
| 1269 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1270 | ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1271 | // FIXME: Make sure that the "to" context supports C++0x! |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1272 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); |
| 1273 | if (!ToExprOrErr) |
| 1274 | return ToExprOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1275 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1276 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1277 | if (!ToUnderlyingTypeOrErr) |
| 1278 | return ToUnderlyingTypeOrErr.takeError(); |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 1279 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1280 | return Importer.getToContext().getDecltypeType( |
| 1281 | *ToExprOrErr, *ToUnderlyingTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1282 | } |
| 1283 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1284 | ExpectedType |
| 1285 | ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 1286 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); |
| 1287 | if (!ToBaseTypeOrErr) |
| 1288 | return ToBaseTypeOrErr.takeError(); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1289 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1290 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1291 | if (!ToUnderlyingTypeOrErr) |
| 1292 | return ToUnderlyingTypeOrErr.takeError(); |
| 1293 | |
| 1294 | return Importer.getToContext().getUnaryTransformType( |
| 1295 | *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind()); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1296 | } |
| 1297 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1298 | ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 1299 | // FIXME: Make sure that the "to" context supports C++11! |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1300 | ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType()); |
| 1301 | if (!ToDeducedTypeOrErr) |
| 1302 | return ToDeducedTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1303 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1304 | return Importer.getToContext().getAutoType(*ToDeducedTypeOrErr, |
| 1305 | T->getKeyword(), |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 1306 | /*IsDependent*/false); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1307 | } |
| 1308 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1309 | ExpectedType ASTNodeImporter::VisitInjectedClassNameType( |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1310 | const InjectedClassNameType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1311 | Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1312 | if (!ToDeclOrErr) |
| 1313 | return ToDeclOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1314 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1315 | ExpectedType ToInjTypeOrErr = import(T->getInjectedSpecializationType()); |
| 1316 | if (!ToInjTypeOrErr) |
| 1317 | return ToInjTypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1318 | |
| 1319 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading |
| 1320 | // See comments in InjectedClassNameType definition for details |
| 1321 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); |
| 1322 | enum { |
| 1323 | TypeAlignmentInBits = 4, |
| 1324 | TypeAlignment = 1 << TypeAlignmentInBits |
| 1325 | }; |
| 1326 | |
| 1327 | return QualType(new (Importer.getToContext(), TypeAlignment) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1328 | InjectedClassNameType(*ToDeclOrErr, *ToInjTypeOrErr), 0); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1329 | } |
| 1330 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1331 | ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) { |
| 1332 | Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1333 | if (!ToDeclOrErr) |
| 1334 | return ToDeclOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1335 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1336 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1337 | } |
| 1338 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1339 | ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) { |
| 1340 | Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1341 | if (!ToDeclOrErr) |
| 1342 | return ToDeclOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1343 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1344 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1345 | } |
| 1346 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1347 | ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { |
| 1348 | ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType()); |
| 1349 | if (!ToModifiedTypeOrErr) |
| 1350 | return ToModifiedTypeOrErr.takeError(); |
| 1351 | ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType()); |
| 1352 | if (!ToEquivalentTypeOrErr) |
| 1353 | return ToEquivalentTypeOrErr.takeError(); |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1354 | |
| 1355 | return Importer.getToContext().getAttributedType(T->getAttrKind(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1356 | *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr); |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1357 | } |
| 1358 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1359 | ExpectedType ASTNodeImporter::VisitTemplateTypeParmType( |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1360 | const TemplateTypeParmType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1361 | Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1362 | if (!ToDeclOrErr) |
| 1363 | return ToDeclOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1364 | |
| 1365 | return Importer.getToContext().getTemplateTypeParmType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1366 | T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1367 | } |
| 1368 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1369 | ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType( |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1370 | const SubstTemplateTypeParmType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1371 | ExpectedType ReplacedOrErr = import(QualType(T->getReplacedParameter(), 0)); |
| 1372 | if (!ReplacedOrErr) |
| 1373 | return ReplacedOrErr.takeError(); |
| 1374 | const TemplateTypeParmType *Replaced = |
| 1375 | cast<TemplateTypeParmType>((*ReplacedOrErr).getTypePtr()); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1376 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1377 | ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType()); |
| 1378 | if (!ToReplacementTypeOrErr) |
| 1379 | return ToReplacementTypeOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1380 | |
| 1381 | return Importer.getToContext().getSubstTemplateTypeParmType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1382 | Replaced, (*ToReplacementTypeOrErr).getCanonicalType()); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1385 | ExpectedType ASTNodeImporter::VisitTemplateSpecializationType( |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1386 | const TemplateSpecializationType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1387 | auto ToTemplateOrErr = import(T->getTemplateName()); |
| 1388 | if (!ToTemplateOrErr) |
| 1389 | return ToTemplateOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1390 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1391 | SmallVector<TemplateArgument, 2> ToTemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1392 | if (Error Err = ImportTemplateArguments( |
| 1393 | T->getArgs(), T->getNumArgs(), ToTemplateArgs)) |
| 1394 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1395 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1396 | QualType ToCanonType; |
| 1397 | if (!QualType(T, 0).isCanonical()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1398 | QualType FromCanonType |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1399 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1400 | if (ExpectedType TyOrErr = import(FromCanonType)) |
| 1401 | ToCanonType = *TyOrErr; |
| 1402 | else |
| 1403 | return TyOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1404 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1405 | return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr, |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 1406 | ToTemplateArgs, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1407 | ToCanonType); |
| 1408 | } |
| 1409 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1410 | ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1411 | // Note: the qualifier in an ElaboratedType is optional. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1412 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1413 | if (!ToQualifierOrErr) |
| 1414 | return ToQualifierOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1415 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1416 | ExpectedType ToNamedTypeOrErr = import(T->getNamedType()); |
| 1417 | if (!ToNamedTypeOrErr) |
| 1418 | return ToNamedTypeOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1419 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1420 | Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl()); |
| 1421 | if (!ToOwnedTagDeclOrErr) |
| 1422 | return ToOwnedTagDeclOrErr.takeError(); |
Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 1423 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1424 | return Importer.getToContext().getElaboratedType(T->getKeyword(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1425 | *ToQualifierOrErr, |
| 1426 | *ToNamedTypeOrErr, |
| 1427 | *ToOwnedTagDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1428 | } |
| 1429 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1430 | ExpectedType |
| 1431 | ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { |
| 1432 | ExpectedType ToPatternOrErr = import(T->getPattern()); |
| 1433 | if (!ToPatternOrErr) |
| 1434 | return ToPatternOrErr.takeError(); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1435 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1436 | return Importer.getToContext().getPackExpansionType(*ToPatternOrErr, |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1437 | T->getNumExpansions()); |
| 1438 | } |
| 1439 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1440 | ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType( |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1441 | const DependentTemplateSpecializationType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1442 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1443 | if (!ToQualifierOrErr) |
| 1444 | return ToQualifierOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1445 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1446 | IdentifierInfo *ToName = Importer.Import(T->getIdentifier()); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1447 | |
| 1448 | SmallVector<TemplateArgument, 2> ToPack; |
| 1449 | ToPack.reserve(T->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1450 | if (Error Err = ImportTemplateArguments( |
| 1451 | T->getArgs(), T->getNumArgs(), ToPack)) |
| 1452 | return std::move(Err); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1453 | |
| 1454 | return Importer.getToContext().getDependentTemplateSpecializationType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1455 | T->getKeyword(), *ToQualifierOrErr, ToName, ToPack); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1458 | ExpectedType |
| 1459 | ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) { |
| 1460 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1461 | if (!ToQualifierOrErr) |
| 1462 | return ToQualifierOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1463 | |
| 1464 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1465 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1466 | QualType Canon; |
| 1467 | if (T != T->getCanonicalTypeInternal().getTypePtr()) { |
| 1468 | if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal())) |
| 1469 | Canon = (*TyOrErr).getCanonicalType(); |
| 1470 | else |
| 1471 | return TyOrErr.takeError(); |
| 1472 | } |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1473 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1474 | return Importer.getToContext().getDependentNameType(T->getKeyword(), |
| 1475 | *ToQualifierOrErr, |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1476 | Name, Canon); |
| 1477 | } |
| 1478 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1479 | ExpectedType |
| 1480 | ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
| 1481 | Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1482 | if (!ToDeclOrErr) |
| 1483 | return ToDeclOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1484 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1485 | return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1486 | } |
| 1487 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1488 | ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { |
| 1489 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); |
| 1490 | if (!ToBaseTypeOrErr) |
| 1491 | return ToBaseTypeOrErr.takeError(); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1492 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1493 | SmallVector<QualType, 4> TypeArgs; |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 1494 | for (auto TypeArg : T->getTypeArgsAsWritten()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1495 | if (ExpectedType TyOrErr = import(TypeArg)) |
| 1496 | TypeArgs.push_back(*TyOrErr); |
| 1497 | else |
| 1498 | return TyOrErr.takeError(); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1499 | } |
| 1500 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1501 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 1502 | for (auto *P : T->quals()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1503 | if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P)) |
| 1504 | Protocols.push_back(*ProtocolOrErr); |
| 1505 | else |
| 1506 | return ProtocolOrErr.takeError(); |
| 1507 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1508 | } |
| 1509 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1510 | return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs, |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 1511 | Protocols, |
| 1512 | T->isKindOfTypeAsWritten()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1513 | } |
| 1514 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1515 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1516 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1517 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1518 | if (!ToPointeeTypeOrErr) |
| 1519 | return ToPointeeTypeOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1520 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1521 | return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1522 | } |
| 1523 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 1524 | //---------------------------------------------------------------------------- |
| 1525 | // Import Declarations |
| 1526 | //---------------------------------------------------------------------------- |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1527 | Error ASTNodeImporter::ImportDeclParts( |
| 1528 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, |
| 1529 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) { |
Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1530 | // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop. |
| 1531 | // example: int struct_in_proto(struct data_t{int a;int b;} *d); |
| 1532 | DeclContext *OrigDC = D->getDeclContext(); |
| 1533 | FunctionDecl *FunDecl; |
| 1534 | if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) && |
| 1535 | FunDecl->hasBody()) { |
Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1536 | auto getLeafPointeeType = [](const Type *T) { |
| 1537 | while (T->isPointerType() || T->isArrayType()) { |
| 1538 | T = T->getPointeeOrArrayElementType(); |
| 1539 | } |
| 1540 | return T; |
| 1541 | }; |
| 1542 | for (const ParmVarDecl *P : FunDecl->parameters()) { |
| 1543 | const Type *LeafT = |
| 1544 | getLeafPointeeType(P->getType().getCanonicalType().getTypePtr()); |
| 1545 | auto *RT = dyn_cast<RecordType>(LeafT); |
| 1546 | if (RT && RT->getDecl() == D) { |
| 1547 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 1548 | << D->getDeclKindName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1549 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1550 | } |
Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1551 | } |
| 1552 | } |
| 1553 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1554 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1555 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 1556 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1557 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1558 | // Import the name of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1559 | if (Error Err = importInto(Name, D->getDeclName())) |
| 1560 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1561 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1562 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1563 | if (Error Err = importInto(Loc, D->getLocation())) |
| 1564 | return Err; |
| 1565 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1566 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); |
Gabor Marton | be77a98 | 2018-12-12 11:22:55 +0000 | [diff] [blame] | 1567 | if (ToD) |
| 1568 | if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD)) |
| 1569 | return Err; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1570 | |
| 1571 | return Error::success(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1572 | } |
| 1573 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1574 | Error ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1575 | if (!FromD) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1576 | return Error::success(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1577 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1578 | if (!ToD) |
| 1579 | if (Error Err = importInto(ToD, FromD)) |
| 1580 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1581 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1582 | if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) { |
| 1583 | if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) { |
| 1584 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && |
| 1585 | !ToRecord->getDefinition()) { |
| 1586 | if (Error Err = ImportDefinition(FromRecord, ToRecord)) |
| 1587 | return Err; |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1588 | } |
| 1589 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1590 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1591 | } |
| 1592 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1593 | if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) { |
| 1594 | if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1595 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1596 | if (Error Err = ImportDefinition(FromEnum, ToEnum)) |
| 1597 | return Err; |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1598 | } |
| 1599 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1600 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1601 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1602 | |
| 1603 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1604 | } |
| 1605 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1606 | Error |
| 1607 | ASTNodeImporter::ImportDeclarationNameLoc( |
| 1608 | const DeclarationNameInfo &From, DeclarationNameInfo& To) { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1609 | // NOTE: To.Name and To.Loc are already imported. |
| 1610 | // We only have to import To.LocInfo. |
| 1611 | switch (To.getName().getNameKind()) { |
| 1612 | case DeclarationName::Identifier: |
| 1613 | case DeclarationName::ObjCZeroArgSelector: |
| 1614 | case DeclarationName::ObjCOneArgSelector: |
| 1615 | case DeclarationName::ObjCMultiArgSelector: |
| 1616 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1617 | case DeclarationName::CXXDeductionGuideName: |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1618 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1619 | |
| 1620 | case DeclarationName::CXXOperatorName: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1621 | if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange())) |
| 1622 | To.setCXXOperatorNameRange(*ToRangeOrErr); |
| 1623 | else |
| 1624 | return ToRangeOrErr.takeError(); |
| 1625 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1626 | } |
| 1627 | case DeclarationName::CXXLiteralOperatorName: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1628 | if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc())) |
| 1629 | To.setCXXLiteralOperatorNameLoc(*LocOrErr); |
| 1630 | else |
| 1631 | return LocOrErr.takeError(); |
| 1632 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1633 | } |
| 1634 | case DeclarationName::CXXConstructorName: |
| 1635 | case DeclarationName::CXXDestructorName: |
| 1636 | case DeclarationName::CXXConversionFunctionName: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1637 | if (auto ToTInfoOrErr = import(From.getNamedTypeInfo())) |
| 1638 | To.setNamedTypeInfo(*ToTInfoOrErr); |
| 1639 | else |
| 1640 | return ToTInfoOrErr.takeError(); |
| 1641 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1642 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1643 | } |
Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 1644 | llvm_unreachable("Unknown name kind."); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1645 | } |
| 1646 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1647 | Error |
| 1648 | ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1649 | if (Importer.isMinimalImport() && !ForceImport) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1650 | auto ToDCOrErr = Importer.ImportContext(FromDC); |
| 1651 | return ToDCOrErr.takeError(); |
| 1652 | } |
Davide Italiano | 93a64ef | 2018-10-30 20:46:29 +0000 | [diff] [blame] | 1653 | llvm::SmallVector<Decl *, 8> ImportedDecls; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1654 | for (auto *From : FromDC->decls()) { |
| 1655 | ExpectedDecl ImportedOrErr = import(From); |
Davide Italiano | 93a64ef | 2018-10-30 20:46:29 +0000 | [diff] [blame] | 1656 | if (!ImportedOrErr) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1657 | // Ignore the error, continue with next Decl. |
| 1658 | // FIXME: Handle this case somehow better. |
Davide Italiano | 93a64ef | 2018-10-30 20:46:29 +0000 | [diff] [blame] | 1659 | consumeError(ImportedOrErr.takeError()); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1660 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1661 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1662 | return Error::success(); |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 1663 | } |
| 1664 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1665 | Error ASTNodeImporter::ImportDeclContext( |
| 1666 | Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) { |
| 1667 | auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext()); |
| 1668 | if (!ToDCOrErr) |
| 1669 | return ToDCOrErr.takeError(); |
| 1670 | ToDC = *ToDCOrErr; |
| 1671 | |
| 1672 | if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) { |
| 1673 | auto ToLexicalDCOrErr = Importer.ImportContext( |
| 1674 | FromD->getLexicalDeclContext()); |
| 1675 | if (!ToLexicalDCOrErr) |
| 1676 | return ToLexicalDCOrErr.takeError(); |
| 1677 | ToLexicalDC = *ToLexicalDCOrErr; |
| 1678 | } else |
| 1679 | ToLexicalDC = ToDC; |
| 1680 | |
| 1681 | return Error::success(); |
| 1682 | } |
| 1683 | |
| 1684 | Error ASTNodeImporter::ImportImplicitMethods( |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1685 | const CXXRecordDecl *From, CXXRecordDecl *To) { |
| 1686 | assert(From->isCompleteDefinition() && To->getDefinition() == To && |
| 1687 | "Import implicit methods to or from non-definition"); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1688 | |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1689 | for (CXXMethodDecl *FromM : From->methods()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1690 | if (FromM->isImplicit()) { |
| 1691 | Expected<CXXMethodDecl *> ToMOrErr = import(FromM); |
| 1692 | if (!ToMOrErr) |
| 1693 | return ToMOrErr.takeError(); |
| 1694 | } |
| 1695 | |
| 1696 | return Error::success(); |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1697 | } |
| 1698 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1699 | static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, |
| 1700 | ASTImporter &Importer) { |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1701 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1702 | Decl *ToTypedef = Importer.Import(FromTypedef); |
| 1703 | if (!ToTypedef) |
| 1704 | return make_error<ImportError>(); |
| 1705 | To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(ToTypedef)); |
| 1706 | // FIXME: This should be the final code. |
| 1707 | //if (Expected<Decl *> ToTypedefOrErr = Importer.Import(FromTypedef)) |
| 1708 | // To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr)); |
| 1709 | //else |
| 1710 | // return ToTypedefOrErr.takeError(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1711 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1712 | return Error::success(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1713 | } |
| 1714 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1715 | Error ASTNodeImporter::ImportDefinition( |
| 1716 | RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1717 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1718 | if (Kind == IDK_Everything) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1719 | return ImportDeclContext(From, /*ForceImport=*/true); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1720 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1721 | return Error::success(); |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1722 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1723 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1724 | To->startDefinition(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1725 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1726 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 1727 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1728 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1729 | // Add base classes. |
Gabor Marton | 17d3967 | 2018-11-26 15:54:08 +0000 | [diff] [blame] | 1730 | auto *ToCXX = dyn_cast<CXXRecordDecl>(To); |
| 1731 | auto *FromCXX = dyn_cast<CXXRecordDecl>(From); |
| 1732 | if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) { |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1733 | |
| 1734 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); |
| 1735 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); |
| 1736 | ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1737 | ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1738 | ToData.Aggregate = FromData.Aggregate; |
| 1739 | ToData.PlainOldData = FromData.PlainOldData; |
| 1740 | ToData.Empty = FromData.Empty; |
| 1741 | ToData.Polymorphic = FromData.Polymorphic; |
| 1742 | ToData.Abstract = FromData.Abstract; |
| 1743 | ToData.IsStandardLayout = FromData.IsStandardLayout; |
Richard Smith | b6070db | 2018-04-05 18:55:37 +0000 | [diff] [blame] | 1744 | ToData.IsCXX11StandardLayout = FromData.IsCXX11StandardLayout; |
| 1745 | ToData.HasBasesWithFields = FromData.HasBasesWithFields; |
| 1746 | ToData.HasBasesWithNonStaticDataMembers = |
| 1747 | FromData.HasBasesWithNonStaticDataMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1748 | ToData.HasPrivateFields = FromData.HasPrivateFields; |
| 1749 | ToData.HasProtectedFields = FromData.HasProtectedFields; |
| 1750 | ToData.HasPublicFields = FromData.HasPublicFields; |
| 1751 | ToData.HasMutableFields = FromData.HasMutableFields; |
Richard Smith | ab44d5b | 2013-12-10 08:25:00 +0000 | [diff] [blame] | 1752 | ToData.HasVariantMembers = FromData.HasVariantMembers; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1753 | ToData.HasOnlyCMembers = FromData.HasOnlyCMembers; |
Richard Smith | e2648ba | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 1754 | ToData.HasInClassInitializer = FromData.HasInClassInitializer; |
Richard Smith | 593f993 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 1755 | ToData.HasUninitializedReferenceMember |
| 1756 | = FromData.HasUninitializedReferenceMember; |
Nico Weber | 6a6376b | 2016-02-19 01:52:46 +0000 | [diff] [blame] | 1757 | ToData.HasUninitializedFields = FromData.HasUninitializedFields; |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 1758 | ToData.HasInheritedConstructor = FromData.HasInheritedConstructor; |
| 1759 | ToData.HasInheritedAssignment = FromData.HasInheritedAssignment; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1760 | ToData.NeedOverloadResolutionForCopyConstructor |
| 1761 | = FromData.NeedOverloadResolutionForCopyConstructor; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1762 | ToData.NeedOverloadResolutionForMoveConstructor |
| 1763 | = FromData.NeedOverloadResolutionForMoveConstructor; |
| 1764 | ToData.NeedOverloadResolutionForMoveAssignment |
| 1765 | = FromData.NeedOverloadResolutionForMoveAssignment; |
| 1766 | ToData.NeedOverloadResolutionForDestructor |
| 1767 | = FromData.NeedOverloadResolutionForDestructor; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1768 | ToData.DefaultedCopyConstructorIsDeleted |
| 1769 | = FromData.DefaultedCopyConstructorIsDeleted; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1770 | ToData.DefaultedMoveConstructorIsDeleted |
| 1771 | = FromData.DefaultedMoveConstructorIsDeleted; |
| 1772 | ToData.DefaultedMoveAssignmentIsDeleted |
| 1773 | = FromData.DefaultedMoveAssignmentIsDeleted; |
| 1774 | ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1775 | ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers; |
| 1776 | ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1777 | ToData.HasConstexprNonCopyMoveConstructor |
| 1778 | = FromData.HasConstexprNonCopyMoveConstructor; |
Nico Weber | 72c57f4 | 2016-02-24 20:58:14 +0000 | [diff] [blame] | 1779 | ToData.HasDefaultedDefaultConstructor |
| 1780 | = FromData.HasDefaultedDefaultConstructor; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1781 | ToData.DefaultedDefaultConstructorIsConstexpr |
| 1782 | = FromData.DefaultedDefaultConstructorIsConstexpr; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1783 | ToData.HasConstexprDefaultConstructor |
| 1784 | = FromData.HasConstexprDefaultConstructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1785 | ToData.HasNonLiteralTypeFieldsOrBases |
| 1786 | = FromData.HasNonLiteralTypeFieldsOrBases; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1787 | // ComputedVisibleConversions not imported. |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1788 | ToData.UserProvidedDefaultConstructor |
| 1789 | = FromData.UserProvidedDefaultConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1790 | ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers; |
Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 1791 | ToData.ImplicitCopyConstructorCanHaveConstParamForVBase |
| 1792 | = FromData.ImplicitCopyConstructorCanHaveConstParamForVBase; |
| 1793 | ToData.ImplicitCopyConstructorCanHaveConstParamForNonVBase |
| 1794 | = FromData.ImplicitCopyConstructorCanHaveConstParamForNonVBase; |
Richard Smith | 1c33fe8 | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 1795 | ToData.ImplicitCopyAssignmentHasConstParam |
| 1796 | = FromData.ImplicitCopyAssignmentHasConstParam; |
| 1797 | ToData.HasDeclaredCopyConstructorWithConstParam |
| 1798 | = FromData.HasDeclaredCopyConstructorWithConstParam; |
| 1799 | ToData.HasDeclaredCopyAssignmentWithConstParam |
| 1800 | = FromData.HasDeclaredCopyAssignmentWithConstParam; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1801 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1802 | SmallVector<CXXBaseSpecifier *, 4> Bases; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1803 | for (const auto &Base1 : FromCXX->bases()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1804 | ExpectedType TyOrErr = import(Base1.getType()); |
| 1805 | if (!TyOrErr) |
| 1806 | return TyOrErr.takeError(); |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1807 | |
| 1808 | SourceLocation EllipsisLoc; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1809 | if (Base1.isPackExpansion()) { |
| 1810 | if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc())) |
| 1811 | EllipsisLoc = *LocOrErr; |
| 1812 | else |
| 1813 | return LocOrErr.takeError(); |
| 1814 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1815 | |
| 1816 | // Ensure that we have a definition for the base. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1817 | if (Error Err = |
| 1818 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl())) |
| 1819 | return Err; |
| 1820 | |
| 1821 | auto RangeOrErr = import(Base1.getSourceRange()); |
| 1822 | if (!RangeOrErr) |
| 1823 | return RangeOrErr.takeError(); |
| 1824 | |
| 1825 | auto TSIOrErr = import(Base1.getTypeSourceInfo()); |
| 1826 | if (!TSIOrErr) |
| 1827 | return TSIOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1828 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1829 | Bases.push_back( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1830 | new (Importer.getToContext()) CXXBaseSpecifier( |
| 1831 | *RangeOrErr, |
| 1832 | Base1.isVirtual(), |
| 1833 | Base1.isBaseOfClass(), |
| 1834 | Base1.getAccessSpecifierAsWritten(), |
| 1835 | *TSIOrErr, |
| 1836 | EllipsisLoc)); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1837 | } |
| 1838 | if (!Bases.empty()) |
Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1839 | ToCXX->setBases(Bases.data(), Bases.size()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1840 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1841 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1842 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1843 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 1844 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1845 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1846 | To->completeDefinition(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1847 | return Error::success(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1848 | } |
| 1849 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1850 | Error ASTNodeImporter::ImportInitializer(VarDecl *From, VarDecl *To) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1851 | if (To->getAnyInitializer()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1852 | return Error::success(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1853 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1854 | Expr *FromInit = From->getInit(); |
| 1855 | if (!FromInit) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1856 | return Error::success(); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1857 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1858 | ExpectedExpr ToInitOrErr = import(FromInit); |
| 1859 | if (!ToInitOrErr) |
| 1860 | return ToInitOrErr.takeError(); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1861 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1862 | To->setInit(*ToInitOrErr); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1863 | if (From->isInitKnownICE()) { |
| 1864 | EvaluatedStmt *Eval = To->ensureEvaluatedStmt(); |
| 1865 | Eval->CheckedICE = true; |
| 1866 | Eval->IsICE = From->isInitICE(); |
| 1867 | } |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1868 | |
| 1869 | // FIXME: Other bits to merge? |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1870 | return Error::success(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1871 | } |
| 1872 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1873 | Error ASTNodeImporter::ImportDefinition( |
| 1874 | EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1875 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1876 | if (Kind == IDK_Everything) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1877 | return ImportDeclContext(From, /*ForceImport=*/true); |
| 1878 | return Error::success(); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1879 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1880 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1881 | To->startDefinition(); |
| 1882 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1883 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 1884 | return Err; |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1885 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1886 | ExpectedType ToTypeOrErr = |
| 1887 | import(Importer.getFromContext().getTypeDeclType(From)); |
| 1888 | if (!ToTypeOrErr) |
| 1889 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1890 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1891 | ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType()); |
| 1892 | if (!ToPromotionTypeOrErr) |
| 1893 | return ToPromotionTypeOrErr.takeError(); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1894 | |
| 1895 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1896 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 1897 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1898 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1899 | // FIXME: we might need to merge the number of positive or negative bits |
| 1900 | // if the enumerator lists don't match. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1901 | To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr, |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1902 | From->getNumPositiveBits(), |
| 1903 | From->getNumNegativeBits()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1904 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1905 | } |
| 1906 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1907 | // FIXME: Remove this, use `import` instead. |
| 1908 | Expected<TemplateParameterList *> ASTNodeImporter::ImportTemplateParameterList( |
| 1909 | TemplateParameterList *Params) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1910 | SmallVector<NamedDecl *, 4> ToParams(Params->size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1911 | if (Error Err = ImportContainerChecked(*Params, ToParams)) |
| 1912 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1913 | |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1914 | Expr *ToRequiresClause; |
| 1915 | if (Expr *const R = Params->getRequiresClause()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1916 | if (Error Err = importInto(ToRequiresClause, R)) |
| 1917 | return std::move(Err); |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1918 | } else { |
| 1919 | ToRequiresClause = nullptr; |
| 1920 | } |
| 1921 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1922 | auto ToTemplateLocOrErr = import(Params->getTemplateLoc()); |
| 1923 | if (!ToTemplateLocOrErr) |
| 1924 | return ToTemplateLocOrErr.takeError(); |
| 1925 | auto ToLAngleLocOrErr = import(Params->getLAngleLoc()); |
| 1926 | if (!ToLAngleLocOrErr) |
| 1927 | return ToLAngleLocOrErr.takeError(); |
| 1928 | auto ToRAngleLocOrErr = import(Params->getRAngleLoc()); |
| 1929 | if (!ToRAngleLocOrErr) |
| 1930 | return ToRAngleLocOrErr.takeError(); |
| 1931 | |
| 1932 | return TemplateParameterList::Create( |
| 1933 | Importer.getToContext(), |
| 1934 | *ToTemplateLocOrErr, |
| 1935 | *ToLAngleLocOrErr, |
| 1936 | ToParams, |
| 1937 | *ToRAngleLocOrErr, |
| 1938 | ToRequiresClause); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1939 | } |
| 1940 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1941 | Error ASTNodeImporter::ImportTemplateArguments( |
| 1942 | const TemplateArgument *FromArgs, unsigned NumFromArgs, |
| 1943 | SmallVectorImpl<TemplateArgument> &ToArgs) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1944 | for (unsigned I = 0; I != NumFromArgs; ++I) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1945 | if (auto ToOrErr = import(FromArgs[I])) |
| 1946 | ToArgs.push_back(*ToOrErr); |
| 1947 | else |
| 1948 | return ToOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1949 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1950 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1951 | return Error::success(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1952 | } |
| 1953 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1954 | // FIXME: Do not forget to remove this and use only 'import'. |
| 1955 | Expected<TemplateArgument> |
| 1956 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { |
| 1957 | return import(From); |
| 1958 | } |
| 1959 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1960 | template <typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1961 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1962 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { |
| 1963 | for (const auto &FromLoc : Container) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1964 | if (auto ToLocOrErr = import(FromLoc)) |
| 1965 | ToTAInfo.addArgument(*ToLocOrErr); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1966 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1967 | return ToLocOrErr.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1968 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1969 | return Error::success(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1970 | } |
| 1971 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1972 | static StructuralEquivalenceKind |
| 1973 | getStructuralEquivalenceKind(const ASTImporter &Importer) { |
| 1974 | return Importer.isMinimalImport() ? StructuralEquivalenceKind::Minimal |
| 1975 | : StructuralEquivalenceKind::Default; |
| 1976 | } |
| 1977 | |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1978 | bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) { |
| 1979 | StructuralEquivalenceContext Ctx( |
| 1980 | Importer.getFromContext(), Importer.getToContext(), |
| 1981 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1982 | false, Complain); |
| 1983 | return Ctx.IsEquivalent(From, To); |
| 1984 | } |
| 1985 | |
| 1986 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1987 | RecordDecl *ToRecord, bool Complain) { |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1988 | // Eliminate a potential failure point where we attempt to re-import |
| 1989 | // something we're trying to import while completing ToRecord. |
| 1990 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); |
| 1991 | if (ToOrigin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1992 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1993 | if (ToOriginRecord) |
| 1994 | ToRecord = ToOriginRecord; |
| 1995 | } |
| 1996 | |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1997 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1998 | ToRecord->getASTContext(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1999 | Importer.getNonEquivalentDecls(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2000 | getStructuralEquivalenceKind(Importer), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2001 | false, Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2002 | return Ctx.IsEquivalent(FromRecord, ToRecord); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2003 | } |
| 2004 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2005 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 2006 | bool Complain) { |
| 2007 | StructuralEquivalenceContext Ctx( |
| 2008 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2009 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2010 | false, Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2011 | return Ctx.IsEquivalent(FromVar, ToVar); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2012 | } |
| 2013 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2014 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2015 | StructuralEquivalenceContext Ctx( |
| 2016 | Importer.getFromContext(), Importer.getToContext(), |
| 2017 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2018 | return Ctx.IsEquivalent(FromEnum, ToEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2019 | } |
| 2020 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2021 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, |
| 2022 | FunctionTemplateDecl *To) { |
| 2023 | StructuralEquivalenceContext Ctx( |
| 2024 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2025 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2026 | false, false); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2027 | return Ctx.IsEquivalent(From, To); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2028 | } |
| 2029 | |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2030 | bool ASTNodeImporter::IsStructuralMatch(FunctionDecl *From, FunctionDecl *To) { |
| 2031 | StructuralEquivalenceContext Ctx( |
| 2032 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2033 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2034 | false, false); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2035 | return Ctx.IsEquivalent(From, To); |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2036 | } |
| 2037 | |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2038 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2039 | EnumConstantDecl *ToEC) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2040 | const llvm::APSInt &FromVal = FromEC->getInitVal(); |
| 2041 | const llvm::APSInt &ToVal = ToEC->getInitVal(); |
| 2042 | |
| 2043 | return FromVal.isSigned() == ToVal.isSigned() && |
| 2044 | FromVal.getBitWidth() == ToVal.getBitWidth() && |
| 2045 | FromVal == ToVal; |
| 2046 | } |
| 2047 | |
| 2048 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2049 | ClassTemplateDecl *To) { |
| 2050 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2051 | Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2052 | Importer.getNonEquivalentDecls(), |
| 2053 | getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2054 | return Ctx.IsEquivalent(From, To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2055 | } |
| 2056 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2057 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, |
| 2058 | VarTemplateDecl *To) { |
| 2059 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2060 | Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2061 | Importer.getNonEquivalentDecls(), |
| 2062 | getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2063 | return Ctx.IsEquivalent(From, To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2064 | } |
| 2065 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2066 | ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 2067 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2068 | << D->getDeclKindName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2069 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2070 | } |
| 2071 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2072 | ExpectedDecl ASTNodeImporter::VisitImportDecl(ImportDecl *D) { |
| 2073 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 2074 | << D->getDeclKindName(); |
| 2075 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| 2076 | } |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2077 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2078 | ExpectedDecl ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { |
| 2079 | // Import the context of this declaration. |
| 2080 | DeclContext *DC, *LexicalDC; |
| 2081 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 2082 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2083 | |
| 2084 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2085 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2086 | if (!LocOrErr) |
| 2087 | return LocOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2088 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2089 | EmptyDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2090 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2091 | return ToD; |
| 2092 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2093 | ToD->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2094 | LexicalDC->addDeclInternal(ToD); |
| 2095 | return ToD; |
| 2096 | } |
| 2097 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2098 | ExpectedDecl ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2099 | TranslationUnitDecl *ToD = |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2100 | Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2101 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2102 | Importer.MapImported(D, ToD); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2103 | |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2104 | return ToD; |
| 2105 | } |
| 2106 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2107 | ExpectedDecl ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
| 2108 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2109 | if (!LocOrErr) |
| 2110 | return LocOrErr.takeError(); |
| 2111 | auto ColonLocOrErr = import(D->getColonLoc()); |
| 2112 | if (!ColonLocOrErr) |
| 2113 | return ColonLocOrErr.takeError(); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2114 | |
| 2115 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2116 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2117 | if (!DCOrErr) |
| 2118 | return DCOrErr.takeError(); |
| 2119 | DeclContext *DC = *DCOrErr; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2120 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2121 | AccessSpecDecl *ToD; |
| 2122 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2123 | DC, *LocOrErr, *ColonLocOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2124 | return ToD; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2125 | |
| 2126 | // Lexical DeclContext and Semantic DeclContext |
| 2127 | // is always the same for the accessSpec. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2128 | ToD->setLexicalDeclContext(DC); |
| 2129 | DC->addDeclInternal(ToD); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2130 | |
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 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2134 | ExpectedDecl ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 2135 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2136 | if (!DCOrErr) |
| 2137 | return DCOrErr.takeError(); |
| 2138 | DeclContext *DC = *DCOrErr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2139 | DeclContext *LexicalDC = DC; |
| 2140 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2141 | SourceLocation ToLocation, ToRParenLoc; |
| 2142 | Expr *ToAssertExpr; |
| 2143 | StringLiteral *ToMessage; |
| 2144 | if (auto Imp = importSeq( |
| 2145 | D->getLocation(), D->getAssertExpr(), D->getMessage(), D->getRParenLoc())) |
| 2146 | std::tie(ToLocation, ToAssertExpr, ToMessage, ToRParenLoc) = *Imp; |
| 2147 | else |
| 2148 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2149 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2150 | StaticAssertDecl *ToD; |
| 2151 | if (GetImportedOrCreateDecl( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2152 | ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage, |
| 2153 | ToRParenLoc, D->isFailed())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2154 | return ToD; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2155 | |
| 2156 | ToD->setLexicalDeclContext(LexicalDC); |
| 2157 | LexicalDC->addDeclInternal(ToD); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2158 | return ToD; |
| 2159 | } |
| 2160 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2161 | ExpectedDecl ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2162 | // Import the major distinguishing characteristics of this namespace. |
| 2163 | DeclContext *DC, *LexicalDC; |
| 2164 | DeclarationName Name; |
| 2165 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2166 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2167 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2168 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2169 | if (ToD) |
| 2170 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2171 | |
| 2172 | NamespaceDecl *MergeWithNamespace = nullptr; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2173 | if (!Name) { |
| 2174 | // This is an anonymous namespace. Adopt an existing anonymous |
| 2175 | // namespace if we can. |
| 2176 | // FIXME: Not testable. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2177 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2178 | MergeWithNamespace = TU->getAnonymousNamespace(); |
| 2179 | else |
| 2180 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); |
| 2181 | } else { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2182 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2183 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2184 | for (auto *FoundDecl : FoundDecls) { |
| 2185 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2186 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2187 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2188 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2189 | MergeWithNamespace = FoundNS; |
| 2190 | ConflictingDecls.clear(); |
| 2191 | break; |
| 2192 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2193 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2194 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2195 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2196 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2197 | if (!ConflictingDecls.empty()) { |
John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 2198 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2199 | ConflictingDecls.data(), |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2200 | ConflictingDecls.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2201 | if (!Name) |
| 2202 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2203 | } |
| 2204 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2205 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2206 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2207 | if (!BeginLocOrErr) |
| 2208 | return BeginLocOrErr.takeError(); |
| 2209 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2210 | // Create the "to" namespace, if needed. |
| 2211 | NamespaceDecl *ToNamespace = MergeWithNamespace; |
| 2212 | if (!ToNamespace) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2213 | if (GetImportedOrCreateDecl( |
| 2214 | ToNamespace, D, Importer.getToContext(), DC, D->isInline(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2215 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2216 | /*PrevDecl=*/nullptr)) |
| 2217 | return ToNamespace; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2218 | ToNamespace->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2219 | LexicalDC->addDeclInternal(ToNamespace); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2220 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2221 | // If this is an anonymous namespace, register it as the anonymous |
| 2222 | // namespace within its context. |
| 2223 | if (!Name) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2224 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2225 | TU->setAnonymousNamespace(ToNamespace); |
| 2226 | else |
| 2227 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); |
| 2228 | } |
| 2229 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2230 | Importer.MapImported(D, ToNamespace); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2231 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2232 | if (Error Err = ImportDeclContext(D)) |
| 2233 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2234 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2235 | return ToNamespace; |
| 2236 | } |
| 2237 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2238 | ExpectedDecl ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2239 | // Import the major distinguishing characteristics of this namespace. |
| 2240 | DeclContext *DC, *LexicalDC; |
| 2241 | DeclarationName Name; |
| 2242 | SourceLocation Loc; |
| 2243 | NamedDecl *LookupD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2244 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) |
| 2245 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2246 | if (LookupD) |
| 2247 | return LookupD; |
| 2248 | |
| 2249 | // NOTE: No conflict resolution is done for namespace aliases now. |
| 2250 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2251 | SourceLocation ToNamespaceLoc, ToAliasLoc, ToTargetNameLoc; |
| 2252 | NestedNameSpecifierLoc ToQualifierLoc; |
| 2253 | NamespaceDecl *ToNamespace; |
| 2254 | if (auto Imp = importSeq( |
| 2255 | D->getNamespaceLoc(), D->getAliasLoc(), D->getQualifierLoc(), |
| 2256 | D->getTargetNameLoc(), D->getNamespace())) |
| 2257 | std::tie( |
| 2258 | ToNamespaceLoc, ToAliasLoc, ToQualifierLoc, ToTargetNameLoc, |
| 2259 | ToNamespace) = *Imp; |
| 2260 | else |
| 2261 | return Imp.takeError(); |
| 2262 | IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier()); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2263 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2264 | NamespaceAliasDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2265 | if (GetImportedOrCreateDecl( |
| 2266 | ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc, |
| 2267 | ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2268 | return ToD; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2269 | |
| 2270 | ToD->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2271 | LexicalDC->addDeclInternal(ToD); |
| 2272 | |
| 2273 | return ToD; |
| 2274 | } |
| 2275 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2276 | ExpectedDecl |
| 2277 | ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2278 | // Import the major distinguishing characteristics of this typedef. |
| 2279 | DeclContext *DC, *LexicalDC; |
| 2280 | DeclarationName Name; |
| 2281 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2282 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2283 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2284 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2285 | if (ToD) |
| 2286 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2287 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2288 | // If this typedef is not in block scope, determine whether we've |
| 2289 | // seen a typedef with the same name (that we can merge with) or any |
| 2290 | // other entity by that name (which name lookup could conflict with). |
| 2291 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2292 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2293 | unsigned IDNS = Decl::IDNS_Ordinary; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2294 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2295 | for (auto *FoundDecl : FoundDecls) { |
| 2296 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2297 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2298 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2299 | QualType FromUT = D->getUnderlyingType(); |
| 2300 | QualType FoundUT = FoundTypedef->getUnderlyingType(); |
| 2301 | if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) { |
| 2302 | // If the "From" context has a complete underlying type but we |
| 2303 | // already have a complete underlying type then return with that. |
| 2304 | if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2305 | return Importer.MapImported(D, FoundTypedef); |
Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2306 | } |
| 2307 | // FIXME Handle redecl chain. |
| 2308 | break; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2309 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2310 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2311 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2312 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2313 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2314 | if (!ConflictingDecls.empty()) { |
| 2315 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2316 | ConflictingDecls.data(), |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2317 | ConflictingDecls.size()); |
| 2318 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2319 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2320 | } |
| 2321 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2322 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2323 | QualType ToUnderlyingType; |
| 2324 | TypeSourceInfo *ToTypeSourceInfo; |
| 2325 | SourceLocation ToBeginLoc; |
| 2326 | if (auto Imp = importSeq( |
| 2327 | D->getUnderlyingType(), D->getTypeSourceInfo(), D->getBeginLoc())) |
| 2328 | std::tie(ToUnderlyingType, ToTypeSourceInfo, ToBeginLoc) = *Imp; |
| 2329 | else |
| 2330 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2331 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2332 | // Create the new typedef node. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2333 | // FIXME: ToUnderlyingType is not used. |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2334 | TypedefNameDecl *ToTypedef; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2335 | if (IsAlias) { |
| 2336 | if (GetImportedOrCreateDecl<TypeAliasDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2337 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2338 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2339 | return ToTypedef; |
| 2340 | } else if (GetImportedOrCreateDecl<TypedefDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2341 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2342 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2343 | return ToTypedef; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2344 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2345 | ToTypedef->setAccess(D->getAccess()); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2346 | ToTypedef->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2347 | |
| 2348 | // Templated declarations should not appear in DeclContext. |
| 2349 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; |
| 2350 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) |
| 2351 | LexicalDC->addDeclInternal(ToTypedef); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2352 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2353 | return ToTypedef; |
| 2354 | } |
| 2355 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2356 | ExpectedDecl ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2357 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); |
| 2358 | } |
| 2359 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2360 | ExpectedDecl ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2361 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); |
| 2362 | } |
| 2363 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2364 | ExpectedDecl |
| 2365 | ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2366 | // Import the major distinguishing characteristics of this typedef. |
| 2367 | DeclContext *DC, *LexicalDC; |
| 2368 | DeclarationName Name; |
| 2369 | SourceLocation Loc; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2370 | NamedDecl *FoundD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2371 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) |
| 2372 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2373 | if (FoundD) |
| 2374 | return FoundD; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2375 | |
| 2376 | // If this typedef is not in block scope, determine whether we've |
| 2377 | // seen a typedef with the same name (that we can merge with) or any |
| 2378 | // other entity by that name (which name lookup could conflict with). |
| 2379 | if (!DC->isFunctionOrMethod()) { |
| 2380 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 2381 | unsigned IDNS = Decl::IDNS_Ordinary; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2382 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2383 | for (auto *FoundDecl : FoundDecls) { |
| 2384 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2385 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2386 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2387 | return Importer.MapImported(D, FoundAlias); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2388 | ConflictingDecls.push_back(FoundDecl); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2389 | } |
| 2390 | |
| 2391 | if (!ConflictingDecls.empty()) { |
| 2392 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2393 | ConflictingDecls.data(), |
| 2394 | ConflictingDecls.size()); |
| 2395 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2396 | return make_error<ImportError>(ImportError::NameConflict); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2397 | } |
| 2398 | } |
| 2399 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2400 | TemplateParameterList *ToTemplateParameters; |
| 2401 | TypeAliasDecl *ToTemplatedDecl; |
| 2402 | if (auto Imp = importSeq(D->getTemplateParameters(), D->getTemplatedDecl())) |
| 2403 | std::tie(ToTemplateParameters, ToTemplatedDecl) = *Imp; |
| 2404 | else |
| 2405 | return Imp.takeError(); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2406 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2407 | TypeAliasTemplateDecl *ToAlias; |
| 2408 | if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2409 | Name, ToTemplateParameters, ToTemplatedDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2410 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2411 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2412 | ToTemplatedDecl->setDescribedAliasTemplate(ToAlias); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2413 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2414 | ToAlias->setAccess(D->getAccess()); |
| 2415 | ToAlias->setLexicalDeclContext(LexicalDC); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2416 | LexicalDC->addDeclInternal(ToAlias); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2417 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2418 | } |
| 2419 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2420 | ExpectedDecl ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2421 | // Import the major distinguishing characteristics of this label. |
| 2422 | DeclContext *DC, *LexicalDC; |
| 2423 | DeclarationName Name; |
| 2424 | SourceLocation Loc; |
| 2425 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2426 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2427 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2428 | if (ToD) |
| 2429 | return ToD; |
| 2430 | |
| 2431 | assert(LexicalDC->isFunctionOrMethod()); |
| 2432 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2433 | LabelDecl *ToLabel; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2434 | if (D->isGnuLocal()) { |
| 2435 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2436 | if (!BeginLocOrErr) |
| 2437 | return BeginLocOrErr.takeError(); |
| 2438 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2439 | Name.getAsIdentifierInfo(), *BeginLocOrErr)) |
| 2440 | return ToLabel; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2441 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2442 | } else { |
| 2443 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2444 | Name.getAsIdentifierInfo())) |
| 2445 | return ToLabel; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2446 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2447 | } |
| 2448 | |
| 2449 | Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt()); |
| 2450 | if (!ToStmtOrErr) |
| 2451 | return ToStmtOrErr.takeError(); |
| 2452 | |
| 2453 | ToLabel->setStmt(*ToStmtOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2454 | ToLabel->setLexicalDeclContext(LexicalDC); |
| 2455 | LexicalDC->addDeclInternal(ToLabel); |
| 2456 | return ToLabel; |
| 2457 | } |
| 2458 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2459 | ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2460 | // Import the major distinguishing characteristics of this enum. |
| 2461 | DeclContext *DC, *LexicalDC; |
| 2462 | DeclarationName Name; |
| 2463 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2464 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2465 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2466 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2467 | if (ToD) |
| 2468 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2469 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2470 | // Figure out what enum name we're looking for. |
| 2471 | unsigned IDNS = Decl::IDNS_Tag; |
| 2472 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2473 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2474 | if (Error Err = importInto( |
| 2475 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2476 | return std::move(Err); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2477 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2478 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2479 | IDNS |= Decl::IDNS_Ordinary; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2480 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2481 | // We may already have an enum of the same name; try to find and match it. |
| 2482 | if (!DC->isFunctionOrMethod() && SearchName) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2483 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2484 | auto FoundDecls = |
| 2485 | Importer.findDeclsInToCtx(DC, SearchName); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2486 | for (auto *FoundDecl : FoundDecls) { |
| 2487 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2488 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2489 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2490 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2491 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2492 | FoundDecl = Tag->getDecl(); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2493 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2494 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2495 | if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) { |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2496 | if (IsStructuralMatch(D, FoundEnum)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2497 | return Importer.MapImported(D, FoundEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2498 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2499 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2500 | ConflictingDecls.push_back(FoundDecl); |
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 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2503 | if (!ConflictingDecls.empty()) { |
| 2504 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2505 | ConflictingDecls.data(), |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2506 | ConflictingDecls.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2507 | if (!Name) |
| 2508 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2509 | } |
| 2510 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2511 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2512 | SourceLocation ToBeginLoc; |
| 2513 | NestedNameSpecifierLoc ToQualifierLoc; |
| 2514 | QualType ToIntegerType; |
| 2515 | if (auto Imp = importSeq( |
| 2516 | D->getBeginLoc(), D->getQualifierLoc(), D->getIntegerType())) |
| 2517 | std::tie(ToBeginLoc, ToQualifierLoc, ToIntegerType) = *Imp; |
| 2518 | else |
| 2519 | return Imp.takeError(); |
| 2520 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2521 | // Create the enum declaration. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2522 | EnumDecl *D2; |
| 2523 | if (GetImportedOrCreateDecl( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2524 | D2, D, Importer.getToContext(), DC, ToBeginLoc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2525 | Loc, Name.getAsIdentifierInfo(), nullptr, D->isScoped(), |
| 2526 | D->isScopedUsingClassTag(), D->isFixed())) |
| 2527 | return D2; |
| 2528 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2529 | D2->setQualifierInfo(ToQualifierLoc); |
| 2530 | D2->setIntegerType(ToIntegerType); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2531 | D2->setAccess(D->getAccess()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2532 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2533 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2534 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2535 | // Import the definition |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2536 | if (D->isCompleteDefinition()) |
| 2537 | if (Error Err = ImportDefinition(D, D2)) |
| 2538 | return std::move(Err); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2539 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2540 | return D2; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2541 | } |
| 2542 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2543 | ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2544 | bool IsFriendTemplate = false; |
| 2545 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2546 | IsFriendTemplate = |
| 2547 | DCXX->getDescribedClassTemplate() && |
| 2548 | DCXX->getDescribedClassTemplate()->getFriendObjectKind() != |
| 2549 | Decl::FOK_None; |
| 2550 | } |
| 2551 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2552 | // If this record has a definition in the translation unit we're coming from, |
| 2553 | // but this particular declaration is not that definition, import the |
| 2554 | // definition and map to that. |
Douglas Gregor | 0a5a221 | 2010-02-11 01:04:33 +0000 | [diff] [blame] | 2555 | TagDecl *Definition = D->getDefinition(); |
Gabor Marton | a3af567 | 2018-05-23 14:24:02 +0000 | [diff] [blame] | 2556 | if (Definition && Definition != D && |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2557 | // Friend template declaration must be imported on its own. |
| 2558 | !IsFriendTemplate && |
Gabor Marton | a3af567 | 2018-05-23 14:24:02 +0000 | [diff] [blame] | 2559 | // In contrast to a normal CXXRecordDecl, the implicit |
| 2560 | // CXXRecordDecl of ClassTemplateSpecializationDecl is its redeclaration. |
| 2561 | // The definition of the implicit CXXRecordDecl in this case is the |
| 2562 | // ClassTemplateSpecializationDecl itself. Thus, we start with an extra |
| 2563 | // condition in order to be able to import the implict Decl. |
| 2564 | !D->isImplicit()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2565 | ExpectedDecl ImportedDefOrErr = import(Definition); |
| 2566 | if (!ImportedDefOrErr) |
| 2567 | return ImportedDefOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2568 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2569 | return Importer.MapImported(D, *ImportedDefOrErr); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2570 | } |
Gabor Marton | a3af567 | 2018-05-23 14:24:02 +0000 | [diff] [blame] | 2571 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2572 | // Import the major distinguishing characteristics of this record. |
| 2573 | DeclContext *DC, *LexicalDC; |
| 2574 | DeclarationName Name; |
| 2575 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2576 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2577 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2578 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2579 | if (ToD) |
| 2580 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2581 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2582 | // Figure out what structure name we're looking for. |
| 2583 | unsigned IDNS = Decl::IDNS_Tag; |
| 2584 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2585 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2586 | if (Error Err = importInto( |
| 2587 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2588 | return std::move(Err); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2589 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2590 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2591 | IDNS |= Decl::IDNS_Ordinary | Decl::IDNS_TagFriend; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2592 | |
| 2593 | // We may already have a record of the same name; try to find and match it. |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2594 | RecordDecl *PrevDecl = nullptr; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2595 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2596 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2597 | auto FoundDecls = |
| 2598 | Importer.findDeclsInToCtx(DC, SearchName); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2599 | if (!FoundDecls.empty()) { |
| 2600 | // We're going to have to compare D against potentially conflicting Decls, so complete it. |
| 2601 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) |
| 2602 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 2603 | } |
| 2604 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2605 | for (auto *FoundDecl : FoundDecls) { |
| 2606 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2607 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2608 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2609 | Decl *Found = FoundDecl; |
| 2610 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 2611 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2612 | Found = Tag->getDecl(); |
| 2613 | } |
Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2614 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2615 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2616 | // Do not emit false positive diagnostic in case of unnamed |
| 2617 | // struct/union and in case of anonymous structs. Would be false |
| 2618 | // because there may be several anonymous/unnamed structs in a class. |
| 2619 | // E.g. these are both valid: |
| 2620 | // struct A { // unnamed structs |
| 2621 | // struct { struct A *next; } entry0; |
| 2622 | // struct { struct A *next; } entry1; |
| 2623 | // }; |
| 2624 | // struct X { struct { int a; }; struct { int b; }; }; // anon structs |
| 2625 | if (!SearchName) |
Gabor Marton | 0bebf95 | 2018-07-05 09:51:13 +0000 | [diff] [blame] | 2626 | if (!IsStructuralMatch(D, FoundRecord, false)) |
| 2627 | continue; |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2628 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2629 | if (IsStructuralMatch(D, FoundRecord)) { |
| 2630 | RecordDecl *FoundDef = FoundRecord->getDefinition(); |
| 2631 | if (D->isThisDeclarationADefinition() && FoundDef) { |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2632 | // FIXME: Structural equivalence check should check for same |
| 2633 | // user-defined methods. |
| 2634 | Importer.MapImported(D, FoundDef); |
| 2635 | if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2636 | auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef); |
| 2637 | assert(FoundCXX && "Record type mismatch"); |
| 2638 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2639 | if (!Importer.isMinimalImport()) |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2640 | // FoundDef may not have every implicit method that D has |
| 2641 | // because implicit methods are created only if they are used. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2642 | if (Error Err = ImportImplicitMethods(DCXX, FoundCXX)) |
| 2643 | return std::move(Err); |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2644 | } |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2645 | } |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2646 | PrevDecl = FoundRecord->getMostRecentDecl(); |
| 2647 | break; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2648 | } |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2649 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2650 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2651 | ConflictingDecls.push_back(FoundDecl); |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2652 | } // for |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2653 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2654 | if (!ConflictingDecls.empty() && SearchName) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2655 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2656 | ConflictingDecls.data(), |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2657 | ConflictingDecls.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2658 | if (!Name) |
| 2659 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2660 | } |
| 2661 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2662 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2663 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2664 | if (!BeginLocOrErr) |
| 2665 | return BeginLocOrErr.takeError(); |
| 2666 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2667 | // Create the record declaration. |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2668 | RecordDecl *D2 = nullptr; |
| 2669 | CXXRecordDecl *D2CXX = nullptr; |
| 2670 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2671 | if (DCXX->isLambda()) { |
| 2672 | auto TInfoOrErr = import(DCXX->getLambdaTypeInfo()); |
| 2673 | if (!TInfoOrErr) |
| 2674 | return TInfoOrErr.takeError(); |
| 2675 | if (GetImportedOrCreateSpecialDecl( |
| 2676 | D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(), |
| 2677 | DC, *TInfoOrErr, Loc, DCXX->isDependentLambda(), |
| 2678 | DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault())) |
| 2679 | return D2CXX; |
| 2680 | ExpectedDecl CDeclOrErr = import(DCXX->getLambdaContextDecl()); |
| 2681 | if (!CDeclOrErr) |
| 2682 | return CDeclOrErr.takeError(); |
| 2683 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), *CDeclOrErr); |
| 2684 | } else if (DCXX->isInjectedClassName()) { |
| 2685 | // We have to be careful to do a similar dance to the one in |
| 2686 | // Sema::ActOnStartCXXMemberDeclarations |
| 2687 | const bool DelayTypeCreation = true; |
| 2688 | if (GetImportedOrCreateDecl( |
| 2689 | D2CXX, D, Importer.getToContext(), D->getTagKind(), DC, |
| 2690 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), |
| 2691 | cast_or_null<CXXRecordDecl>(PrevDecl), DelayTypeCreation)) |
| 2692 | return D2CXX; |
| 2693 | Importer.getToContext().getTypeDeclType( |
| 2694 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); |
| 2695 | } else { |
| 2696 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), |
| 2697 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
| 2698 | Name.getAsIdentifierInfo(), |
| 2699 | cast_or_null<CXXRecordDecl>(PrevDecl))) |
| 2700 | return D2CXX; |
| 2701 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2702 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2703 | D2 = D2CXX; |
| 2704 | D2->setAccess(D->getAccess()); |
| 2705 | D2->setLexicalDeclContext(LexicalDC); |
| 2706 | if (!DCXX->getDescribedClassTemplate() || DCXX->isImplicit()) |
| 2707 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2708 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2709 | if (LexicalDC != DC && D->isInIdentifierNamespace(Decl::IDNS_TagFriend)) |
| 2710 | DC->makeDeclVisibleInContext(D2); |
| 2711 | |
| 2712 | if (ClassTemplateDecl *FromDescribed = |
| 2713 | DCXX->getDescribedClassTemplate()) { |
| 2714 | ClassTemplateDecl *ToDescribed; |
| 2715 | if (Error Err = importInto(ToDescribed, FromDescribed)) |
| 2716 | return std::move(Err); |
| 2717 | D2CXX->setDescribedClassTemplate(ToDescribed); |
| 2718 | if (!DCXX->isInjectedClassName() && !IsFriendTemplate) { |
| 2719 | // In a record describing a template the type should be an |
| 2720 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the |
| 2721 | // previously set type to the correct value here (ToDescribed is not |
| 2722 | // available at record create). |
| 2723 | // FIXME: The previous type is cleared but not removed from |
| 2724 | // ASTContext's internal storage. |
| 2725 | CXXRecordDecl *Injected = nullptr; |
| 2726 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { |
| 2727 | auto *Record = dyn_cast<CXXRecordDecl>(Found); |
| 2728 | if (Record && Record->isInjectedClassName()) { |
| 2729 | Injected = Record; |
| 2730 | break; |
Gabor Marton | 5915777e | 2018-06-26 13:44:24 +0000 | [diff] [blame] | 2731 | } |
| 2732 | } |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2733 | // Create an injected type for the whole redecl chain. |
| 2734 | SmallVector<Decl *, 2> Redecls = |
| 2735 | getCanonicalForwardRedeclChain(D2CXX); |
| 2736 | for (auto *R : Redecls) { |
| 2737 | auto *RI = cast<CXXRecordDecl>(R); |
| 2738 | RI->setTypeForDecl(nullptr); |
| 2739 | // Below we create a new injected type and assign that to the |
| 2740 | // canonical decl, subsequent declarations in the chain will reuse |
| 2741 | // that type. |
| 2742 | Importer.getToContext().getInjectedClassNameType( |
| 2743 | RI, ToDescribed->getInjectedClassNameSpecialization()); |
| 2744 | } |
| 2745 | // Set the new type for the previous injected decl too. |
| 2746 | if (Injected) { |
| 2747 | Injected->setTypeForDecl(nullptr); |
| 2748 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); |
| 2749 | } |
| 2750 | } |
| 2751 | } else if (MemberSpecializationInfo *MemberInfo = |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2752 | DCXX->getMemberSpecializationInfo()) { |
| 2753 | TemplateSpecializationKind SK = |
| 2754 | MemberInfo->getTemplateSpecializationKind(); |
| 2755 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2756 | |
| 2757 | if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst)) |
| 2758 | D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK); |
| 2759 | else |
| 2760 | return ToInstOrErr.takeError(); |
| 2761 | |
| 2762 | if (ExpectedSLoc POIOrErr = |
| 2763 | import(MemberInfo->getPointOfInstantiation())) |
| 2764 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( |
| 2765 | *POIOrErr); |
| 2766 | else |
| 2767 | return POIOrErr.takeError(); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2768 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2769 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2770 | } else { |
| 2771 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), |
| 2772 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
| 2773 | Name.getAsIdentifierInfo(), PrevDecl)) |
| 2774 | return D2; |
| 2775 | D2->setLexicalDeclContext(LexicalDC); |
| 2776 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2777 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2778 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2779 | if (auto QualifierLocOrErr = import(D->getQualifierLoc())) |
| 2780 | D2->setQualifierInfo(*QualifierLocOrErr); |
| 2781 | else |
| 2782 | return QualifierLocOrErr.takeError(); |
| 2783 | |
| 2784 | if (D->isAnonymousStructOrUnion()) |
| 2785 | D2->setAnonymousStructOrUnion(true); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2786 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2787 | if (D->isCompleteDefinition()) |
| 2788 | if (Error Err = ImportDefinition(D, D2, IDK_Default)) |
| 2789 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2790 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2791 | return D2; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2792 | } |
| 2793 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2794 | ExpectedDecl ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2795 | // Import the major distinguishing characteristics of this enumerator. |
| 2796 | DeclContext *DC, *LexicalDC; |
| 2797 | DeclarationName Name; |
| 2798 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2799 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2800 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2801 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2802 | if (ToD) |
| 2803 | return ToD; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2804 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2805 | // Determine whether there are any other declarations with the same name and |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2806 | // in the same context. |
| 2807 | if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2808 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2809 | unsigned IDNS = Decl::IDNS_Ordinary; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2810 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2811 | for (auto *FoundDecl : FoundDecls) { |
| 2812 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2813 | continue; |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2814 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2815 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2816 | if (IsStructuralMatch(D, FoundEnumConstant)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2817 | return Importer.MapImported(D, FoundEnumConstant); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2818 | } |
| 2819 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2820 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2821 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2822 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2823 | if (!ConflictingDecls.empty()) { |
| 2824 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2825 | ConflictingDecls.data(), |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2826 | ConflictingDecls.size()); |
| 2827 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2828 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2829 | } |
| 2830 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2831 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2832 | ExpectedType TypeOrErr = import(D->getType()); |
| 2833 | if (!TypeOrErr) |
| 2834 | return TypeOrErr.takeError(); |
| 2835 | |
| 2836 | ExpectedExpr InitOrErr = import(D->getInitExpr()); |
| 2837 | if (!InitOrErr) |
| 2838 | return InitOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2839 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2840 | EnumConstantDecl *ToEnumerator; |
| 2841 | if (GetImportedOrCreateDecl( |
| 2842 | ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2843 | Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2844 | return ToEnumerator; |
| 2845 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2846 | ToEnumerator->setAccess(D->getAccess()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2847 | ToEnumerator->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2848 | LexicalDC->addDeclInternal(ToEnumerator); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2849 | return ToEnumerator; |
| 2850 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2851 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2852 | Error ASTNodeImporter::ImportTemplateInformation( |
| 2853 | FunctionDecl *FromFD, FunctionDecl *ToFD) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2854 | switch (FromFD->getTemplatedKind()) { |
| 2855 | case FunctionDecl::TK_NonTemplate: |
| 2856 | case FunctionDecl::TK_FunctionTemplate: |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2857 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2858 | |
| 2859 | case FunctionDecl::TK_MemberSpecialization: { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2860 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2861 | |
| 2862 | if (Expected<FunctionDecl *> InstFDOrErr = |
| 2863 | import(FromFD->getInstantiatedFromMemberFunction())) |
| 2864 | ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK); |
| 2865 | else |
| 2866 | return InstFDOrErr.takeError(); |
| 2867 | |
| 2868 | if (ExpectedSLoc POIOrErr = import( |
| 2869 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation())) |
| 2870 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr); |
| 2871 | else |
| 2872 | return POIOrErr.takeError(); |
| 2873 | |
| 2874 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2875 | } |
| 2876 | |
| 2877 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2878 | auto FunctionAndArgsOrErr = |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2879 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2880 | if (!FunctionAndArgsOrErr) |
| 2881 | return FunctionAndArgsOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2882 | |
| 2883 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2884 | Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr)); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2885 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2886 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2887 | TemplateArgumentListInfo ToTAInfo; |
| 2888 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2889 | if (FromTAArgsAsWritten) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2890 | if (Error Err = ImportTemplateArgumentListInfo( |
| 2891 | *FromTAArgsAsWritten, ToTAInfo)) |
| 2892 | return Err; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2893 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2894 | ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation()); |
| 2895 | if (!POIOrErr) |
| 2896 | return POIOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2897 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2898 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2899 | ToFD->setFunctionTemplateSpecialization( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2900 | std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr, |
| 2901 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr); |
| 2902 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2903 | } |
| 2904 | |
| 2905 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 2906 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); |
| 2907 | UnresolvedSet<8> TemplDecls; |
| 2908 | unsigned NumTemplates = FromInfo->getNumTemplates(); |
| 2909 | for (unsigned I = 0; I < NumTemplates; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2910 | if (Expected<FunctionTemplateDecl *> ToFTDOrErr = |
| 2911 | import(FromInfo->getTemplate(I))) |
| 2912 | TemplDecls.addDecl(*ToFTDOrErr); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2913 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2914 | return ToFTDOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2915 | } |
| 2916 | |
| 2917 | // Import TemplateArgumentListInfo. |
| 2918 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2919 | if (Error Err = ImportTemplateArgumentListInfo( |
| 2920 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), |
| 2921 | llvm::makeArrayRef( |
| 2922 | FromInfo->getTemplateArgs(), FromInfo->getNumTemplateArgs()), |
| 2923 | ToTAInfo)) |
| 2924 | return Err; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2925 | |
| 2926 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), |
| 2927 | TemplDecls, ToTAInfo); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2928 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2929 | } |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2930 | } |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2931 | llvm_unreachable("All cases should be covered!"); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2932 | } |
| 2933 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2934 | Expected<FunctionDecl *> |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2935 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2936 | auto FunctionAndArgsOrErr = |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2937 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2938 | if (!FunctionAndArgsOrErr) |
| 2939 | return FunctionAndArgsOrErr.takeError(); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2940 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2941 | FunctionTemplateDecl *Template; |
| 2942 | TemplateArgsTy ToTemplArgs; |
| 2943 | std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2944 | void *InsertPos = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2945 | auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2946 | return FoundSpec; |
| 2947 | } |
| 2948 | |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 2949 | Error ASTNodeImporter::ImportFunctionDeclBody(FunctionDecl *FromFD, |
| 2950 | FunctionDecl *ToFD) { |
| 2951 | if (Stmt *FromBody = FromFD->getBody()) { |
| 2952 | if (ExpectedStmt ToBodyOrErr = import(FromBody)) |
| 2953 | ToFD->setBody(*ToBodyOrErr); |
| 2954 | else |
| 2955 | return ToBodyOrErr.takeError(); |
| 2956 | } |
| 2957 | return Error::success(); |
| 2958 | } |
| 2959 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2960 | ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2961 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2962 | SmallVector<Decl *, 2> Redecls = getCanonicalForwardRedeclChain(D); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2963 | auto RedeclIt = Redecls.begin(); |
| 2964 | // Import the first part of the decl chain. I.e. import all previous |
| 2965 | // declarations starting from the canonical decl. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2966 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 2967 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 2968 | if (!ToRedeclOrErr) |
| 2969 | return ToRedeclOrErr.takeError(); |
| 2970 | } |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2971 | assert(*RedeclIt == D); |
| 2972 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2973 | // Import the major distinguishing characteristics of this function. |
| 2974 | DeclContext *DC, *LexicalDC; |
| 2975 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2976 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2977 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2978 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2979 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2980 | if (ToD) |
| 2981 | return ToD; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2982 | |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 2983 | FunctionDecl *FoundByLookup = nullptr; |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 2984 | FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2985 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2986 | // If this is a function template specialization, then try to find the same |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2987 | // existing specialization in the "to" context. The lookup below will not |
| 2988 | // find any specialization, but would find the primary template; thus, we |
| 2989 | // have to skip normal lookup in case of specializations. |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2990 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? |
| 2991 | if (D->getTemplatedKind() == |
| 2992 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2993 | auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D); |
| 2994 | if (!FoundFunctionOrErr) |
| 2995 | return FoundFunctionOrErr.takeError(); |
| 2996 | if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) { |
| 2997 | if (D->doesThisDeclarationHaveABody() && FoundFunction->hasBody()) |
| 2998 | return Importer.MapImported(D, FoundFunction); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2999 | FoundByLookup = FoundFunction; |
| 3000 | } |
| 3001 | } |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3002 | // Try to find a function in our own ("to") context with the same name, same |
| 3003 | // type, and in the same context as the function we're importing. |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3004 | else if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3005 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3006 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3007 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3008 | for (auto *FoundDecl : FoundDecls) { |
| 3009 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3010 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3011 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3012 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { |
Rafael Espindola | 3ae0005 | 2013-05-13 00:12:11 +0000 | [diff] [blame] | 3013 | if (FoundFunction->hasExternalFormalLinkage() && |
| 3014 | D->hasExternalFormalLinkage()) { |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 3015 | if (IsStructuralMatch(D, FoundFunction)) { |
| 3016 | const FunctionDecl *Definition = nullptr; |
| 3017 | if (D->doesThisDeclarationHaveABody() && |
| 3018 | FoundFunction->hasBody(Definition)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3019 | return Importer.MapImported( |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 3020 | D, const_cast<FunctionDecl *>(Definition)); |
| 3021 | } |
| 3022 | FoundByLookup = FoundFunction; |
| 3023 | break; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3024 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3025 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3026 | // FIXME: Check for overloading more carefully, e.g., by boosting |
| 3027 | // Sema::IsOverload out to the AST library. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3028 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3029 | // Function overloading is okay in C++. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3030 | if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3031 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3032 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3033 | // Complain about inconsistent function types. |
| 3034 | Importer.ToDiag(Loc, diag::err_odr_function_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3035 | << Name << D->getType() << FoundFunction->getType(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3036 | Importer.ToDiag(FoundFunction->getLocation(), |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3037 | diag::note_odr_value_here) |
| 3038 | << FoundFunction->getType(); |
| 3039 | } |
| 3040 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3041 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3042 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3043 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3044 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3045 | if (!ConflictingDecls.empty()) { |
| 3046 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3047 | ConflictingDecls.data(), |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3048 | ConflictingDecls.size()); |
| 3049 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3050 | return make_error<ImportError>(ImportError::NameConflict); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3051 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3052 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3053 | |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3054 | // We do not allow more than one in-class declaration of a function. This is |
| 3055 | // because AST clients like VTableBuilder asserts on this. VTableBuilder |
| 3056 | // assumes there is only one in-class declaration. Building a redecl |
| 3057 | // chain would result in more than one in-class declaration for |
| 3058 | // overrides (even if they are part of the same redecl chain inside the |
| 3059 | // derived class.) |
| 3060 | if (FoundByLookup) { |
Mikael Holmen | c1c97aa | 2019-01-29 06:53:31 +0000 | [diff] [blame^] | 3061 | if (isa<CXXMethodDecl>(FoundByLookup)) { |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3062 | if (D->getLexicalDeclContext() == D->getDeclContext()) { |
| 3063 | if (!D->doesThisDeclarationHaveABody()) |
| 3064 | return Importer.MapImported(D, FoundByLookup); |
| 3065 | else { |
| 3066 | // Let's continue and build up the redecl chain in this case. |
| 3067 | // FIXME Merge the functions into one decl. |
| 3068 | } |
| 3069 | } |
| 3070 | } |
| 3071 | } |
| 3072 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3073 | DeclarationNameInfo NameInfo(Name, Loc); |
| 3074 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3075 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 3076 | return std::move(Err); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3077 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3078 | QualType FromTy = D->getType(); |
| 3079 | bool usedDifferentExceptionSpec = false; |
| 3080 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3081 | if (const auto *FromFPT = D->getType()->getAs<FunctionProtoType>()) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3082 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); |
| 3083 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the |
| 3084 | // FunctionDecl that we are importing the FunctionProtoType for. |
| 3085 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| 3086 | // with a simplified function type and update it afterwards. |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 3087 | if (FromEPI.ExceptionSpec.SourceDecl || |
| 3088 | FromEPI.ExceptionSpec.SourceTemplate || |
| 3089 | FromEPI.ExceptionSpec.NoexceptExpr) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3090 | FunctionProtoType::ExtProtoInfo DefaultEPI; |
| 3091 | FromTy = Importer.getFromContext().getFunctionType( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3092 | FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI); |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3093 | usedDifferentExceptionSpec = true; |
| 3094 | } |
| 3095 | } |
| 3096 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3097 | QualType T; |
| 3098 | TypeSourceInfo *TInfo; |
| 3099 | SourceLocation ToInnerLocStart, ToEndLoc; |
| 3100 | NestedNameSpecifierLoc ToQualifierLoc; |
| 3101 | if (auto Imp = importSeq( |
| 3102 | FromTy, D->getTypeSourceInfo(), D->getInnerLocStart(), |
| 3103 | D->getQualifierLoc(), D->getEndLoc())) |
| 3104 | std::tie(T, TInfo, ToInnerLocStart, ToQualifierLoc, ToEndLoc) = *Imp; |
| 3105 | else |
| 3106 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3107 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3108 | // Import the function parameters. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3109 | SmallVector<ParmVarDecl *, 8> Parameters; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3110 | for (auto P : D->parameters()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3111 | if (Expected<ParmVarDecl *> ToPOrErr = import(P)) |
| 3112 | Parameters.push_back(*ToPOrErr); |
| 3113 | else |
| 3114 | return ToPOrErr.takeError(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3115 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3116 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3117 | // Create the imported function. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3118 | FunctionDecl *ToFunction = nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3119 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3120 | if (GetImportedOrCreateDecl<CXXConstructorDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3121 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3122 | ToInnerLocStart, NameInfo, T, TInfo, |
| 3123 | FromConstructor->isExplicit(), |
| 3124 | D->isInlineSpecified(), D->isImplicit(), D->isConstexpr())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3125 | return ToFunction; |
Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3126 | } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) { |
| 3127 | |
| 3128 | auto Imp = |
| 3129 | importSeq(const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()), |
| 3130 | FromDtor->getOperatorDeleteThisArg()); |
| 3131 | |
| 3132 | if (!Imp) |
| 3133 | return Imp.takeError(); |
| 3134 | |
| 3135 | FunctionDecl *ToOperatorDelete; |
| 3136 | Expr *ToThisArg; |
| 3137 | std::tie(ToOperatorDelete, ToThisArg) = *Imp; |
| 3138 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3139 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3140 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3141 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| 3142 | D->isImplicit())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3143 | return ToFunction; |
Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3144 | |
| 3145 | CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction); |
| 3146 | |
| 3147 | ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3148 | } else if (CXXConversionDecl *FromConversion = |
| 3149 | dyn_cast<CXXConversionDecl>(D)) { |
| 3150 | if (GetImportedOrCreateDecl<CXXConversionDecl>( |
| 3151 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3152 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3153 | FromConversion->isExplicit(), D->isConstexpr(), SourceLocation())) |
| 3154 | return ToFunction; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3155 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3156 | if (GetImportedOrCreateDecl<CXXMethodDecl>( |
| 3157 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3158 | ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3159 | Method->isInlineSpecified(), D->isConstexpr(), SourceLocation())) |
| 3160 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3161 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3162 | if (GetImportedOrCreateDecl(ToFunction, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3163 | ToInnerLocStart, NameInfo, T, TInfo, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3164 | D->getStorageClass(), D->isInlineSpecified(), |
| 3165 | D->hasWrittenPrototype(), D->isConstexpr())) |
| 3166 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3167 | } |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3168 | |
Gabor Marton | f5e4f0a | 2018-11-20 14:19:39 +0000 | [diff] [blame] | 3169 | // Connect the redecl chain. |
| 3170 | if (FoundByLookup) { |
| 3171 | auto *Recent = const_cast<FunctionDecl *>( |
| 3172 | FoundByLookup->getMostRecentDecl()); |
| 3173 | ToFunction->setPreviousDecl(Recent); |
| 3174 | } |
| 3175 | |
| 3176 | // Import Ctor initializers. |
| 3177 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
| 3178 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
| 3179 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers); |
| 3180 | // Import first, then allocate memory and copy if there was no error. |
| 3181 | if (Error Err = ImportContainerChecked( |
| 3182 | FromConstructor->inits(), CtorInitializers)) |
| 3183 | return std::move(Err); |
| 3184 | auto **Memory = |
| 3185 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 3186 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
| 3187 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); |
| 3188 | ToCtor->setCtorInitializers(Memory); |
| 3189 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 3190 | } |
| 3191 | } |
| 3192 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3193 | ToFunction->setQualifierInfo(ToQualifierLoc); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3194 | ToFunction->setAccess(D->getAccess()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3195 | ToFunction->setLexicalDeclContext(LexicalDC); |
John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 3196 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 3197 | ToFunction->setTrivial(D->isTrivial()); |
| 3198 | ToFunction->setPure(D->isPure()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3199 | ToFunction->setRangeEnd(ToEndLoc); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3200 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3201 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3202 | for (auto *Param : Parameters) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3203 | Param->setOwningFunction(ToFunction); |
| 3204 | ToFunction->addDeclInternal(Param); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3205 | } |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 3206 | ToFunction->setParams(Parameters); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3207 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3208 | // We need to complete creation of FunctionProtoTypeLoc manually with setting |
| 3209 | // params it refers to. |
| 3210 | if (TInfo) { |
| 3211 | if (auto ProtoLoc = |
| 3212 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { |
| 3213 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) |
| 3214 | ProtoLoc.setParam(I, Parameters[I]); |
| 3215 | } |
| 3216 | } |
| 3217 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3218 | if (usedDifferentExceptionSpec) { |
| 3219 | // Update FunctionProtoType::ExtProtoInfo. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3220 | if (ExpectedType TyOrErr = import(D->getType())) |
| 3221 | ToFunction->setType(*TyOrErr); |
| 3222 | else |
| 3223 | return TyOrErr.takeError(); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 3224 | } |
| 3225 | |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3226 | // Import the describing template function, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3227 | if (FromFT) { |
| 3228 | auto ToFTOrErr = import(FromFT); |
| 3229 | if (!ToFTOrErr) |
| 3230 | return ToFTOrErr.takeError(); |
| 3231 | } |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3232 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3233 | if (D->doesThisDeclarationHaveABody()) { |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3234 | Error Err = ImportFunctionDeclBody(D, ToFunction); |
| 3235 | |
| 3236 | if (Err) |
| 3237 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3238 | } |
| 3239 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3240 | // FIXME: Other bits to merge? |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3241 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3242 | // If it is a template, import all related things. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3243 | if (Error Err = ImportTemplateInformation(D, ToFunction)) |
| 3244 | return std::move(Err); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3245 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3246 | bool IsFriend = D->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend); |
| 3247 | |
| 3248 | // TODO Can we generalize this approach to other AST nodes as well? |
| 3249 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 3250 | DC->addDeclInternal(ToFunction); |
| 3251 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3252 | LexicalDC->addDeclInternal(ToFunction); |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3253 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3254 | // Friend declaration's lexical context is the befriending class, but the |
| 3255 | // semantic context is the enclosing scope of the befriending class. |
| 3256 | // We want the friend functions to be found in the semantic context by lookup. |
| 3257 | // FIXME should we handle this generically in VisitFriendDecl? |
| 3258 | // In Other cases when LexicalDC != DC we don't want it to be added, |
| 3259 | // e.g out-of-class definitions like void B::f() {} . |
| 3260 | if (LexicalDC != DC && IsFriend) { |
| 3261 | DC->makeDeclVisibleInContext(ToFunction); |
| 3262 | } |
| 3263 | |
Gabor Marton | 7a0841e | 2018-10-29 10:18:28 +0000 | [diff] [blame] | 3264 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) |
| 3265 | ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod); |
| 3266 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3267 | // Import the rest of the chain. I.e. import all subsequent declarations. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3268 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3269 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 3270 | if (!ToRedeclOrErr) |
| 3271 | return ToRedeclOrErr.takeError(); |
| 3272 | } |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3273 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3274 | return ToFunction; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3275 | } |
| 3276 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3277 | ExpectedDecl ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3278 | return VisitFunctionDecl(D); |
| 3279 | } |
| 3280 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3281 | ExpectedDecl ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3282 | return VisitCXXMethodDecl(D); |
| 3283 | } |
| 3284 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3285 | ExpectedDecl ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3286 | return VisitCXXMethodDecl(D); |
| 3287 | } |
| 3288 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3289 | ExpectedDecl ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3290 | return VisitCXXMethodDecl(D); |
| 3291 | } |
| 3292 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3293 | ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3294 | // Import the major distinguishing characteristics of a variable. |
| 3295 | DeclContext *DC, *LexicalDC; |
| 3296 | DeclarationName Name; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3297 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3298 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3299 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3300 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3301 | if (ToD) |
| 3302 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3303 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3304 | // Determine whether we've already imported this field. |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3305 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3306 | for (auto *FoundDecl : FoundDecls) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3307 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3308 | // For anonymous fields, match up by index. |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3309 | if (!Name && |
| 3310 | ASTImporter::getFieldIndex(D) != |
| 3311 | ASTImporter::getFieldIndex(FoundField)) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3312 | continue; |
| 3313 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3314 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3315 | FoundField->getType())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3316 | Importer.MapImported(D, FoundField); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3317 | // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the |
| 3318 | // initializer of a FieldDecl might not had been instantiated in the |
| 3319 | // "To" context. However, the "From" context might instantiated that, |
| 3320 | // thus we have to merge that. |
| 3321 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
| 3322 | // We don't have yet the initializer set. |
| 3323 | if (FoundField->hasInClassInitializer() && |
| 3324 | !FoundField->getInClassInitializer()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3325 | if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) |
| 3326 | FoundField->setInClassInitializer(*ToInitializerOrErr); |
| 3327 | else { |
| 3328 | // We can't return error here, |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3329 | // since we already mapped D as imported. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3330 | // FIXME: warning message? |
| 3331 | consumeError(ToInitializerOrErr.takeError()); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3332 | return FoundField; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3333 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3334 | } |
| 3335 | } |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3336 | return FoundField; |
| 3337 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3338 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3339 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3340 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 3341 | << Name << D->getType() << FoundField->getType(); |
| 3342 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3343 | << FoundField->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3344 | |
| 3345 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3346 | } |
| 3347 | } |
| 3348 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3349 | QualType ToType; |
| 3350 | TypeSourceInfo *ToTInfo; |
| 3351 | Expr *ToBitWidth; |
| 3352 | SourceLocation ToInnerLocStart; |
| 3353 | Expr *ToInitializer; |
| 3354 | if (auto Imp = importSeq( |
| 3355 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), |
| 3356 | D->getInnerLocStart(), D->getInClassInitializer())) |
| 3357 | std::tie( |
| 3358 | ToType, ToTInfo, ToBitWidth, ToInnerLocStart, ToInitializer) = *Imp; |
| 3359 | else |
| 3360 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3361 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3362 | FieldDecl *ToField; |
| 3363 | if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3364 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3365 | ToType, ToTInfo, ToBitWidth, D->isMutable(), |
| 3366 | D->getInClassInitStyle())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3367 | return ToField; |
| 3368 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3369 | ToField->setAccess(D->getAccess()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3370 | ToField->setLexicalDeclContext(LexicalDC); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3371 | if (ToInitializer) |
| 3372 | ToField->setInClassInitializer(ToInitializer); |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3373 | ToField->setImplicit(D->isImplicit()); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3374 | LexicalDC->addDeclInternal(ToField); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3375 | return ToField; |
| 3376 | } |
| 3377 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3378 | ExpectedDecl ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3379 | // Import the major distinguishing characteristics of a variable. |
| 3380 | DeclContext *DC, *LexicalDC; |
| 3381 | DeclarationName Name; |
| 3382 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3383 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3384 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3385 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3386 | if (ToD) |
| 3387 | return ToD; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3388 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3389 | // Determine whether we've already imported this field. |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3390 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3391 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3392 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3393 | // For anonymous indirect fields, match up by index. |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3394 | if (!Name && |
| 3395 | ASTImporter::getFieldIndex(D) != |
| 3396 | ASTImporter::getFieldIndex(FoundField)) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3397 | continue; |
| 3398 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3399 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3400 | FoundField->getType(), |
David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 3401 | !Name.isEmpty())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3402 | Importer.MapImported(D, FoundField); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3403 | return FoundField; |
| 3404 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3405 | |
| 3406 | // If there are more anonymous fields to check, continue. |
| 3407 | if (!Name && I < N-1) |
| 3408 | continue; |
| 3409 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3410 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3411 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 3412 | << Name << D->getType() << FoundField->getType(); |
| 3413 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3414 | << FoundField->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3415 | |
| 3416 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3417 | } |
| 3418 | } |
| 3419 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3420 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3421 | auto TypeOrErr = import(D->getType()); |
| 3422 | if (!TypeOrErr) |
| 3423 | return TypeOrErr.takeError(); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3424 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3425 | auto **NamedChain = |
| 3426 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3427 | |
| 3428 | unsigned i = 0; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3429 | for (auto *PI : D->chain()) |
| 3430 | if (Expected<NamedDecl *> ToD = import(PI)) |
| 3431 | NamedChain[i++] = *ToD; |
| 3432 | else |
| 3433 | return ToD.takeError(); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3434 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3435 | llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()}; |
| 3436 | IndirectFieldDecl *ToIndirectField; |
| 3437 | if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3438 | Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3439 | // FIXME here we leak `NamedChain` which is allocated before |
| 3440 | return ToIndirectField; |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 3441 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3442 | for (const auto *Attr : D->attrs()) |
| 3443 | ToIndirectField->addAttr(Importer.Import(Attr)); |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 3444 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3445 | ToIndirectField->setAccess(D->getAccess()); |
| 3446 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3447 | LexicalDC->addDeclInternal(ToIndirectField); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3448 | return ToIndirectField; |
| 3449 | } |
| 3450 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3451 | ExpectedDecl ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3452 | // Import the major distinguishing characteristics of a declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3453 | DeclContext *DC, *LexicalDC; |
| 3454 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 3455 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3456 | |
| 3457 | // Determine whether we've already imported this decl. |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3458 | // FriendDecl is not a NamedDecl so we cannot use lookup. |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3459 | auto *RD = cast<CXXRecordDecl>(DC); |
| 3460 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3461 | |
| 3462 | while (ImportedFriend) { |
| 3463 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 3464 | if (IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(), |
| 3465 | /*Complain=*/false)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3466 | return Importer.MapImported(D, ImportedFriend); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3467 | |
| 3468 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| 3469 | if (Importer.IsStructurallyEquivalent( |
| 3470 | D->getFriendType()->getType(), |
| 3471 | ImportedFriend->getFriendType()->getType(), true)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3472 | return Importer.MapImported(D, ImportedFriend); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3473 | } |
| 3474 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 3475 | } |
| 3476 | |
| 3477 | // Not found. Create it. |
| 3478 | FriendDecl::FriendUnion ToFU; |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3479 | if (NamedDecl *FriendD = D->getFriendDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3480 | NamedDecl *ToFriendD; |
| 3481 | if (Error Err = importInto(ToFriendD, FriendD)) |
| 3482 | return std::move(Err); |
| 3483 | |
| 3484 | if (FriendD->getFriendObjectKind() != Decl::FOK_None && |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3485 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) |
| 3486 | ToFriendD->setObjectOfFriendDecl(false); |
| 3487 | |
| 3488 | ToFU = ToFriendD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3489 | } else { // The friend is a type, not a decl. |
| 3490 | if (auto TSIOrErr = import(D->getFriendType())) |
| 3491 | ToFU = *TSIOrErr; |
| 3492 | else |
| 3493 | return TSIOrErr.takeError(); |
| 3494 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3495 | |
| 3496 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3497 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3498 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3499 | if (auto ListOrErr = ImportTemplateParameterList(FromTPLists[I])) |
| 3500 | ToTPLists[I] = *ListOrErr; |
| 3501 | else |
| 3502 | return ListOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3503 | } |
| 3504 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3505 | auto LocationOrErr = import(D->getLocation()); |
| 3506 | if (!LocationOrErr) |
| 3507 | return LocationOrErr.takeError(); |
| 3508 | auto FriendLocOrErr = import(D->getFriendLoc()); |
| 3509 | if (!FriendLocOrErr) |
| 3510 | return FriendLocOrErr.takeError(); |
| 3511 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3512 | FriendDecl *FrD; |
| 3513 | if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3514 | *LocationOrErr, ToFU, |
| 3515 | *FriendLocOrErr, ToTPLists)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3516 | return FrD; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3517 | |
| 3518 | FrD->setAccess(D->getAccess()); |
| 3519 | FrD->setLexicalDeclContext(LexicalDC); |
| 3520 | LexicalDC->addDeclInternal(FrD); |
| 3521 | return FrD; |
| 3522 | } |
| 3523 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3524 | ExpectedDecl ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3525 | // Import the major distinguishing characteristics of an ivar. |
| 3526 | DeclContext *DC, *LexicalDC; |
| 3527 | DeclarationName Name; |
| 3528 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3529 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3530 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3531 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3532 | if (ToD) |
| 3533 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3534 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3535 | // Determine whether we've already imported this ivar |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3536 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
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; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3606 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3607 | for (auto *FoundDecl : FoundDecls) { |
| 3608 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3609 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3610 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3611 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3612 | // 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] | 3613 | if (FoundVar->hasExternalFormalLinkage() && |
| 3614 | D->hasExternalFormalLinkage()) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3615 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3616 | FoundVar->getType())) { |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3617 | |
| 3618 | // The VarDecl in the "From" context has a definition, but in the |
| 3619 | // "To" context we already have a definition. |
| 3620 | VarDecl *FoundDef = FoundVar->getDefinition(); |
| 3621 | if (D->isThisDeclarationADefinition() && FoundDef) |
| 3622 | // FIXME Check for ODR error if the two definitions have |
| 3623 | // different initializers? |
| 3624 | return Importer.MapImported(D, FoundDef); |
| 3625 | |
| 3626 | // The VarDecl in the "From" context has an initializer, but in the |
| 3627 | // "To" context we already have an initializer. |
| 3628 | const VarDecl *FoundDInit = nullptr; |
| 3629 | if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit)) |
| 3630 | // FIXME Diagnose ODR error if the two initializers are different? |
| 3631 | return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit)); |
| 3632 | |
| 3633 | FoundByLookup = FoundVar; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3634 | break; |
| 3635 | } |
| 3636 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3637 | const ArrayType *FoundArray |
| 3638 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 3639 | const ArrayType *TArray |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3640 | = Importer.getToContext().getAsArrayType(D->getType()); |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3641 | if (FoundArray && TArray) { |
| 3642 | if (isa<IncompleteArrayType>(FoundArray) && |
| 3643 | isa<ConstantArrayType>(TArray)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3644 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3645 | if (auto TyOrErr = import(D->getType())) |
| 3646 | FoundVar->setType(*TyOrErr); |
| 3647 | else |
| 3648 | return TyOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3649 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3650 | FoundByLookup = FoundVar; |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3651 | break; |
| 3652 | } else if (isa<IncompleteArrayType>(TArray) && |
| 3653 | isa<ConstantArrayType>(FoundArray)) { |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3654 | FoundByLookup = FoundVar; |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3655 | break; |
Douglas Gregor | 2fbe558 | 2010-02-10 17:16:49 +0000 | [diff] [blame] | 3656 | } |
| 3657 | } |
| 3658 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3659 | Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3660 | << Name << D->getType() << FoundVar->getType(); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3661 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 3662 | << FoundVar->getType(); |
| 3663 | } |
| 3664 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3665 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3666 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3667 | } |
| 3668 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3669 | if (!ConflictingDecls.empty()) { |
| 3670 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3671 | ConflictingDecls.data(), |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3672 | ConflictingDecls.size()); |
| 3673 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3674 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3675 | } |
| 3676 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3677 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3678 | QualType ToType; |
| 3679 | TypeSourceInfo *ToTypeSourceInfo; |
| 3680 | SourceLocation ToInnerLocStart; |
| 3681 | NestedNameSpecifierLoc ToQualifierLoc; |
| 3682 | if (auto Imp = importSeq( |
| 3683 | D->getType(), D->getTypeSourceInfo(), D->getInnerLocStart(), |
| 3684 | D->getQualifierLoc())) |
| 3685 | std::tie(ToType, ToTypeSourceInfo, ToInnerLocStart, ToQualifierLoc) = *Imp; |
| 3686 | else |
| 3687 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3688 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3689 | // Create the imported variable. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3690 | VarDecl *ToVar; |
| 3691 | if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3692 | ToInnerLocStart, Loc, |
| 3693 | Name.getAsIdentifierInfo(), |
| 3694 | ToType, ToTypeSourceInfo, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3695 | D->getStorageClass())) |
| 3696 | return ToVar; |
| 3697 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3698 | ToVar->setQualifierInfo(ToQualifierLoc); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3699 | ToVar->setAccess(D->getAccess()); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3700 | ToVar->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3701 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3702 | if (FoundByLookup) { |
| 3703 | auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl()); |
| 3704 | ToVar->setPreviousDecl(Recent); |
| 3705 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3706 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3707 | if (Error Err = ImportInitializer(D, ToVar)) |
| 3708 | return std::move(Err); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3709 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3710 | if (D->isConstexpr()) |
| 3711 | ToVar->setConstexpr(true); |
| 3712 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3713 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 3714 | DC->addDeclInternal(ToVar); |
| 3715 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
| 3716 | LexicalDC->addDeclInternal(ToVar); |
| 3717 | |
| 3718 | // Import the rest of the chain. I.e. import all subsequent declarations. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3719 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3720 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3721 | if (!RedeclOrErr) |
| 3722 | return RedeclOrErr.takeError(); |
| 3723 | } |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3724 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3725 | return ToVar; |
| 3726 | } |
| 3727 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3728 | ExpectedDecl ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3729 | // Parameters are created in the translation unit's context, then moved |
| 3730 | // into the function declaration's context afterward. |
| 3731 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3732 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3733 | DeclarationName ToDeclName; |
| 3734 | SourceLocation ToLocation; |
| 3735 | QualType ToType; |
| 3736 | if (auto Imp = importSeq(D->getDeclName(), D->getLocation(), D->getType())) |
| 3737 | std::tie(ToDeclName, ToLocation, ToType) = *Imp; |
| 3738 | else |
| 3739 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3740 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3741 | // Create the imported parameter. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3742 | ImplicitParamDecl *ToParm = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3743 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
| 3744 | ToLocation, ToDeclName.getAsIdentifierInfo(), |
| 3745 | ToType, D->getParameterKind())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3746 | return ToParm; |
| 3747 | return ToParm; |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3748 | } |
| 3749 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3750 | ExpectedDecl ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3751 | // Parameters are created in the translation unit's context, then moved |
| 3752 | // into the function declaration's context afterward. |
| 3753 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3754 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3755 | DeclarationName ToDeclName; |
| 3756 | SourceLocation ToLocation, ToInnerLocStart; |
| 3757 | QualType ToType; |
| 3758 | TypeSourceInfo *ToTypeSourceInfo; |
| 3759 | if (auto Imp = importSeq( |
| 3760 | D->getDeclName(), D->getLocation(), D->getType(), D->getInnerLocStart(), |
| 3761 | D->getTypeSourceInfo())) |
| 3762 | std::tie( |
| 3763 | ToDeclName, ToLocation, ToType, ToInnerLocStart, |
| 3764 | ToTypeSourceInfo) = *Imp; |
| 3765 | else |
| 3766 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3767 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3768 | ParmVarDecl *ToParm; |
| 3769 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3770 | ToInnerLocStart, ToLocation, |
| 3771 | ToDeclName.getAsIdentifierInfo(), ToType, |
| 3772 | ToTypeSourceInfo, D->getStorageClass(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3773 | /*DefaultArg*/ nullptr)) |
| 3774 | return ToParm; |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3775 | |
| 3776 | // Set the default argument. |
John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 3777 | ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg()); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3778 | ToParm->setKNRPromoted(D->isKNRPromoted()); |
| 3779 | |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3780 | if (D->hasUninstantiatedDefaultArg()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3781 | if (auto ToDefArgOrErr = import(D->getUninstantiatedDefaultArg())) |
| 3782 | ToParm->setUninstantiatedDefaultArg(*ToDefArgOrErr); |
| 3783 | else |
| 3784 | return ToDefArgOrErr.takeError(); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3785 | } else if (D->hasUnparsedDefaultArg()) { |
| 3786 | ToParm->setUnparsedDefaultArg(); |
| 3787 | } else if (D->hasDefaultArg()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3788 | if (auto ToDefArgOrErr = import(D->getDefaultArg())) |
| 3789 | ToParm->setDefaultArg(*ToDefArgOrErr); |
| 3790 | else |
| 3791 | return ToDefArgOrErr.takeError(); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3792 | } |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3793 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3794 | if (D->isObjCMethodParameter()) { |
| 3795 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); |
| 3796 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); |
| 3797 | } else { |
| 3798 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), |
| 3799 | D->getFunctionScopeIndex()); |
| 3800 | } |
| 3801 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3802 | return ToParm; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3803 | } |
| 3804 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3805 | ExpectedDecl ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3806 | // Import the major distinguishing characteristics of a method. |
| 3807 | DeclContext *DC, *LexicalDC; |
| 3808 | DeclarationName Name; |
| 3809 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3810 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3811 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3812 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3813 | if (ToD) |
| 3814 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3815 | |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3816 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3817 | for (auto *FoundDecl : FoundDecls) { |
| 3818 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3819 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 3820 | continue; |
| 3821 | |
| 3822 | // Check return types. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3823 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 3824 | FoundMethod->getReturnType())) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3825 | Importer.ToDiag(Loc, diag::err_odr_objc_method_result_type_inconsistent) |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3826 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 3827 | << FoundMethod->getReturnType(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3828 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3829 | diag::note_odr_objc_method_here) |
| 3830 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3831 | |
| 3832 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3833 | } |
| 3834 | |
| 3835 | // Check the number of parameters. |
| 3836 | if (D->param_size() != FoundMethod->param_size()) { |
| 3837 | Importer.ToDiag(Loc, diag::err_odr_objc_method_num_params_inconsistent) |
| 3838 | << D->isInstanceMethod() << Name |
| 3839 | << D->param_size() << FoundMethod->param_size(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3840 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3841 | diag::note_odr_objc_method_here) |
| 3842 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3843 | |
| 3844 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3845 | } |
| 3846 | |
| 3847 | // Check parameter types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3848 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3849 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 3850 | P != PEnd; ++P, ++FoundP) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3851 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3852 | (*FoundP)->getType())) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3853 | Importer.FromDiag((*P)->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3854 | diag::err_odr_objc_method_param_type_inconsistent) |
| 3855 | << D->isInstanceMethod() << Name |
| 3856 | << (*P)->getType() << (*FoundP)->getType(); |
| 3857 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 3858 | << (*FoundP)->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3859 | |
| 3860 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3861 | } |
| 3862 | } |
| 3863 | |
| 3864 | // Check variadic/non-variadic. |
| 3865 | // Check the number of parameters. |
| 3866 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
| 3867 | Importer.ToDiag(Loc, diag::err_odr_objc_method_variadic_inconsistent) |
| 3868 | << D->isInstanceMethod() << Name; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3869 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3870 | diag::note_odr_objc_method_here) |
| 3871 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3872 | |
| 3873 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3874 | } |
| 3875 | |
| 3876 | // FIXME: Any other bits we need to merge? |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3877 | return Importer.MapImported(D, FoundMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3878 | } |
| 3879 | } |
| 3880 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3881 | SourceLocation ToEndLoc; |
| 3882 | QualType ToReturnType; |
| 3883 | TypeSourceInfo *ToReturnTypeSourceInfo; |
| 3884 | if (auto Imp = importSeq( |
| 3885 | D->getEndLoc(), D->getReturnType(), D->getReturnTypeSourceInfo())) |
| 3886 | std::tie(ToEndLoc, ToReturnType, ToReturnTypeSourceInfo) = *Imp; |
| 3887 | else |
| 3888 | return Imp.takeError(); |
Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 3889 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3890 | ObjCMethodDecl *ToMethod; |
| 3891 | if (GetImportedOrCreateDecl( |
| 3892 | ToMethod, D, Importer.getToContext(), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3893 | ToEndLoc, Name.getObjCSelector(), ToReturnType, |
| 3894 | ToReturnTypeSourceInfo, DC, D->isInstanceMethod(), D->isVariadic(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3895 | D->isPropertyAccessor(), D->isImplicit(), D->isDefined(), |
| 3896 | D->getImplementationControl(), D->hasRelatedResultType())) |
| 3897 | return ToMethod; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3898 | |
| 3899 | // FIXME: When we decide to merge method definitions, we'll need to |
| 3900 | // deal with implicit parameters. |
| 3901 | |
| 3902 | // Import the parameters |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3903 | SmallVector<ParmVarDecl *, 5> ToParams; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3904 | for (auto *FromP : D->parameters()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3905 | if (Expected<ParmVarDecl *> ToPOrErr = import(FromP)) |
| 3906 | ToParams.push_back(*ToPOrErr); |
| 3907 | else |
| 3908 | return ToPOrErr.takeError(); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3909 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3910 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3911 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3912 | for (auto *ToParam : ToParams) { |
| 3913 | ToParam->setOwningFunction(ToMethod); |
| 3914 | ToMethod->addDeclInternal(ToParam); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3915 | } |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3916 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3917 | SmallVector<SourceLocation, 12> FromSelLocs; |
| 3918 | D->getSelectorLocs(FromSelLocs); |
| 3919 | SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size()); |
| 3920 | if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs)) |
| 3921 | return std::move(Err); |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3922 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3923 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3924 | |
| 3925 | ToMethod->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3926 | LexicalDC->addDeclInternal(ToMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3927 | return ToMethod; |
| 3928 | } |
| 3929 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3930 | ExpectedDecl ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3931 | // Import the major distinguishing characteristics of a category. |
| 3932 | DeclContext *DC, *LexicalDC; |
| 3933 | DeclarationName Name; |
| 3934 | SourceLocation Loc; |
| 3935 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3936 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3937 | return std::move(Err); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3938 | if (ToD) |
| 3939 | return ToD; |
| 3940 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3941 | SourceLocation ToVarianceLoc, ToLocation, ToColonLoc; |
| 3942 | TypeSourceInfo *ToTypeSourceInfo; |
| 3943 | if (auto Imp = importSeq( |
| 3944 | D->getVarianceLoc(), D->getLocation(), D->getColonLoc(), |
| 3945 | D->getTypeSourceInfo())) |
| 3946 | std::tie(ToVarianceLoc, ToLocation, ToColonLoc, ToTypeSourceInfo) = *Imp; |
| 3947 | else |
| 3948 | return Imp.takeError(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3949 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3950 | ObjCTypeParamDecl *Result; |
| 3951 | if (GetImportedOrCreateDecl( |
| 3952 | Result, D, Importer.getToContext(), DC, D->getVariance(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3953 | ToVarianceLoc, D->getIndex(), |
| 3954 | ToLocation, Name.getAsIdentifierInfo(), |
| 3955 | ToColonLoc, ToTypeSourceInfo)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3956 | return Result; |
| 3957 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3958 | Result->setLexicalDeclContext(LexicalDC); |
| 3959 | return Result; |
| 3960 | } |
| 3961 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3962 | ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3963 | // Import the major distinguishing characteristics of a category. |
| 3964 | DeclContext *DC, *LexicalDC; |
| 3965 | DeclarationName Name; |
| 3966 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3967 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3968 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3969 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3970 | if (ToD) |
| 3971 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3972 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3973 | ObjCInterfaceDecl *ToInterface; |
| 3974 | if (Error Err = importInto(ToInterface, D->getClassInterface())) |
| 3975 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3976 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3977 | // Determine if we've already encountered this category. |
| 3978 | ObjCCategoryDecl *MergeWithCategory |
| 3979 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 3980 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 3981 | if (!ToCategory) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3982 | SourceLocation ToAtStartLoc, ToCategoryNameLoc; |
| 3983 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; |
| 3984 | if (auto Imp = importSeq( |
| 3985 | D->getAtStartLoc(), D->getCategoryNameLoc(), |
| 3986 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) |
| 3987 | std::tie( |
| 3988 | ToAtStartLoc, ToCategoryNameLoc, |
| 3989 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; |
| 3990 | else |
| 3991 | return Imp.takeError(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3992 | |
| 3993 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3994 | ToAtStartLoc, Loc, |
| 3995 | ToCategoryNameLoc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3996 | Name.getAsIdentifierInfo(), ToInterface, |
| 3997 | /*TypeParamList=*/nullptr, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3998 | ToIvarLBraceLoc, |
| 3999 | ToIvarRBraceLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4000 | return ToCategory; |
| 4001 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4002 | ToCategory->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4003 | LexicalDC->addDeclInternal(ToCategory); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4004 | // Import the type parameter list after MapImported, to avoid |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4005 | // loops when bringing in their DeclContext. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4006 | if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList())) |
| 4007 | ToCategory->setTypeParamList(*PListOrErr); |
| 4008 | else |
| 4009 | return PListOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4010 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4011 | // Import protocols |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4012 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4013 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4014 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 4015 | = D->protocol_loc_begin(); |
| 4016 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 4017 | FromProtoEnd = D->protocol_end(); |
| 4018 | FromProto != FromProtoEnd; |
| 4019 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4020 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4021 | Protocols.push_back(*ToProtoOrErr); |
| 4022 | else |
| 4023 | return ToProtoOrErr.takeError(); |
| 4024 | |
| 4025 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4026 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4027 | else |
| 4028 | return ToProtoLocOrErr.takeError(); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4029 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4030 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4031 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4032 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 4033 | ProtocolLocs.data(), Importer.getToContext()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4034 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4035 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4036 | Importer.MapImported(D, ToCategory); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4037 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4038 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4039 | // Import all of the members of this category. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4040 | if (Error Err = ImportDeclContext(D)) |
| 4041 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4042 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4043 | // If we have an implementation, import it as well. |
| 4044 | if (D->getImplementation()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4045 | if (Expected<ObjCCategoryImplDecl *> ToImplOrErr = |
| 4046 | import(D->getImplementation())) |
| 4047 | ToCategory->setImplementation(*ToImplOrErr); |
| 4048 | else |
| 4049 | return ToImplOrErr.takeError(); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4050 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4051 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4052 | return ToCategory; |
| 4053 | } |
| 4054 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4055 | Error ASTNodeImporter::ImportDefinition( |
| 4056 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4057 | if (To->getDefinition()) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4058 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4059 | if (Error Err = ImportDeclContext(From)) |
| 4060 | return Err; |
| 4061 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4062 | } |
| 4063 | |
| 4064 | // Start the protocol definition |
| 4065 | To->startDefinition(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4066 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4067 | // Import protocols |
| 4068 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4069 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4070 | ObjCProtocolDecl::protocol_loc_iterator FromProtoLoc = |
| 4071 | From->protocol_loc_begin(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4072 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4073 | FromProtoEnd = From->protocol_end(); |
| 4074 | FromProto != FromProtoEnd; |
| 4075 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4076 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4077 | Protocols.push_back(*ToProtoOrErr); |
| 4078 | else |
| 4079 | return ToProtoOrErr.takeError(); |
| 4080 | |
| 4081 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4082 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4083 | else |
| 4084 | return ToProtoLocOrErr.takeError(); |
| 4085 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4086 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4087 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4088 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4089 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4090 | ProtocolLocs.data(), Importer.getToContext()); |
| 4091 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4092 | if (shouldForceImportDeclContext(Kind)) { |
| 4093 | // Import all of the members of this protocol. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4094 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4095 | return Err; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4096 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4097 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4098 | } |
| 4099 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4100 | ExpectedDecl ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4101 | // 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] | 4102 | // from, but this particular declaration is not that definition, import the |
| 4103 | // definition and map to that. |
| 4104 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 4105 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4106 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4107 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4108 | else |
| 4109 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4110 | } |
| 4111 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4112 | // Import the major distinguishing characteristics of a protocol. |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4113 | DeclContext *DC, *LexicalDC; |
| 4114 | DeclarationName Name; |
| 4115 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4116 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4117 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4118 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4119 | if (ToD) |
| 4120 | return ToD; |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4121 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4122 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4123 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4124 | for (auto *FoundDecl : FoundDecls) { |
| 4125 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4126 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4127 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4128 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4129 | break; |
| 4130 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4131 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4132 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4133 | if (!ToProto) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4134 | auto ToAtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4135 | if (!ToAtBeginLocOrErr) |
| 4136 | return ToAtBeginLocOrErr.takeError(); |
| 4137 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4138 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, |
| 4139 | Name.getAsIdentifierInfo(), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4140 | *ToAtBeginLocOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4141 | /*PrevDecl=*/nullptr)) |
| 4142 | return ToProto; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4143 | ToProto->setLexicalDeclContext(LexicalDC); |
| 4144 | LexicalDC->addDeclInternal(ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4145 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4146 | |
| 4147 | Importer.MapImported(D, ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4148 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4149 | if (D->isThisDeclarationADefinition()) |
| 4150 | if (Error Err = ImportDefinition(D, ToProto)) |
| 4151 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4152 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4153 | return ToProto; |
| 4154 | } |
| 4155 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4156 | ExpectedDecl ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 4157 | DeclContext *DC, *LexicalDC; |
| 4158 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4159 | return std::move(Err); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4160 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4161 | ExpectedSLoc ExternLocOrErr = import(D->getExternLoc()); |
| 4162 | if (!ExternLocOrErr) |
| 4163 | return ExternLocOrErr.takeError(); |
| 4164 | |
| 4165 | ExpectedSLoc LangLocOrErr = import(D->getLocation()); |
| 4166 | if (!LangLocOrErr) |
| 4167 | return LangLocOrErr.takeError(); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4168 | |
| 4169 | bool HasBraces = D->hasBraces(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4170 | |
| 4171 | LinkageSpecDecl *ToLinkageSpec; |
| 4172 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4173 | *ExternLocOrErr, *LangLocOrErr, |
| 4174 | D->getLanguage(), HasBraces)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4175 | return ToLinkageSpec; |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4176 | |
| 4177 | if (HasBraces) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4178 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); |
| 4179 | if (!RBraceLocOrErr) |
| 4180 | return RBraceLocOrErr.takeError(); |
| 4181 | ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4182 | } |
| 4183 | |
| 4184 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 4185 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 4186 | |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4187 | return ToLinkageSpec; |
| 4188 | } |
| 4189 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4190 | ExpectedDecl ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4191 | DeclContext *DC, *LexicalDC; |
| 4192 | DeclarationName Name; |
| 4193 | SourceLocation Loc; |
| 4194 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4195 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4196 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4197 | if (ToD) |
| 4198 | return ToD; |
| 4199 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4200 | SourceLocation ToLoc, ToUsingLoc; |
| 4201 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4202 | if (auto Imp = importSeq( |
| 4203 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc())) |
| 4204 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc) = *Imp; |
| 4205 | else |
| 4206 | return Imp.takeError(); |
| 4207 | |
| 4208 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4209 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4210 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4211 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4212 | UsingDecl *ToUsing; |
| 4213 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4214 | ToUsingLoc, ToQualifierLoc, NameInfo, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4215 | D->hasTypename())) |
| 4216 | return ToUsing; |
| 4217 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4218 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4219 | LexicalDC->addDeclInternal(ToUsing); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4220 | |
| 4221 | if (NamedDecl *FromPattern = |
| 4222 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4223 | if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern)) |
| 4224 | Importer.getToContext().setInstantiatedFromUsingDecl( |
| 4225 | ToUsing, *ToPatternOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4226 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4227 | return ToPatternOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4228 | } |
| 4229 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4230 | for (UsingShadowDecl *FromShadow : D->shadows()) { |
| 4231 | if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow)) |
| 4232 | ToUsing->addShadowDecl(*ToShadowOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4233 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4234 | // FIXME: We return error here but the definition is already created |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4235 | // and available with lookups. How to fix this?.. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4236 | return ToShadowOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4237 | } |
| 4238 | return ToUsing; |
| 4239 | } |
| 4240 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4241 | ExpectedDecl ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4242 | DeclContext *DC, *LexicalDC; |
| 4243 | DeclarationName Name; |
| 4244 | SourceLocation Loc; |
| 4245 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4246 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4247 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4248 | if (ToD) |
| 4249 | return ToD; |
| 4250 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4251 | Expected<UsingDecl *> ToUsingOrErr = import(D->getUsingDecl()); |
| 4252 | if (!ToUsingOrErr) |
| 4253 | return ToUsingOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4254 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4255 | Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl()); |
| 4256 | if (!ToTargetOrErr) |
| 4257 | return ToTargetOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4258 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4259 | UsingShadowDecl *ToShadow; |
| 4260 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4261 | *ToUsingOrErr, *ToTargetOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4262 | return ToShadow; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4263 | |
| 4264 | ToShadow->setLexicalDeclContext(LexicalDC); |
| 4265 | ToShadow->setAccess(D->getAccess()); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4266 | |
| 4267 | if (UsingShadowDecl *FromPattern = |
| 4268 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4269 | if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern)) |
| 4270 | Importer.getToContext().setInstantiatedFromUsingShadowDecl( |
| 4271 | ToShadow, *ToPatternOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4272 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4273 | // FIXME: We return error here but the definition is already created |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4274 | // and available with lookups. How to fix this?.. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4275 | return ToPatternOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4276 | } |
| 4277 | |
| 4278 | LexicalDC->addDeclInternal(ToShadow); |
| 4279 | |
| 4280 | return ToShadow; |
| 4281 | } |
| 4282 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4283 | ExpectedDecl ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4284 | DeclContext *DC, *LexicalDC; |
| 4285 | DeclarationName Name; |
| 4286 | SourceLocation Loc; |
| 4287 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4288 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4289 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4290 | if (ToD) |
| 4291 | return ToD; |
| 4292 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4293 | auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor()); |
| 4294 | if (!ToComAncestorOrErr) |
| 4295 | return ToComAncestorOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4296 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4297 | NamespaceDecl *ToNominatedNamespace; |
| 4298 | SourceLocation ToUsingLoc, ToNamespaceKeyLocation, ToIdentLocation; |
| 4299 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4300 | if (auto Imp = importSeq( |
| 4301 | D->getNominatedNamespace(), D->getUsingLoc(), |
| 4302 | D->getNamespaceKeyLocation(), D->getQualifierLoc(), |
| 4303 | D->getIdentLocation())) |
| 4304 | std::tie( |
| 4305 | ToNominatedNamespace, ToUsingLoc, ToNamespaceKeyLocation, |
| 4306 | ToQualifierLoc, ToIdentLocation) = *Imp; |
| 4307 | else |
| 4308 | return Imp.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4309 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4310 | UsingDirectiveDecl *ToUsingDir; |
| 4311 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4312 | ToUsingLoc, |
| 4313 | ToNamespaceKeyLocation, |
| 4314 | ToQualifierLoc, |
| 4315 | ToIdentLocation, |
| 4316 | ToNominatedNamespace, *ToComAncestorOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4317 | return ToUsingDir; |
| 4318 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4319 | ToUsingDir->setLexicalDeclContext(LexicalDC); |
| 4320 | LexicalDC->addDeclInternal(ToUsingDir); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4321 | |
| 4322 | return ToUsingDir; |
| 4323 | } |
| 4324 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4325 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4326 | UnresolvedUsingValueDecl *D) { |
| 4327 | DeclContext *DC, *LexicalDC; |
| 4328 | DeclarationName Name; |
| 4329 | SourceLocation Loc; |
| 4330 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4331 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4332 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4333 | if (ToD) |
| 4334 | return ToD; |
| 4335 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4336 | SourceLocation ToLoc, ToUsingLoc, ToEllipsisLoc; |
| 4337 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4338 | if (auto Imp = importSeq( |
| 4339 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc(), |
| 4340 | D->getEllipsisLoc())) |
| 4341 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; |
| 4342 | else |
| 4343 | return Imp.takeError(); |
| 4344 | |
| 4345 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4346 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4347 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4348 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4349 | UnresolvedUsingValueDecl *ToUsingValue; |
| 4350 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4351 | ToUsingLoc, ToQualifierLoc, NameInfo, |
| 4352 | ToEllipsisLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4353 | return ToUsingValue; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4354 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4355 | ToUsingValue->setAccess(D->getAccess()); |
| 4356 | ToUsingValue->setLexicalDeclContext(LexicalDC); |
| 4357 | LexicalDC->addDeclInternal(ToUsingValue); |
| 4358 | |
| 4359 | return ToUsingValue; |
| 4360 | } |
| 4361 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4362 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4363 | UnresolvedUsingTypenameDecl *D) { |
| 4364 | DeclContext *DC, *LexicalDC; |
| 4365 | DeclarationName Name; |
| 4366 | SourceLocation Loc; |
| 4367 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4368 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4369 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4370 | if (ToD) |
| 4371 | return ToD; |
| 4372 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4373 | SourceLocation ToUsingLoc, ToTypenameLoc, ToEllipsisLoc; |
| 4374 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4375 | if (auto Imp = importSeq( |
| 4376 | D->getUsingLoc(), D->getTypenameLoc(), D->getQualifierLoc(), |
| 4377 | D->getEllipsisLoc())) |
| 4378 | std::tie(ToUsingLoc, ToTypenameLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; |
| 4379 | else |
| 4380 | return Imp.takeError(); |
| 4381 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4382 | UnresolvedUsingTypenameDecl *ToUsing; |
| 4383 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4384 | ToUsingLoc, ToTypenameLoc, |
| 4385 | ToQualifierLoc, Loc, Name, ToEllipsisLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4386 | return ToUsing; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4387 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4388 | ToUsing->setAccess(D->getAccess()); |
| 4389 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4390 | LexicalDC->addDeclInternal(ToUsing); |
| 4391 | |
| 4392 | return ToUsing; |
| 4393 | } |
| 4394 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4395 | |
| 4396 | Error ASTNodeImporter::ImportDefinition( |
| 4397 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4398 | if (To->getDefinition()) { |
| 4399 | // Check consistency of superclass. |
| 4400 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 4401 | if (FromSuper) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4402 | if (auto FromSuperOrErr = import(FromSuper)) |
| 4403 | FromSuper = *FromSuperOrErr; |
| 4404 | else |
| 4405 | return FromSuperOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4406 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4407 | |
| 4408 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4409 | if ((bool)FromSuper != (bool)ToSuper || |
| 4410 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4411 | Importer.ToDiag(To->getLocation(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4412 | diag::err_odr_objc_superclass_inconsistent) |
| 4413 | << To->getDeclName(); |
| 4414 | if (ToSuper) |
| 4415 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 4416 | << To->getSuperClass()->getDeclName(); |
| 4417 | else |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4418 | Importer.ToDiag(To->getLocation(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4419 | diag::note_odr_objc_missing_superclass); |
| 4420 | if (From->getSuperClass()) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4421 | Importer.FromDiag(From->getSuperClassLoc(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4422 | diag::note_odr_objc_superclass) |
| 4423 | << From->getSuperClass()->getDeclName(); |
| 4424 | else |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4425 | Importer.FromDiag(From->getLocation(), |
| 4426 | diag::note_odr_objc_missing_superclass); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4427 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4428 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4429 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4430 | if (Error Err = ImportDeclContext(From)) |
| 4431 | return Err; |
| 4432 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4433 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4434 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4435 | // Start the definition. |
| 4436 | To->startDefinition(); |
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 | // If this class has a superclass, import it. |
| 4439 | if (From->getSuperClass()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4440 | if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo())) |
| 4441 | To->setSuperClass(*SuperTInfoOrErr); |
| 4442 | else |
| 4443 | return SuperTInfoOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4444 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4445 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4446 | // Import protocols |
| 4447 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4448 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4449 | ObjCInterfaceDecl::protocol_loc_iterator FromProtoLoc = |
| 4450 | From->protocol_loc_begin(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4451 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4452 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4453 | FromProtoEnd = From->protocol_end(); |
| 4454 | FromProto != FromProtoEnd; |
| 4455 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4456 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4457 | Protocols.push_back(*ToProtoOrErr); |
| 4458 | else |
| 4459 | return ToProtoOrErr.takeError(); |
| 4460 | |
| 4461 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4462 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4463 | else |
| 4464 | return ToProtoLocOrErr.takeError(); |
| 4465 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4466 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4467 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4468 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4469 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4470 | ProtocolLocs.data(), Importer.getToContext()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4471 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4472 | // Import categories. When the categories themselves are imported, they'll |
| 4473 | // hook themselves into this interface. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4474 | for (auto *Cat : From->known_categories()) { |
| 4475 | auto ToCatOrErr = import(Cat); |
| 4476 | if (!ToCatOrErr) |
| 4477 | return ToCatOrErr.takeError(); |
| 4478 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4479 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4480 | // If we have an @implementation, import it as well. |
| 4481 | if (From->getImplementation()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4482 | if (Expected<ObjCImplementationDecl *> ToImplOrErr = |
| 4483 | import(From->getImplementation())) |
| 4484 | To->setImplementation(*ToImplOrErr); |
| 4485 | else |
| 4486 | return ToImplOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4487 | } |
| 4488 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4489 | if (shouldForceImportDeclContext(Kind)) { |
| 4490 | // Import all of the members of this class. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4491 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4492 | return Err; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4493 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4494 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4495 | } |
| 4496 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4497 | Expected<ObjCTypeParamList *> |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4498 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 4499 | if (!list) |
| 4500 | return nullptr; |
| 4501 | |
| 4502 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4503 | for (auto *fromTypeParam : *list) { |
| 4504 | if (auto toTypeParamOrErr = import(fromTypeParam)) |
| 4505 | toTypeParams.push_back(*toTypeParamOrErr); |
| 4506 | else |
| 4507 | return toTypeParamOrErr.takeError(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4508 | } |
| 4509 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4510 | auto LAngleLocOrErr = import(list->getLAngleLoc()); |
| 4511 | if (!LAngleLocOrErr) |
| 4512 | return LAngleLocOrErr.takeError(); |
| 4513 | |
| 4514 | auto RAngleLocOrErr = import(list->getRAngleLoc()); |
| 4515 | if (!RAngleLocOrErr) |
| 4516 | return RAngleLocOrErr.takeError(); |
| 4517 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4518 | return ObjCTypeParamList::create(Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4519 | *LAngleLocOrErr, |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4520 | toTypeParams, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4521 | *RAngleLocOrErr); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4522 | } |
| 4523 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4524 | ExpectedDecl ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4525 | // If this class has a definition in the translation unit we're coming from, |
| 4526 | // but this particular declaration is not that definition, import the |
| 4527 | // definition and map to that. |
| 4528 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 4529 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4530 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4531 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4532 | else |
| 4533 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4534 | } |
| 4535 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4536 | // Import the major distinguishing characteristics of an @interface. |
| 4537 | DeclContext *DC, *LexicalDC; |
| 4538 | DeclarationName Name; |
| 4539 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4540 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4541 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4542 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4543 | if (ToD) |
| 4544 | return ToD; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4545 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4546 | // Look for an existing interface with the same name. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4547 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4548 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4549 | for (auto *FoundDecl : FoundDecls) { |
| 4550 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4551 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4552 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4553 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4554 | break; |
| 4555 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4556 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4557 | // Create an interface declaration, if one does not already exist. |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4558 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4559 | if (!ToIface) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4560 | ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4561 | if (!AtBeginLocOrErr) |
| 4562 | return AtBeginLocOrErr.takeError(); |
| 4563 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4564 | if (GetImportedOrCreateDecl( |
| 4565 | ToIface, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4566 | *AtBeginLocOrErr, Name.getAsIdentifierInfo(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4567 | /*TypeParamList=*/nullptr, |
| 4568 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) |
| 4569 | return ToIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4570 | ToIface->setLexicalDeclContext(LexicalDC); |
| 4571 | LexicalDC->addDeclInternal(ToIface); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4572 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4573 | Importer.MapImported(D, ToIface); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4574 | // Import the type parameter list after MapImported, to avoid |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4575 | // loops when bringing in their DeclContext. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4576 | if (auto ToPListOrErr = |
| 4577 | ImportObjCTypeParamList(D->getTypeParamListAsWritten())) |
| 4578 | ToIface->setTypeParamList(*ToPListOrErr); |
| 4579 | else |
| 4580 | return ToPListOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4581 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4582 | if (D->isThisDeclarationADefinition()) |
| 4583 | if (Error Err = ImportDefinition(D, ToIface)) |
| 4584 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4585 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4586 | return ToIface; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4587 | } |
| 4588 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4589 | ExpectedDecl |
| 4590 | ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 4591 | ObjCCategoryDecl *Category; |
| 4592 | if (Error Err = importInto(Category, D->getCategoryDecl())) |
| 4593 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4594 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4595 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 4596 | if (!ToImpl) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4597 | DeclContext *DC, *LexicalDC; |
| 4598 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4599 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4600 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4601 | SourceLocation ToLocation, ToAtStartLoc, ToCategoryNameLoc; |
| 4602 | if (auto Imp = importSeq( |
| 4603 | D->getLocation(), D->getAtStartLoc(), D->getCategoryNameLoc())) |
| 4604 | std::tie(ToLocation, ToAtStartLoc, ToCategoryNameLoc) = *Imp; |
| 4605 | else |
| 4606 | return Imp.takeError(); |
| 4607 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4608 | if (GetImportedOrCreateDecl( |
| 4609 | ToImpl, D, Importer.getToContext(), DC, |
| 4610 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4611 | ToLocation, ToAtStartLoc, ToCategoryNameLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4612 | return ToImpl; |
| 4613 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4614 | ToImpl->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4615 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4616 | Category->setImplementation(ToImpl); |
| 4617 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4618 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4619 | Importer.MapImported(D, ToImpl); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4620 | if (Error Err = ImportDeclContext(D)) |
| 4621 | return std::move(Err); |
| 4622 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4623 | return ToImpl; |
| 4624 | } |
| 4625 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4626 | ExpectedDecl |
| 4627 | ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4628 | // Find the corresponding interface. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4629 | ObjCInterfaceDecl *Iface; |
| 4630 | if (Error Err = importInto(Iface, D->getClassInterface())) |
| 4631 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4632 | |
| 4633 | // Import the superclass, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4634 | ObjCInterfaceDecl *Super; |
| 4635 | if (Error Err = importInto(Super, D->getSuperClass())) |
| 4636 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4637 | |
| 4638 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 4639 | if (!Impl) { |
| 4640 | // We haven't imported an implementation yet. Create a new @implementation |
| 4641 | // now. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4642 | DeclContext *DC, *LexicalDC; |
| 4643 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4644 | return std::move(Err); |
| 4645 | |
| 4646 | SourceLocation ToLocation, ToAtStartLoc, ToSuperClassLoc; |
| 4647 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; |
| 4648 | if (auto Imp = importSeq( |
| 4649 | D->getLocation(), D->getAtStartLoc(), D->getSuperClassLoc(), |
| 4650 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) |
| 4651 | std::tie( |
| 4652 | ToLocation, ToAtStartLoc, ToSuperClassLoc, |
| 4653 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; |
| 4654 | else |
| 4655 | return Imp.takeError(); |
| 4656 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4657 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4658 | DC, Iface, Super, |
| 4659 | ToLocation, |
| 4660 | ToAtStartLoc, |
| 4661 | ToSuperClassLoc, |
| 4662 | ToIvarLBraceLoc, |
| 4663 | ToIvarRBraceLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4664 | return Impl; |
| 4665 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4666 | Impl->setLexicalDeclContext(LexicalDC); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4667 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4668 | // Associate the implementation with the class it implements. |
| 4669 | Iface->setImplementation(Impl); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4670 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4671 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4672 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4673 | |
| 4674 | // Verify that the existing @implementation has the same superclass. |
| 4675 | if ((Super && !Impl->getSuperClass()) || |
| 4676 | (!Super && Impl->getSuperClass()) || |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4677 | (Super && Impl->getSuperClass() && |
| 4678 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 4679 | Impl->getSuperClass()))) { |
| 4680 | Importer.ToDiag(Impl->getLocation(), |
| 4681 | diag::err_odr_objc_superclass_inconsistent) |
| 4682 | << Iface->getDeclName(); |
| 4683 | // FIXME: It would be nice to have the location of the superclass |
| 4684 | // below. |
| 4685 | if (Impl->getSuperClass()) |
| 4686 | Importer.ToDiag(Impl->getLocation(), |
| 4687 | diag::note_odr_objc_superclass) |
| 4688 | << Impl->getSuperClass()->getDeclName(); |
| 4689 | else |
| 4690 | Importer.ToDiag(Impl->getLocation(), |
| 4691 | diag::note_odr_objc_missing_superclass); |
| 4692 | if (D->getSuperClass()) |
| 4693 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4694 | diag::note_odr_objc_superclass) |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4695 | << D->getSuperClass()->getDeclName(); |
| 4696 | else |
| 4697 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4698 | diag::note_odr_objc_missing_superclass); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4699 | |
| 4700 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4701 | } |
| 4702 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4703 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4704 | // Import all of the members of this @implementation. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4705 | if (Error Err = ImportDeclContext(D)) |
| 4706 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4707 | |
| 4708 | return Impl; |
| 4709 | } |
| 4710 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4711 | ExpectedDecl ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4712 | // Import the major distinguishing characteristics of an @property. |
| 4713 | DeclContext *DC, *LexicalDC; |
| 4714 | DeclarationName Name; |
| 4715 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4716 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4717 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4718 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4719 | if (ToD) |
| 4720 | return ToD; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4721 | |
| 4722 | // Check whether we have already imported this property. |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4723 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4724 | for (auto *FoundDecl : FoundDecls) { |
| 4725 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4726 | // Check property types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4727 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4728 | FoundProp->getType())) { |
| 4729 | Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent) |
| 4730 | << Name << D->getType() << FoundProp->getType(); |
| 4731 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 4732 | << FoundProp->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4733 | |
| 4734 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4735 | } |
| 4736 | |
| 4737 | // FIXME: Check property attributes, getters, setters, etc.? |
| 4738 | |
| 4739 | // Consider these properties to be equivalent. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4740 | Importer.MapImported(D, FoundProp); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4741 | return FoundProp; |
| 4742 | } |
| 4743 | } |
| 4744 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4745 | QualType ToType; |
| 4746 | TypeSourceInfo *ToTypeSourceInfo; |
| 4747 | SourceLocation ToAtLoc, ToLParenLoc; |
| 4748 | if (auto Imp = importSeq( |
| 4749 | D->getType(), D->getTypeSourceInfo(), D->getAtLoc(), D->getLParenLoc())) |
| 4750 | std::tie(ToType, ToTypeSourceInfo, ToAtLoc, ToLParenLoc) = *Imp; |
| 4751 | else |
| 4752 | return Imp.takeError(); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4753 | |
| 4754 | // Create the new property. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4755 | ObjCPropertyDecl *ToProperty; |
| 4756 | if (GetImportedOrCreateDecl( |
| 4757 | ToProperty, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4758 | Name.getAsIdentifierInfo(), ToAtLoc, |
| 4759 | ToLParenLoc, ToType, |
| 4760 | ToTypeSourceInfo, D->getPropertyImplementation())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4761 | return ToProperty; |
| 4762 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4763 | Selector ToGetterName, ToSetterName; |
| 4764 | SourceLocation ToGetterNameLoc, ToSetterNameLoc; |
| 4765 | ObjCMethodDecl *ToGetterMethodDecl, *ToSetterMethodDecl; |
| 4766 | ObjCIvarDecl *ToPropertyIvarDecl; |
| 4767 | if (auto Imp = importSeq( |
| 4768 | D->getGetterName(), D->getSetterName(), |
| 4769 | D->getGetterNameLoc(), D->getSetterNameLoc(), |
| 4770 | D->getGetterMethodDecl(), D->getSetterMethodDecl(), |
| 4771 | D->getPropertyIvarDecl())) |
| 4772 | std::tie( |
| 4773 | ToGetterName, ToSetterName, |
| 4774 | ToGetterNameLoc, ToSetterNameLoc, |
| 4775 | ToGetterMethodDecl, ToSetterMethodDecl, |
| 4776 | ToPropertyIvarDecl) = *Imp; |
| 4777 | else |
| 4778 | return Imp.takeError(); |
| 4779 | |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4780 | ToProperty->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4781 | LexicalDC->addDeclInternal(ToProperty); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4782 | |
| 4783 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 4784 | ToProperty->setPropertyAttributesAsWritten( |
| 4785 | D->getPropertyAttributesAsWritten()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4786 | ToProperty->setGetterName(ToGetterName, ToGetterNameLoc); |
| 4787 | ToProperty->setSetterName(ToSetterName, ToSetterNameLoc); |
| 4788 | ToProperty->setGetterMethodDecl(ToGetterMethodDecl); |
| 4789 | ToProperty->setSetterMethodDecl(ToSetterMethodDecl); |
| 4790 | ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4791 | return ToProperty; |
| 4792 | } |
| 4793 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4794 | ExpectedDecl |
| 4795 | ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 4796 | ObjCPropertyDecl *Property; |
| 4797 | if (Error Err = importInto(Property, D->getPropertyDecl())) |
| 4798 | return std::move(Err); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4799 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4800 | DeclContext *DC, *LexicalDC; |
| 4801 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4802 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4803 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4804 | auto *InImpl = cast<ObjCImplDecl>(LexicalDC); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4805 | |
| 4806 | // Import the ivar (for an @synthesize). |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4807 | ObjCIvarDecl *Ivar = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4808 | if (Error Err = importInto(Ivar, D->getPropertyIvarDecl())) |
| 4809 | return std::move(Err); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4810 | |
| 4811 | ObjCPropertyImplDecl *ToImpl |
Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 4812 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 4813 | Property->getQueryKind()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4814 | if (!ToImpl) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4815 | SourceLocation ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc; |
| 4816 | if (auto Imp = importSeq( |
| 4817 | D->getBeginLoc(), D->getLocation(), D->getPropertyIvarDeclLoc())) |
| 4818 | std::tie(ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc) = *Imp; |
| 4819 | else |
| 4820 | return Imp.takeError(); |
| 4821 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4822 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4823 | ToBeginLoc, |
| 4824 | ToLocation, Property, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4825 | D->getPropertyImplementation(), Ivar, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4826 | ToPropertyIvarDeclLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4827 | return ToImpl; |
| 4828 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4829 | ToImpl->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4830 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4831 | } else { |
| 4832 | // Check that we have the same kind of property implementation (@synthesize |
| 4833 | // vs. @dynamic). |
| 4834 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4835 | Importer.ToDiag(ToImpl->getLocation(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4836 | diag::err_odr_objc_property_impl_kind_inconsistent) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4837 | << Property->getDeclName() |
| 4838 | << (ToImpl->getPropertyImplementation() |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4839 | == ObjCPropertyImplDecl::Dynamic); |
| 4840 | Importer.FromDiag(D->getLocation(), |
| 4841 | diag::note_odr_objc_property_impl_kind) |
| 4842 | << D->getPropertyDecl()->getDeclName() |
| 4843 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4844 | |
| 4845 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4846 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4847 | |
| 4848 | // For @synthesize, check that we have the same |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4849 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 4850 | Ivar != ToImpl->getPropertyIvarDecl()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4851 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4852 | diag::err_odr_objc_synthesize_ivar_inconsistent) |
| 4853 | << Property->getDeclName() |
| 4854 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 4855 | << Ivar->getDeclName(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4856 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4857 | diag::note_odr_objc_synthesize_ivar_here) |
| 4858 | << D->getPropertyIvarDecl()->getDeclName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4859 | |
| 4860 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4861 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4862 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4863 | // Merge the existing implementation with the new implementation. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4864 | Importer.MapImported(D, ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4865 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4866 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4867 | return ToImpl; |
| 4868 | } |
| 4869 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4870 | ExpectedDecl |
| 4871 | ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4872 | // For template arguments, we adopt the translation unit as our declaration |
| 4873 | // context. This context will be fixed when the actual template declaration |
| 4874 | // is created. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4875 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4876 | // FIXME: Import default argument. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4877 | |
| 4878 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 4879 | if (!BeginLocOrErr) |
| 4880 | return BeginLocOrErr.takeError(); |
| 4881 | |
| 4882 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 4883 | if (!LocationOrErr) |
| 4884 | return LocationOrErr.takeError(); |
| 4885 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4886 | TemplateTypeParmDecl *ToD = nullptr; |
| 4887 | (void)GetImportedOrCreateDecl( |
| 4888 | ToD, D, Importer.getToContext(), |
| 4889 | Importer.getToContext().getTranslationUnitDecl(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4890 | *BeginLocOrErr, *LocationOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4891 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), |
| 4892 | D->wasDeclaredWithTypename(), D->isParameterPack()); |
| 4893 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4894 | } |
| 4895 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4896 | ExpectedDecl |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4897 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4898 | DeclarationName ToDeclName; |
| 4899 | SourceLocation ToLocation, ToInnerLocStart; |
| 4900 | QualType ToType; |
| 4901 | TypeSourceInfo *ToTypeSourceInfo; |
| 4902 | if (auto Imp = importSeq( |
| 4903 | D->getDeclName(), D->getLocation(), D->getType(), D->getTypeSourceInfo(), |
| 4904 | D->getInnerLocStart())) |
| 4905 | std::tie( |
| 4906 | ToDeclName, ToLocation, ToType, ToTypeSourceInfo, |
| 4907 | ToInnerLocStart) = *Imp; |
| 4908 | else |
| 4909 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4910 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4911 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4912 | |
| 4913 | NonTypeTemplateParmDecl *ToD = nullptr; |
| 4914 | (void)GetImportedOrCreateDecl( |
| 4915 | ToD, D, Importer.getToContext(), |
| 4916 | Importer.getToContext().getTranslationUnitDecl(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4917 | ToInnerLocStart, ToLocation, D->getDepth(), |
| 4918 | D->getPosition(), ToDeclName.getAsIdentifierInfo(), ToType, |
| 4919 | D->isParameterPack(), ToTypeSourceInfo); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4920 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4921 | } |
| 4922 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4923 | ExpectedDecl |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4924 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 4925 | // Import the name of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4926 | auto NameOrErr = import(D->getDeclName()); |
| 4927 | if (!NameOrErr) |
| 4928 | return NameOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4929 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4930 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4931 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 4932 | if (!LocationOrErr) |
| 4933 | return LocationOrErr.takeError(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4934 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4935 | // Import template parameters. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4936 | auto TemplateParamsOrErr = ImportTemplateParameterList( |
| 4937 | D->getTemplateParameters()); |
| 4938 | if (!TemplateParamsOrErr) |
| 4939 | return TemplateParamsOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4940 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4941 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4942 | |
| 4943 | TemplateTemplateParmDecl *ToD = nullptr; |
| 4944 | (void)GetImportedOrCreateDecl( |
| 4945 | ToD, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4946 | Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr, |
| 4947 | D->getDepth(), D->getPosition(), D->isParameterPack(), |
| 4948 | (*NameOrErr).getAsIdentifierInfo(), |
| 4949 | *TemplateParamsOrErr); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4950 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4951 | } |
| 4952 | |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4953 | // Returns the definition for a (forward) declaration of a ClassTemplateDecl, if |
| 4954 | // it has any definition in the redecl chain. |
| 4955 | static ClassTemplateDecl *getDefinition(ClassTemplateDecl *D) { |
| 4956 | CXXRecordDecl *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); |
| 4957 | if (!ToTemplatedDef) |
| 4958 | return nullptr; |
| 4959 | ClassTemplateDecl *TemplateWithDef = |
| 4960 | ToTemplatedDef->getDescribedClassTemplate(); |
| 4961 | return TemplateWithDef; |
| 4962 | } |
| 4963 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4964 | ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4965 | bool IsFriend = D->getFriendObjectKind() != Decl::FOK_None; |
| 4966 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4967 | // If this template has a definition in the translation unit we're coming |
| 4968 | // from, but this particular declaration is not that definition, import the |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4969 | // definition and map to that. |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4970 | ClassTemplateDecl *Definition = getDefinition(D); |
| 4971 | if (Definition && Definition != D && !IsFriend) { |
| 4972 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4973 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4974 | else |
| 4975 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4976 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4977 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4978 | // Import the major distinguishing characteristics of this class template. |
| 4979 | DeclContext *DC, *LexicalDC; |
| 4980 | DeclarationName Name; |
| 4981 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4982 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4983 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4984 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4985 | if (ToD) |
| 4986 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4987 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4988 | ClassTemplateDecl *FoundByLookup = nullptr; |
| 4989 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4990 | // We may already have a template of the same name; try to find and match it. |
| 4991 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4992 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4993 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4994 | for (auto *FoundDecl : FoundDecls) { |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4995 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary | |
| 4996 | Decl::IDNS_TagFriend)) |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4997 | continue; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4998 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4999 | Decl *Found = FoundDecl; |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5000 | auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found); |
| 5001 | if (FoundTemplate) { |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5002 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5003 | if (IsStructuralMatch(D, FoundTemplate)) { |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5004 | ClassTemplateDecl *TemplateWithDef = getDefinition(FoundTemplate); |
| 5005 | if (D->isThisDeclarationADefinition() && TemplateWithDef) { |
| 5006 | return Importer.MapImported(D, TemplateWithDef); |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5007 | } |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5008 | FoundByLookup = FoundTemplate; |
| 5009 | break; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5010 | } |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5011 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5012 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5013 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5014 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5015 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5016 | if (!ConflictingDecls.empty()) { |
| 5017 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5018 | ConflictingDecls.data(), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5019 | ConflictingDecls.size()); |
| 5020 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5021 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5022 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5023 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5024 | } |
| 5025 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5026 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); |
| 5027 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5028 | // Create the declaration that is being templated. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5029 | CXXRecordDecl *ToTemplated; |
| 5030 | if (Error Err = importInto(ToTemplated, FromTemplated)) |
| 5031 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5032 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5033 | // Create the class template declaration itself. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5034 | auto TemplateParamsOrErr = ImportTemplateParameterList( |
| 5035 | D->getTemplateParameters()); |
| 5036 | if (!TemplateParamsOrErr) |
| 5037 | return TemplateParamsOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5038 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5039 | ClassTemplateDecl *D2; |
| 5040 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5041 | *TemplateParamsOrErr, ToTemplated)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5042 | return D2; |
| 5043 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5044 | ToTemplated->setDescribedClassTemplate(D2); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5045 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5046 | D2->setAccess(D->getAccess()); |
| 5047 | D2->setLexicalDeclContext(LexicalDC); |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5048 | |
| 5049 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 5050 | DC->addDeclInternal(D2); |
| 5051 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5052 | LexicalDC->addDeclInternal(D2); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5053 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5054 | if (FoundByLookup) { |
| 5055 | auto *Recent = |
| 5056 | const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl()); |
| 5057 | |
| 5058 | // It is possible that during the import of the class template definition |
| 5059 | // we start the import of a fwd friend decl of the very same class template |
| 5060 | // and we add the fwd friend decl to the lookup table. But the ToTemplated |
| 5061 | // had been created earlier and by that time the lookup could not find |
| 5062 | // anything existing, so it has no previous decl. Later, (still during the |
| 5063 | // import of the fwd friend decl) we start to import the definition again |
| 5064 | // and this time the lookup finds the previous fwd friend class template. |
| 5065 | // In this case we must set up the previous decl for the templated decl. |
| 5066 | if (!ToTemplated->getPreviousDecl()) { |
| 5067 | CXXRecordDecl *PrevTemplated = |
| 5068 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); |
| 5069 | if (ToTemplated != PrevTemplated) |
| 5070 | ToTemplated->setPreviousDecl(PrevTemplated); |
| 5071 | } |
| 5072 | |
| 5073 | D2->setPreviousDecl(Recent); |
| 5074 | } |
| 5075 | |
| 5076 | if (LexicalDC != DC && IsFriend) |
| 5077 | DC->makeDeclVisibleInContext(D2); |
| 5078 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5079 | if (FromTemplated->isCompleteDefinition() && |
| 5080 | !ToTemplated->isCompleteDefinition()) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5081 | // FIXME: Import definition! |
| 5082 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5083 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5084 | return D2; |
| 5085 | } |
| 5086 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5087 | ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5088 | ClassTemplateSpecializationDecl *D) { |
| 5089 | // If this record has a definition in the translation unit we're coming from, |
| 5090 | // but this particular declaration is not that definition, import the |
| 5091 | // definition and map to that. |
| 5092 | TagDecl *Definition = D->getDefinition(); |
| 5093 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5094 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 5095 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5096 | else |
| 5097 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5098 | } |
| 5099 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5100 | ClassTemplateDecl *ClassTemplate; |
| 5101 | if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate())) |
| 5102 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5103 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5104 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5105 | DeclContext *DC, *LexicalDC; |
| 5106 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5107 | return std::move(Err); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5108 | |
| 5109 | // Import template arguments. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5110 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5111 | if (Error Err = ImportTemplateArguments( |
| 5112 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5113 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5114 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5115 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5116 | void *InsertPos = nullptr; |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5117 | ClassTemplateSpecializationDecl *D2 = nullptr; |
| 5118 | ClassTemplatePartialSpecializationDecl *PartialSpec = |
| 5119 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D); |
| 5120 | if (PartialSpec) |
| 5121 | D2 = ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos); |
| 5122 | else |
| 5123 | D2 = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
| 5124 | ClassTemplateSpecializationDecl * const PrevDecl = D2; |
| 5125 | RecordDecl *FoundDef = D2 ? D2->getDefinition() : nullptr; |
| 5126 | if (FoundDef) { |
| 5127 | if (!D->isCompleteDefinition()) { |
| 5128 | // The "From" translation unit only had a forward declaration; call it |
| 5129 | // the same declaration. |
| 5130 | // TODO Handle the redecl chain properly! |
| 5131 | return Importer.MapImported(D, FoundDef); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5132 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5133 | |
| 5134 | if (IsStructuralMatch(D, FoundDef)) { |
| 5135 | |
| 5136 | Importer.MapImported(D, FoundDef); |
| 5137 | |
| 5138 | // Import those those default field initializers which have been |
| 5139 | // instantiated in the "From" context, but not in the "To" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5140 | for (auto *FromField : D->fields()) { |
| 5141 | auto ToOrErr = import(FromField); |
| 5142 | if (!ToOrErr) |
| 5143 | // FIXME: return the error? |
| 5144 | consumeError(ToOrErr.takeError()); |
| 5145 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5146 | |
| 5147 | // Import those methods which have been instantiated in the |
| 5148 | // "From" context, but not in the "To" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5149 | for (CXXMethodDecl *FromM : D->methods()) { |
| 5150 | auto ToOrErr = import(FromM); |
| 5151 | if (!ToOrErr) |
| 5152 | // FIXME: return the error? |
| 5153 | consumeError(ToOrErr.takeError()); |
| 5154 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5155 | |
| 5156 | // TODO Import instantiated default arguments. |
| 5157 | // TODO Import instantiated exception specifications. |
| 5158 | // |
| 5159 | // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint what |
| 5160 | // else could be fused during an AST merge. |
| 5161 | |
| 5162 | return FoundDef; |
| 5163 | } |
| 5164 | } else { // We either couldn't find any previous specialization in the "To" |
| 5165 | // context, or we found one but without definition. Let's create a |
| 5166 | // new specialization and register that at the class template. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5167 | |
| 5168 | // Import the location of this declaration. |
| 5169 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5170 | if (!BeginLocOrErr) |
| 5171 | return BeginLocOrErr.takeError(); |
| 5172 | ExpectedSLoc IdLocOrErr = import(D->getLocation()); |
| 5173 | if (!IdLocOrErr) |
| 5174 | return IdLocOrErr.takeError(); |
| 5175 | |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5176 | if (PartialSpec) { |
| 5177 | // Import TemplateArgumentListInfo. |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5178 | TemplateArgumentListInfo ToTAInfo; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5179 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5180 | if (Error Err = ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) |
| 5181 | return std::move(Err); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5182 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5183 | QualType CanonInjType; |
| 5184 | if (Error Err = importInto( |
| 5185 | CanonInjType, PartialSpec->getInjectedSpecializationType())) |
| 5186 | return std::move(Err); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5187 | CanonInjType = CanonInjType.getCanonicalType(); |
| 5188 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5189 | auto ToTPListOrErr = ImportTemplateParameterList( |
| 5190 | PartialSpec->getTemplateParameters()); |
| 5191 | if (!ToTPListOrErr) |
| 5192 | return ToTPListOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5193 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5194 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5195 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| 5196 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, ClassTemplate, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5197 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5198 | ToTAInfo, CanonInjType, |
| 5199 | cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl))) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5200 | return D2; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5201 | |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5202 | // Update InsertPos, because preceding import calls may have invalidated |
| 5203 | // it by adding new specializations. |
| 5204 | if (!ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos)) |
| 5205 | // Add this partial specialization to the class template. |
| 5206 | ClassTemplate->AddPartialSpecialization( |
| 5207 | cast<ClassTemplatePartialSpecializationDecl>(D2), InsertPos); |
| 5208 | |
| 5209 | } else { // Not a partial specialization. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5210 | if (GetImportedOrCreateDecl( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5211 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| 5212 | *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs, |
| 5213 | PrevDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5214 | return D2; |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5215 | |
| 5216 | // Update InsertPos, because preceding import calls may have invalidated |
| 5217 | // it by adding new specializations. |
| 5218 | if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos)) |
| 5219 | // Add this specialization to the class template. |
| 5220 | ClassTemplate->AddSpecialization(D2, InsertPos); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5221 | } |
| 5222 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5223 | D2->setSpecializationKind(D->getSpecializationKind()); |
| 5224 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5225 | // Import the qualifier, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5226 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5227 | D2->setQualifierInfo(*LocOrErr); |
| 5228 | else |
| 5229 | return LocOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5230 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5231 | if (auto *TSI = D->getTypeAsWritten()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5232 | if (auto TInfoOrErr = import(TSI)) |
| 5233 | D2->setTypeAsWritten(*TInfoOrErr); |
| 5234 | else |
| 5235 | return TInfoOrErr.takeError(); |
| 5236 | |
| 5237 | if (auto LocOrErr = import(D->getTemplateKeywordLoc())) |
| 5238 | D2->setTemplateKeywordLoc(*LocOrErr); |
| 5239 | else |
| 5240 | return LocOrErr.takeError(); |
| 5241 | |
| 5242 | if (auto LocOrErr = import(D->getExternLoc())) |
| 5243 | D2->setExternLoc(*LocOrErr); |
| 5244 | else |
| 5245 | return LocOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5246 | } |
| 5247 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5248 | if (D->getPointOfInstantiation().isValid()) { |
| 5249 | if (auto POIOrErr = import(D->getPointOfInstantiation())) |
| 5250 | D2->setPointOfInstantiation(*POIOrErr); |
| 5251 | else |
| 5252 | return POIOrErr.takeError(); |
| 5253 | } |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5254 | |
| 5255 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 5256 | |
Gabor Marton | b14056b | 2018-05-25 11:21:24 +0000 | [diff] [blame] | 5257 | // Set the context of this specialization/instantiation. |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5258 | D2->setLexicalDeclContext(LexicalDC); |
Gabor Marton | b14056b | 2018-05-25 11:21:24 +0000 | [diff] [blame] | 5259 | |
| 5260 | // Add to the DC only if it was an explicit specialization/instantiation. |
| 5261 | if (D2->isExplicitInstantiationOrSpecialization()) { |
| 5262 | LexicalDC->addDeclInternal(D2); |
| 5263 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5264 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5265 | if (D->isCompleteDefinition()) |
| 5266 | if (Error Err = ImportDefinition(D, D2)) |
| 5267 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5268 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5269 | return D2; |
| 5270 | } |
| 5271 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5272 | ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5273 | // If this variable has a definition in the translation unit we're coming |
| 5274 | // from, |
| 5275 | // but this particular declaration is not that definition, import the |
| 5276 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5277 | auto *Definition = |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5278 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); |
| 5279 | if (Definition && Definition != D->getTemplatedDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5280 | if (ExpectedDecl ImportedDefOrErr = import( |
| 5281 | Definition->getDescribedVarTemplate())) |
| 5282 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5283 | else |
| 5284 | return ImportedDefOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5285 | } |
| 5286 | |
| 5287 | // Import the major distinguishing characteristics of this variable template. |
| 5288 | DeclContext *DC, *LexicalDC; |
| 5289 | DeclarationName Name; |
| 5290 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5291 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5292 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5293 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5294 | if (ToD) |
| 5295 | return ToD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5296 | |
| 5297 | // We may already have a template of the same name; try to find and match it. |
| 5298 | assert(!DC->isFunctionOrMethod() && |
| 5299 | "Variable templates cannot be declared at function scope"); |
| 5300 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5301 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5302 | for (auto *FoundDecl : FoundDecls) { |
| 5303 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5304 | continue; |
| 5305 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5306 | Decl *Found = FoundDecl; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5307 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5308 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 5309 | // The variable templates structurally match; call it the same template. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5310 | Importer.MapImported(D->getTemplatedDecl(), |
| 5311 | FoundTemplate->getTemplatedDecl()); |
| 5312 | return Importer.MapImported(D, FoundTemplate); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5313 | } |
| 5314 | } |
| 5315 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5316 | ConflictingDecls.push_back(FoundDecl); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5317 | } |
| 5318 | |
| 5319 | if (!ConflictingDecls.empty()) { |
| 5320 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 5321 | ConflictingDecls.data(), |
| 5322 | ConflictingDecls.size()); |
| 5323 | } |
| 5324 | |
| 5325 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5326 | // FIXME: Is it possible to get other error than name conflict? |
| 5327 | // (Put this `if` into the previous `if`?) |
| 5328 | return make_error<ImportError>(ImportError::NameConflict); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5329 | |
| 5330 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 5331 | |
| 5332 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5333 | // FIXME: Value not used? |
| 5334 | ExpectedType TypeOrErr = import(DTemplated->getType()); |
| 5335 | if (!TypeOrErr) |
| 5336 | return TypeOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5337 | |
| 5338 | // Create the declaration that is being templated. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5339 | VarDecl *ToTemplated; |
| 5340 | if (Error Err = importInto(ToTemplated, DTemplated)) |
| 5341 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5342 | |
| 5343 | // Create the variable template declaration itself. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5344 | auto TemplateParamsOrErr = ImportTemplateParameterList( |
| 5345 | D->getTemplateParameters()); |
| 5346 | if (!TemplateParamsOrErr) |
| 5347 | return TemplateParamsOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5348 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5349 | VarTemplateDecl *ToVarTD; |
| 5350 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5351 | Name, *TemplateParamsOrErr, ToTemplated)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5352 | return ToVarTD; |
| 5353 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5354 | ToTemplated->setDescribedVarTemplate(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5355 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5356 | ToVarTD->setAccess(D->getAccess()); |
| 5357 | ToVarTD->setLexicalDeclContext(LexicalDC); |
| 5358 | LexicalDC->addDeclInternal(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5359 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5360 | if (DTemplated->isThisDeclarationADefinition() && |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5361 | !ToTemplated->isThisDeclarationADefinition()) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5362 | // FIXME: Import definition! |
| 5363 | } |
| 5364 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5365 | return ToVarTD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5366 | } |
| 5367 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5368 | ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5369 | VarTemplateSpecializationDecl *D) { |
| 5370 | // If this record has a definition in the translation unit we're coming from, |
| 5371 | // but this particular declaration is not that definition, import the |
| 5372 | // definition and map to that. |
| 5373 | VarDecl *Definition = D->getDefinition(); |
| 5374 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5375 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 5376 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5377 | else |
| 5378 | return ImportedDefOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5379 | } |
| 5380 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5381 | VarTemplateDecl *VarTemplate; |
| 5382 | if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate())) |
| 5383 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5384 | |
| 5385 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5386 | DeclContext *DC, *LexicalDC; |
| 5387 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5388 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5389 | |
| 5390 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5391 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5392 | if (!BeginLocOrErr) |
| 5393 | return BeginLocOrErr.takeError(); |
| 5394 | |
| 5395 | auto IdLocOrErr = import(D->getLocation()); |
| 5396 | if (!IdLocOrErr) |
| 5397 | return IdLocOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5398 | |
| 5399 | // Import template arguments. |
| 5400 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5401 | if (Error Err = ImportTemplateArguments( |
| 5402 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5403 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5404 | |
| 5405 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5406 | void *InsertPos = nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5407 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 5408 | TemplateArgs, InsertPos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5409 | if (D2) { |
| 5410 | // We already have a variable template specialization with these template |
| 5411 | // arguments. |
| 5412 | |
| 5413 | // FIXME: Check for specialization vs. instantiation errors. |
| 5414 | |
| 5415 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 5416 | if (!D->isThisDeclarationADefinition() || |
| 5417 | IsStructuralMatch(D, FoundDef)) { |
| 5418 | // The record types structurally match, or the "from" translation |
| 5419 | // unit only had a forward declaration anyway; call it the same |
| 5420 | // variable. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5421 | return Importer.MapImported(D, FoundDef); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5422 | } |
| 5423 | } |
| 5424 | } else { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5425 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5426 | QualType T; |
| 5427 | if (Error Err = importInto(T, D->getType())) |
| 5428 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5429 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5430 | auto TInfoOrErr = import(D->getTypeSourceInfo()); |
| 5431 | if (!TInfoOrErr) |
| 5432 | return TInfoOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5433 | |
| 5434 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5435 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5436 | D->getTemplateArgsInfo(), ToTAInfo)) |
| 5437 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5438 | |
| 5439 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5440 | // Create a new specialization. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5441 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { |
| 5442 | // Import TemplateArgumentListInfo |
| 5443 | TemplateArgumentListInfo ArgInfos; |
| 5444 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); |
| 5445 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5446 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5447 | *FromTAArgsAsWritten, ArgInfos)) |
| 5448 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5449 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5450 | auto ToTPListOrErr = ImportTemplateParameterList( |
| 5451 | FromPartial->getTemplateParameters()); |
| 5452 | if (!ToTPListOrErr) |
| 5453 | return ToTPListOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5454 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5455 | PartVarSpecDecl *ToPartial; |
| 5456 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5457 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, |
| 5458 | VarTemplate, T, *TInfoOrErr, |
| 5459 | D->getStorageClass(), TemplateArgs, ArgInfos)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5460 | return ToPartial; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5461 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5462 | if (Expected<PartVarSpecDecl *> ToInstOrErr = import( |
| 5463 | FromPartial->getInstantiatedFromMember())) |
| 5464 | ToPartial->setInstantiatedFromMember(*ToInstOrErr); |
| 5465 | else |
| 5466 | return ToInstOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5467 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5468 | if (FromPartial->isMemberSpecialization()) |
| 5469 | ToPartial->setMemberSpecialization(); |
| 5470 | |
| 5471 | D2 = ToPartial; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5472 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5473 | } else { // Full specialization |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5474 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, |
| 5475 | *BeginLocOrErr, *IdLocOrErr, VarTemplate, |
| 5476 | T, *TInfoOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5477 | D->getStorageClass(), TemplateArgs)) |
| 5478 | return D2; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5479 | } |
| 5480 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5481 | if (D->getPointOfInstantiation().isValid()) { |
| 5482 | if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation())) |
| 5483 | D2->setPointOfInstantiation(*POIOrErr); |
| 5484 | else |
| 5485 | return POIOrErr.takeError(); |
| 5486 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5487 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5488 | D2->setSpecializationKind(D->getSpecializationKind()); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5489 | D2->setTemplateArgsInfo(ToTAInfo); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5490 | |
| 5491 | // Add this specialization to the class template. |
| 5492 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 5493 | |
| 5494 | // Import the qualifier, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5495 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5496 | D2->setQualifierInfo(*LocOrErr); |
| 5497 | else |
| 5498 | return LocOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5499 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5500 | if (D->isConstexpr()) |
| 5501 | D2->setConstexpr(true); |
| 5502 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5503 | // Add the specialization to this context. |
| 5504 | D2->setLexicalDeclContext(LexicalDC); |
| 5505 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5506 | |
| 5507 | D2->setAccess(D->getAccess()); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5508 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5509 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5510 | if (Error Err = ImportInitializer(D, D2)) |
| 5511 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5512 | |
| 5513 | return D2; |
| 5514 | } |
| 5515 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5516 | ExpectedDecl |
| 5517 | ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5518 | DeclContext *DC, *LexicalDC; |
| 5519 | DeclarationName Name; |
| 5520 | SourceLocation Loc; |
| 5521 | NamedDecl *ToD; |
| 5522 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5523 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5524 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5525 | |
| 5526 | if (ToD) |
| 5527 | return ToD; |
| 5528 | |
| 5529 | // Try to find a function in our own ("to") context with the same name, same |
| 5530 | // type, and in the same context as the function we're importing. |
| 5531 | if (!LexicalDC->isFunctionOrMethod()) { |
| 5532 | unsigned IDNS = Decl::IDNS_Ordinary; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5533 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5534 | for (auto *FoundDecl : FoundDecls) { |
| 5535 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5536 | continue; |
| 5537 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5538 | if (auto *FoundFunction = |
| 5539 | dyn_cast<FunctionTemplateDecl>(FoundDecl)) { |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5540 | if (FoundFunction->hasExternalFormalLinkage() && |
| 5541 | D->hasExternalFormalLinkage()) { |
| 5542 | if (IsStructuralMatch(D, FoundFunction)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5543 | Importer.MapImported(D, FoundFunction); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5544 | // FIXME: Actually try to merge the body and other attributes. |
| 5545 | return FoundFunction; |
| 5546 | } |
| 5547 | } |
| 5548 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5549 | // TODO: handle conflicting names |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5550 | } |
| 5551 | } |
| 5552 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5553 | auto ParamsOrErr = ImportTemplateParameterList( |
| 5554 | D->getTemplateParameters()); |
| 5555 | if (!ParamsOrErr) |
| 5556 | return ParamsOrErr.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5557 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5558 | FunctionDecl *TemplatedFD; |
| 5559 | if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl())) |
| 5560 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5561 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5562 | FunctionTemplateDecl *ToFunc; |
| 5563 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5564 | *ParamsOrErr, TemplatedFD)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5565 | return ToFunc; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5566 | |
| 5567 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); |
| 5568 | ToFunc->setAccess(D->getAccess()); |
| 5569 | ToFunc->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5570 | |
| 5571 | LexicalDC->addDeclInternal(ToFunc); |
| 5572 | return ToFunc; |
| 5573 | } |
| 5574 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5575 | //---------------------------------------------------------------------------- |
| 5576 | // Import Statements |
| 5577 | //---------------------------------------------------------------------------- |
| 5578 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5579 | ExpectedStmt ASTNodeImporter::VisitStmt(Stmt *S) { |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5580 | Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node) |
| 5581 | << S->getStmtClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5582 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5583 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5584 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5585 | |
| 5586 | ExpectedStmt ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5587 | SmallVector<IdentifierInfo *, 4> Names; |
| 5588 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 5589 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5590 | // ToII is nullptr when no symbolic name is given for output operand |
| 5591 | // see ParseStmtAsm::ParseAsmOperandsOpt |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5592 | Names.push_back(ToII); |
| 5593 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5594 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5595 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 5596 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5597 | // ToII is nullptr when no symbolic name is given for input operand |
| 5598 | // see ParseStmtAsm::ParseAsmOperandsOpt |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5599 | Names.push_back(ToII); |
| 5600 | } |
| 5601 | |
| 5602 | SmallVector<StringLiteral *, 4> Clobbers; |
| 5603 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5604 | if (auto ClobberOrErr = import(S->getClobberStringLiteral(I))) |
| 5605 | Clobbers.push_back(*ClobberOrErr); |
| 5606 | else |
| 5607 | return ClobberOrErr.takeError(); |
| 5608 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5609 | } |
| 5610 | |
| 5611 | SmallVector<StringLiteral *, 4> Constraints; |
| 5612 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5613 | if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I))) |
| 5614 | Constraints.push_back(*OutputOrErr); |
| 5615 | else |
| 5616 | return OutputOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5617 | } |
| 5618 | |
| 5619 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5620 | if (auto InputOrErr = import(S->getInputConstraintLiteral(I))) |
| 5621 | Constraints.push_back(*InputOrErr); |
| 5622 | else |
| 5623 | return InputOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5624 | } |
| 5625 | |
| 5626 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5627 | if (Error Err = ImportContainerChecked(S->outputs(), Exprs)) |
| 5628 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5629 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5630 | if (Error Err = ImportArrayChecked( |
| 5631 | S->inputs(), Exprs.begin() + S->getNumOutputs())) |
| 5632 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5633 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5634 | ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc()); |
| 5635 | if (!AsmLocOrErr) |
| 5636 | return AsmLocOrErr.takeError(); |
| 5637 | auto AsmStrOrErr = import(S->getAsmString()); |
| 5638 | if (!AsmStrOrErr) |
| 5639 | return AsmStrOrErr.takeError(); |
| 5640 | ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc()); |
| 5641 | if (!RParenLocOrErr) |
| 5642 | return RParenLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5643 | |
| 5644 | return new (Importer.getToContext()) GCCAsmStmt( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5645 | Importer.getToContext(), |
| 5646 | *AsmLocOrErr, |
| 5647 | S->isSimple(), |
| 5648 | S->isVolatile(), |
| 5649 | S->getNumOutputs(), |
| 5650 | S->getNumInputs(), |
| 5651 | Names.data(), |
| 5652 | Constraints.data(), |
| 5653 | Exprs.data(), |
| 5654 | *AsmStrOrErr, |
| 5655 | S->getNumClobbers(), |
| 5656 | Clobbers.data(), |
| 5657 | *RParenLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5658 | } |
| 5659 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5660 | ExpectedStmt ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| 5661 | auto Imp = importSeq(S->getDeclGroup(), S->getBeginLoc(), S->getEndLoc()); |
| 5662 | if (!Imp) |
| 5663 | return Imp.takeError(); |
| 5664 | |
| 5665 | DeclGroupRef ToDG; |
| 5666 | SourceLocation ToBeginLoc, ToEndLoc; |
| 5667 | std::tie(ToDG, ToBeginLoc, ToEndLoc) = *Imp; |
| 5668 | |
| 5669 | return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5670 | } |
| 5671 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5672 | ExpectedStmt ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 5673 | ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc()); |
| 5674 | if (!ToSemiLocOrErr) |
| 5675 | return ToSemiLocOrErr.takeError(); |
| 5676 | return new (Importer.getToContext()) NullStmt( |
| 5677 | *ToSemiLocOrErr, S->hasLeadingEmptyMacro()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5678 | } |
| 5679 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5680 | ExpectedStmt ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5681 | SmallVector<Stmt *, 8> ToStmts(S->size()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5682 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5683 | if (Error Err = ImportContainerChecked(S->body(), ToStmts)) |
| 5684 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5685 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5686 | ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc()); |
| 5687 | if (!ToLBracLocOrErr) |
| 5688 | return ToLBracLocOrErr.takeError(); |
| 5689 | |
| 5690 | ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc()); |
| 5691 | if (!ToRBracLocOrErr) |
| 5692 | return ToRBracLocOrErr.takeError(); |
| 5693 | |
| 5694 | return CompoundStmt::Create( |
| 5695 | Importer.getToContext(), ToStmts, |
| 5696 | *ToLBracLocOrErr, *ToRBracLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5697 | } |
| 5698 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5699 | ExpectedStmt ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| 5700 | auto Imp = importSeq( |
| 5701 | S->getLHS(), S->getRHS(), S->getSubStmt(), S->getCaseLoc(), |
| 5702 | S->getEllipsisLoc(), S->getColonLoc()); |
| 5703 | if (!Imp) |
| 5704 | return Imp.takeError(); |
| 5705 | |
| 5706 | Expr *ToLHS, *ToRHS; |
| 5707 | Stmt *ToSubStmt; |
| 5708 | SourceLocation ToCaseLoc, ToEllipsisLoc, ToColonLoc; |
| 5709 | std::tie(ToLHS, ToRHS, ToSubStmt, ToCaseLoc, ToEllipsisLoc, ToColonLoc) = |
| 5710 | *Imp; |
| 5711 | |
Bruno Ricci | 5b3057175 | 2018-10-28 12:30:53 +0000 | [diff] [blame] | 5712 | auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS, |
| 5713 | ToCaseLoc, ToEllipsisLoc, ToColonLoc); |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5714 | ToStmt->setSubStmt(ToSubStmt); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5715 | |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5716 | return ToStmt; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5717 | } |
| 5718 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5719 | ExpectedStmt ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| 5720 | auto Imp = importSeq(S->getDefaultLoc(), S->getColonLoc(), S->getSubStmt()); |
| 5721 | if (!Imp) |
| 5722 | return Imp.takeError(); |
| 5723 | |
| 5724 | SourceLocation ToDefaultLoc, ToColonLoc; |
| 5725 | Stmt *ToSubStmt; |
| 5726 | std::tie(ToDefaultLoc, ToColonLoc, ToSubStmt) = *Imp; |
| 5727 | |
| 5728 | return new (Importer.getToContext()) DefaultStmt( |
| 5729 | ToDefaultLoc, ToColonLoc, ToSubStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5730 | } |
| 5731 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5732 | ExpectedStmt ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| 5733 | auto Imp = importSeq(S->getIdentLoc(), S->getDecl(), S->getSubStmt()); |
| 5734 | if (!Imp) |
| 5735 | return Imp.takeError(); |
| 5736 | |
| 5737 | SourceLocation ToIdentLoc; |
| 5738 | LabelDecl *ToLabelDecl; |
| 5739 | Stmt *ToSubStmt; |
| 5740 | std::tie(ToIdentLoc, ToLabelDecl, ToSubStmt) = *Imp; |
| 5741 | |
| 5742 | return new (Importer.getToContext()) LabelStmt( |
| 5743 | ToIdentLoc, ToLabelDecl, ToSubStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5744 | } |
| 5745 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5746 | ExpectedStmt ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { |
| 5747 | ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc()); |
| 5748 | if (!ToAttrLocOrErr) |
| 5749 | return ToAttrLocOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5750 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 5751 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5752 | if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs)) |
| 5753 | return std::move(Err); |
| 5754 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 5755 | if (!ToSubStmtOrErr) |
| 5756 | return ToSubStmtOrErr.takeError(); |
| 5757 | |
| 5758 | return AttributedStmt::Create( |
| 5759 | Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5760 | } |
| 5761 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5762 | ExpectedStmt ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| 5763 | auto Imp = importSeq( |
| 5764 | S->getIfLoc(), S->getInit(), S->getConditionVariable(), S->getCond(), |
| 5765 | S->getThen(), S->getElseLoc(), S->getElse()); |
| 5766 | if (!Imp) |
| 5767 | return Imp.takeError(); |
| 5768 | |
| 5769 | SourceLocation ToIfLoc, ToElseLoc; |
| 5770 | Stmt *ToInit, *ToThen, *ToElse; |
| 5771 | VarDecl *ToConditionVariable; |
| 5772 | Expr *ToCond; |
| 5773 | std::tie( |
| 5774 | ToIfLoc, ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, ToElse) = |
| 5775 | *Imp; |
| 5776 | |
Bruno Ricci | b1cc94b | 2018-10-27 21:12:20 +0000 | [diff] [blame] | 5777 | return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->isConstexpr(), |
| 5778 | ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, |
| 5779 | ToElse); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5780 | } |
| 5781 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5782 | ExpectedStmt ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
| 5783 | auto Imp = importSeq( |
| 5784 | S->getInit(), S->getConditionVariable(), S->getCond(), |
| 5785 | S->getBody(), S->getSwitchLoc()); |
| 5786 | if (!Imp) |
| 5787 | return Imp.takeError(); |
| 5788 | |
| 5789 | Stmt *ToInit, *ToBody; |
| 5790 | VarDecl *ToConditionVariable; |
| 5791 | Expr *ToCond; |
| 5792 | SourceLocation ToSwitchLoc; |
| 5793 | std::tie(ToInit, ToConditionVariable, ToCond, ToBody, ToSwitchLoc) = *Imp; |
| 5794 | |
Bruno Ricci | e2806f8 | 2018-10-29 16:12:37 +0000 | [diff] [blame] | 5795 | auto *ToStmt = SwitchStmt::Create(Importer.getToContext(), ToInit, |
| 5796 | ToConditionVariable, ToCond); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5797 | ToStmt->setBody(ToBody); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5798 | ToStmt->setSwitchLoc(ToSwitchLoc); |
| 5799 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5800 | // Now we have to re-chain the cases. |
| 5801 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 5802 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 5803 | SC = SC->getNextSwitchCase()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5804 | Expected<SwitchCase *> ToSCOrErr = import(SC); |
| 5805 | if (!ToSCOrErr) |
| 5806 | return ToSCOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5807 | if (LastChainedSwitchCase) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5808 | LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5809 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5810 | ToStmt->setSwitchCaseList(*ToSCOrErr); |
| 5811 | LastChainedSwitchCase = *ToSCOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5812 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5813 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5814 | return ToStmt; |
| 5815 | } |
| 5816 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5817 | ExpectedStmt ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| 5818 | auto Imp = importSeq( |
| 5819 | S->getConditionVariable(), S->getCond(), S->getBody(), S->getWhileLoc()); |
| 5820 | if (!Imp) |
| 5821 | return Imp.takeError(); |
| 5822 | |
| 5823 | VarDecl *ToConditionVariable; |
| 5824 | Expr *ToCond; |
| 5825 | Stmt *ToBody; |
| 5826 | SourceLocation ToWhileLoc; |
| 5827 | std::tie(ToConditionVariable, ToCond, ToBody, ToWhileLoc) = *Imp; |
| 5828 | |
Bruno Ricci | bacf751 | 2018-10-30 13:42:41 +0000 | [diff] [blame] | 5829 | return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond, |
| 5830 | ToBody, ToWhileLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5831 | } |
| 5832 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5833 | ExpectedStmt ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| 5834 | auto Imp = importSeq( |
| 5835 | S->getBody(), S->getCond(), S->getDoLoc(), S->getWhileLoc(), |
| 5836 | S->getRParenLoc()); |
| 5837 | if (!Imp) |
| 5838 | return Imp.takeError(); |
| 5839 | |
| 5840 | Stmt *ToBody; |
| 5841 | Expr *ToCond; |
| 5842 | SourceLocation ToDoLoc, ToWhileLoc, ToRParenLoc; |
| 5843 | std::tie(ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc) = *Imp; |
| 5844 | |
| 5845 | return new (Importer.getToContext()) DoStmt( |
| 5846 | ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5847 | } |
| 5848 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5849 | ExpectedStmt ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| 5850 | auto Imp = importSeq( |
| 5851 | S->getInit(), S->getCond(), S->getConditionVariable(), S->getInc(), |
| 5852 | S->getBody(), S->getForLoc(), S->getLParenLoc(), S->getRParenLoc()); |
| 5853 | if (!Imp) |
| 5854 | return Imp.takeError(); |
| 5855 | |
| 5856 | Stmt *ToInit; |
| 5857 | Expr *ToCond, *ToInc; |
| 5858 | VarDecl *ToConditionVariable; |
| 5859 | Stmt *ToBody; |
| 5860 | SourceLocation ToForLoc, ToLParenLoc, ToRParenLoc; |
| 5861 | std::tie( |
| 5862 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, |
| 5863 | ToLParenLoc, ToRParenLoc) = *Imp; |
| 5864 | |
| 5865 | return new (Importer.getToContext()) ForStmt( |
| 5866 | Importer.getToContext(), |
| 5867 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc, |
| 5868 | ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5869 | } |
| 5870 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5871 | ExpectedStmt ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| 5872 | auto Imp = importSeq(S->getLabel(), S->getGotoLoc(), S->getLabelLoc()); |
| 5873 | if (!Imp) |
| 5874 | return Imp.takeError(); |
| 5875 | |
| 5876 | LabelDecl *ToLabel; |
| 5877 | SourceLocation ToGotoLoc, ToLabelLoc; |
| 5878 | std::tie(ToLabel, ToGotoLoc, ToLabelLoc) = *Imp; |
| 5879 | |
| 5880 | return new (Importer.getToContext()) GotoStmt( |
| 5881 | ToLabel, ToGotoLoc, ToLabelLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5882 | } |
| 5883 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5884 | ExpectedStmt ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 5885 | auto Imp = importSeq(S->getGotoLoc(), S->getStarLoc(), S->getTarget()); |
| 5886 | if (!Imp) |
| 5887 | return Imp.takeError(); |
| 5888 | |
| 5889 | SourceLocation ToGotoLoc, ToStarLoc; |
| 5890 | Expr *ToTarget; |
| 5891 | std::tie(ToGotoLoc, ToStarLoc, ToTarget) = *Imp; |
| 5892 | |
| 5893 | return new (Importer.getToContext()) IndirectGotoStmt( |
| 5894 | ToGotoLoc, ToStarLoc, ToTarget); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5895 | } |
| 5896 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5897 | ExpectedStmt ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 5898 | ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc()); |
| 5899 | if (!ToContinueLocOrErr) |
| 5900 | return ToContinueLocOrErr.takeError(); |
| 5901 | return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5902 | } |
| 5903 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5904 | ExpectedStmt ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 5905 | auto ToBreakLocOrErr = import(S->getBreakLoc()); |
| 5906 | if (!ToBreakLocOrErr) |
| 5907 | return ToBreakLocOrErr.takeError(); |
| 5908 | return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5909 | } |
| 5910 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5911 | ExpectedStmt ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| 5912 | auto Imp = importSeq( |
| 5913 | S->getReturnLoc(), S->getRetValue(), S->getNRVOCandidate()); |
| 5914 | if (!Imp) |
| 5915 | return Imp.takeError(); |
| 5916 | |
| 5917 | SourceLocation ToReturnLoc; |
| 5918 | Expr *ToRetValue; |
| 5919 | const VarDecl *ToNRVOCandidate; |
| 5920 | std::tie(ToReturnLoc, ToRetValue, ToNRVOCandidate) = *Imp; |
| 5921 | |
Bruno Ricci | 023b1d1 | 2018-10-30 14:40:49 +0000 | [diff] [blame] | 5922 | return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue, |
| 5923 | ToNRVOCandidate); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5924 | } |
| 5925 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5926 | ExpectedStmt ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| 5927 | auto Imp = importSeq( |
| 5928 | S->getCatchLoc(), S->getExceptionDecl(), S->getHandlerBlock()); |
| 5929 | if (!Imp) |
| 5930 | return Imp.takeError(); |
| 5931 | |
| 5932 | SourceLocation ToCatchLoc; |
| 5933 | VarDecl *ToExceptionDecl; |
| 5934 | Stmt *ToHandlerBlock; |
| 5935 | std::tie(ToCatchLoc, ToExceptionDecl, ToHandlerBlock) = *Imp; |
| 5936 | |
| 5937 | return new (Importer.getToContext()) CXXCatchStmt ( |
| 5938 | ToCatchLoc, ToExceptionDecl, ToHandlerBlock); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5939 | } |
| 5940 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5941 | ExpectedStmt ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 5942 | ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc()); |
| 5943 | if (!ToTryLocOrErr) |
| 5944 | return ToTryLocOrErr.takeError(); |
| 5945 | |
| 5946 | ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock()); |
| 5947 | if (!ToTryBlockOrErr) |
| 5948 | return ToTryBlockOrErr.takeError(); |
| 5949 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5950 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 5951 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 5952 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5953 | if (auto ToHandlerOrErr = import(FromHandler)) |
| 5954 | ToHandlers[HI] = *ToHandlerOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5955 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5956 | return ToHandlerOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5957 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5958 | |
| 5959 | return CXXTryStmt::Create( |
| 5960 | Importer.getToContext(), *ToTryLocOrErr,*ToTryBlockOrErr, ToHandlers); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5961 | } |
| 5962 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5963 | ExpectedStmt ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
| 5964 | auto Imp1 = importSeq( |
| 5965 | S->getInit(), S->getRangeStmt(), S->getBeginStmt(), S->getEndStmt(), |
| 5966 | S->getCond(), S->getInc(), S->getLoopVarStmt(), S->getBody()); |
| 5967 | if (!Imp1) |
| 5968 | return Imp1.takeError(); |
| 5969 | auto Imp2 = importSeq( |
| 5970 | S->getForLoc(), S->getCoawaitLoc(), S->getColonLoc(), S->getRParenLoc()); |
| 5971 | if (!Imp2) |
| 5972 | return Imp2.takeError(); |
| 5973 | |
| 5974 | DeclStmt *ToRangeStmt, *ToBeginStmt, *ToEndStmt, *ToLoopVarStmt; |
| 5975 | Expr *ToCond, *ToInc; |
| 5976 | Stmt *ToInit, *ToBody; |
| 5977 | std::tie( |
| 5978 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 5979 | ToBody) = *Imp1; |
| 5980 | SourceLocation ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc; |
| 5981 | std::tie(ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc) = *Imp2; |
| 5982 | |
| 5983 | return new (Importer.getToContext()) CXXForRangeStmt( |
| 5984 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 5985 | ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5986 | } |
| 5987 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5988 | ExpectedStmt |
| 5989 | ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 5990 | auto Imp = importSeq( |
| 5991 | S->getElement(), S->getCollection(), S->getBody(), |
| 5992 | S->getForLoc(), S->getRParenLoc()); |
| 5993 | if (!Imp) |
| 5994 | return Imp.takeError(); |
| 5995 | |
| 5996 | Stmt *ToElement, *ToBody; |
| 5997 | Expr *ToCollection; |
| 5998 | SourceLocation ToForLoc, ToRParenLoc; |
| 5999 | std::tie(ToElement, ToCollection, ToBody, ToForLoc, ToRParenLoc) = *Imp; |
| 6000 | |
| 6001 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement, |
| 6002 | ToCollection, |
| 6003 | ToBody, |
| 6004 | ToForLoc, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6005 | ToRParenLoc); |
| 6006 | } |
| 6007 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6008 | ExpectedStmt ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 6009 | auto Imp = importSeq( |
| 6010 | S->getAtCatchLoc(), S->getRParenLoc(), S->getCatchParamDecl(), |
| 6011 | S->getCatchBody()); |
| 6012 | if (!Imp) |
| 6013 | return Imp.takeError(); |
| 6014 | |
| 6015 | SourceLocation ToAtCatchLoc, ToRParenLoc; |
| 6016 | VarDecl *ToCatchParamDecl; |
| 6017 | Stmt *ToCatchBody; |
| 6018 | std::tie(ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody) = *Imp; |
| 6019 | |
| 6020 | return new (Importer.getToContext()) ObjCAtCatchStmt ( |
| 6021 | ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6022 | } |
| 6023 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6024 | ExpectedStmt ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 6025 | ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc()); |
| 6026 | if (!ToAtFinallyLocOrErr) |
| 6027 | return ToAtFinallyLocOrErr.takeError(); |
| 6028 | ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody()); |
| 6029 | if (!ToAtFinallyStmtOrErr) |
| 6030 | return ToAtFinallyStmtOrErr.takeError(); |
| 6031 | return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr, |
| 6032 | *ToAtFinallyStmtOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6033 | } |
| 6034 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6035 | ExpectedStmt ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 6036 | auto Imp = importSeq( |
| 6037 | S->getAtTryLoc(), S->getTryBody(), S->getFinallyStmt()); |
| 6038 | if (!Imp) |
| 6039 | return Imp.takeError(); |
| 6040 | |
| 6041 | SourceLocation ToAtTryLoc; |
| 6042 | Stmt *ToTryBody, *ToFinallyStmt; |
| 6043 | std::tie(ToAtTryLoc, ToTryBody, ToFinallyStmt) = *Imp; |
| 6044 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6045 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 6046 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 6047 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6048 | if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt)) |
| 6049 | ToCatchStmts[CI] = *ToCatchStmtOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6050 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6051 | return ToCatchStmtOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6052 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6053 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6054 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6055 | ToAtTryLoc, ToTryBody, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6056 | ToCatchStmts.begin(), ToCatchStmts.size(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6057 | ToFinallyStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6058 | } |
| 6059 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6060 | ExpectedStmt ASTNodeImporter::VisitObjCAtSynchronizedStmt |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6061 | (ObjCAtSynchronizedStmt *S) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6062 | auto Imp = importSeq( |
| 6063 | S->getAtSynchronizedLoc(), S->getSynchExpr(), S->getSynchBody()); |
| 6064 | if (!Imp) |
| 6065 | return Imp.takeError(); |
| 6066 | |
| 6067 | SourceLocation ToAtSynchronizedLoc; |
| 6068 | Expr *ToSynchExpr; |
| 6069 | Stmt *ToSynchBody; |
| 6070 | std::tie(ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody) = *Imp; |
| 6071 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6072 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 6073 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 6074 | } |
| 6075 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6076 | ExpectedStmt ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 6077 | ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc()); |
| 6078 | if (!ToThrowLocOrErr) |
| 6079 | return ToThrowLocOrErr.takeError(); |
| 6080 | ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr()); |
| 6081 | if (!ToThrowExprOrErr) |
| 6082 | return ToThrowExprOrErr.takeError(); |
| 6083 | return new (Importer.getToContext()) ObjCAtThrowStmt( |
| 6084 | *ToThrowLocOrErr, *ToThrowExprOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6085 | } |
| 6086 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6087 | ExpectedStmt ASTNodeImporter::VisitObjCAutoreleasePoolStmt( |
| 6088 | ObjCAutoreleasePoolStmt *S) { |
| 6089 | ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc()); |
| 6090 | if (!ToAtLocOrErr) |
| 6091 | return ToAtLocOrErr.takeError(); |
| 6092 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 6093 | if (!ToSubStmtOrErr) |
| 6094 | return ToSubStmtOrErr.takeError(); |
| 6095 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr, |
| 6096 | *ToSubStmtOrErr); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6097 | } |
| 6098 | |
| 6099 | //---------------------------------------------------------------------------- |
| 6100 | // Import Expressions |
| 6101 | //---------------------------------------------------------------------------- |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6102 | ExpectedStmt ASTNodeImporter::VisitExpr(Expr *E) { |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6103 | Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node) |
| 6104 | << E->getStmtClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6105 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6106 | } |
| 6107 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6108 | ExpectedStmt ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| 6109 | auto Imp = importSeq( |
| 6110 | E->getBuiltinLoc(), E->getSubExpr(), E->getWrittenTypeInfo(), |
| 6111 | E->getRParenLoc(), E->getType()); |
| 6112 | if (!Imp) |
| 6113 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6114 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6115 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6116 | Expr *ToSubExpr; |
| 6117 | TypeSourceInfo *ToWrittenTypeInfo; |
| 6118 | QualType ToType; |
| 6119 | std::tie(ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType) = |
| 6120 | *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6121 | |
| 6122 | return new (Importer.getToContext()) VAArgExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6123 | ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType, |
| 6124 | E->isMicrosoftABI()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6125 | } |
| 6126 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6127 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6128 | ExpectedStmt ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 6129 | ExpectedType TypeOrErr = import(E->getType()); |
| 6130 | if (!TypeOrErr) |
| 6131 | return TypeOrErr.takeError(); |
| 6132 | |
| 6133 | ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc()); |
| 6134 | if (!BeginLocOrErr) |
| 6135 | return BeginLocOrErr.takeError(); |
| 6136 | |
| 6137 | return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6138 | } |
| 6139 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6140 | ExpectedStmt ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { |
| 6141 | auto Imp = importSeq( |
| 6142 | E->getBeginLoc(), E->getType(), E->getFunctionName()); |
| 6143 | if (!Imp) |
| 6144 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6145 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6146 | SourceLocation ToBeginLoc; |
| 6147 | QualType ToType; |
| 6148 | StringLiteral *ToFunctionName; |
| 6149 | std::tie(ToBeginLoc, ToType, ToFunctionName) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6150 | |
Bruno Ricci | 17ff026 | 2018-10-27 19:21:19 +0000 | [diff] [blame] | 6151 | return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType, |
| 6152 | E->getIdentKind(), ToFunctionName); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6153 | } |
| 6154 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6155 | ExpectedStmt ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
| 6156 | auto Imp = importSeq( |
| 6157 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDecl(), |
| 6158 | E->getLocation(), E->getType()); |
| 6159 | if (!Imp) |
| 6160 | return Imp.takeError(); |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6161 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6162 | NestedNameSpecifierLoc ToQualifierLoc; |
| 6163 | SourceLocation ToTemplateKeywordLoc, ToLocation; |
| 6164 | ValueDecl *ToDecl; |
| 6165 | QualType ToType; |
| 6166 | std::tie(ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, ToLocation, ToType) = |
| 6167 | *Imp; |
| 6168 | |
| 6169 | NamedDecl *ToFoundD = nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6170 | if (E->getDecl() != E->getFoundDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6171 | auto FoundDOrErr = import(E->getFoundDecl()); |
| 6172 | if (!FoundDOrErr) |
| 6173 | return FoundDOrErr.takeError(); |
| 6174 | ToFoundD = *FoundDOrErr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6175 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6176 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6177 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6178 | TemplateArgumentListInfo *ToResInfo = nullptr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6179 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6180 | if (Error Err = |
| 6181 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 6182 | return std::move(Err); |
| 6183 | ToResInfo = &ToTAInfo; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6184 | } |
| 6185 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6186 | auto *ToE = DeclRefExpr::Create( |
| 6187 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, |
| 6188 | E->refersToEnclosingVariableOrCapture(), ToLocation, ToType, |
| 6189 | E->getValueKind(), ToFoundD, ToResInfo); |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 6190 | if (E->hadMultipleCandidates()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6191 | ToE->setHadMultipleCandidates(true); |
| 6192 | return ToE; |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 6193 | } |
| 6194 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6195 | ExpectedStmt ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 6196 | ExpectedType TypeOrErr = import(E->getType()); |
| 6197 | if (!TypeOrErr) |
| 6198 | return TypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6199 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6200 | return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6201 | } |
| 6202 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6203 | ExpectedStmt ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { |
| 6204 | ExpectedExpr ToInitOrErr = import(E->getInit()); |
| 6205 | if (!ToInitOrErr) |
| 6206 | return ToInitOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6207 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6208 | ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc()); |
| 6209 | if (!ToEqualOrColonLocOrErr) |
| 6210 | return ToEqualOrColonLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6211 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6212 | SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6213 | // List elements from the second, the first is Init itself |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6214 | for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) { |
| 6215 | if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I))) |
| 6216 | ToIndexExprs[I - 1] = *ToArgOrErr; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6217 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6218 | return ToArgOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6219 | } |
| 6220 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6221 | SmallVector<Designator, 4> ToDesignators(E->size()); |
| 6222 | if (Error Err = ImportContainerChecked(E->designators(), ToDesignators)) |
| 6223 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6224 | |
| 6225 | return DesignatedInitExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6226 | Importer.getToContext(), ToDesignators, |
| 6227 | ToIndexExprs, *ToEqualOrColonLocOrErr, |
| 6228 | E->usesGNUSyntax(), *ToInitOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6229 | } |
| 6230 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6231 | ExpectedStmt |
| 6232 | ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 6233 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6234 | if (!ToTypeOrErr) |
| 6235 | return ToTypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6236 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6237 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6238 | if (!ToLocationOrErr) |
| 6239 | return ToLocationOrErr.takeError(); |
| 6240 | |
| 6241 | return new (Importer.getToContext()) CXXNullPtrLiteralExpr( |
| 6242 | *ToTypeOrErr, *ToLocationOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6243 | } |
| 6244 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6245 | ExpectedStmt ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 6246 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6247 | if (!ToTypeOrErr) |
| 6248 | return ToTypeOrErr.takeError(); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6249 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6250 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6251 | if (!ToLocationOrErr) |
| 6252 | return ToLocationOrErr.takeError(); |
| 6253 | |
| 6254 | return IntegerLiteral::Create( |
| 6255 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6256 | } |
| 6257 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6258 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6259 | ExpectedStmt ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 6260 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6261 | if (!ToTypeOrErr) |
| 6262 | return ToTypeOrErr.takeError(); |
| 6263 | |
| 6264 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6265 | if (!ToLocationOrErr) |
| 6266 | return ToLocationOrErr.takeError(); |
| 6267 | |
| 6268 | return FloatingLiteral::Create( |
| 6269 | Importer.getToContext(), E->getValue(), E->isExact(), |
| 6270 | *ToTypeOrErr, *ToLocationOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6271 | } |
| 6272 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6273 | ExpectedStmt ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) { |
| 6274 | auto ToTypeOrErr = import(E->getType()); |
| 6275 | if (!ToTypeOrErr) |
| 6276 | return ToTypeOrErr.takeError(); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6277 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6278 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6279 | if (!ToSubExprOrErr) |
| 6280 | return ToSubExprOrErr.takeError(); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6281 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6282 | return new (Importer.getToContext()) ImaginaryLiteral( |
| 6283 | *ToSubExprOrErr, *ToTypeOrErr); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6284 | } |
| 6285 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6286 | ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 6287 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6288 | if (!ToTypeOrErr) |
| 6289 | return ToTypeOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6290 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6291 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6292 | if (!ToLocationOrErr) |
| 6293 | return ToLocationOrErr.takeError(); |
| 6294 | |
| 6295 | return new (Importer.getToContext()) CharacterLiteral( |
| 6296 | E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr); |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 6297 | } |
| 6298 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6299 | ExpectedStmt ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 6300 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6301 | if (!ToTypeOrErr) |
| 6302 | return ToTypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6303 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6304 | SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated()); |
| 6305 | if (Error Err = ImportArrayChecked( |
| 6306 | E->tokloc_begin(), E->tokloc_end(), ToLocations.begin())) |
| 6307 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6308 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6309 | return StringLiteral::Create( |
| 6310 | Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(), |
| 6311 | *ToTypeOrErr, ToLocations.data(), ToLocations.size()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6312 | } |
| 6313 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6314 | ExpectedStmt ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 6315 | auto Imp = importSeq( |
| 6316 | E->getLParenLoc(), E->getTypeSourceInfo(), E->getType(), |
| 6317 | E->getInitializer()); |
| 6318 | if (!Imp) |
| 6319 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6320 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6321 | SourceLocation ToLParenLoc; |
| 6322 | TypeSourceInfo *ToTypeSourceInfo; |
| 6323 | QualType ToType; |
| 6324 | Expr *ToInitializer; |
| 6325 | std::tie(ToLParenLoc, ToTypeSourceInfo, ToType, ToInitializer) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6326 | |
| 6327 | return new (Importer.getToContext()) CompoundLiteralExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6328 | ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(), |
| 6329 | ToInitializer, E->isFileScope()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6330 | } |
| 6331 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6332 | ExpectedStmt ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { |
| 6333 | auto Imp = importSeq( |
| 6334 | E->getBuiltinLoc(), E->getType(), E->getRParenLoc()); |
| 6335 | if (!Imp) |
| 6336 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6337 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6338 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6339 | QualType ToType; |
| 6340 | std::tie(ToBuiltinLoc, ToType, ToRParenLoc) = *Imp; |
| 6341 | |
| 6342 | SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs()); |
| 6343 | if (Error Err = ImportArrayChecked( |
| 6344 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 6345 | ToExprs.begin())) |
| 6346 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6347 | |
| 6348 | return new (Importer.getToContext()) AtomicExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6349 | ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6350 | } |
| 6351 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6352 | ExpectedStmt ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 6353 | auto Imp = importSeq( |
| 6354 | E->getAmpAmpLoc(), E->getLabelLoc(), E->getLabel(), E->getType()); |
| 6355 | if (!Imp) |
| 6356 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6357 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6358 | SourceLocation ToAmpAmpLoc, ToLabelLoc; |
| 6359 | LabelDecl *ToLabel; |
| 6360 | QualType ToType; |
| 6361 | std::tie(ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6362 | |
| 6363 | return new (Importer.getToContext()) AddrLabelExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6364 | ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6365 | } |
| 6366 | |
Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6367 | ExpectedStmt ASTNodeImporter::VisitConstantExpr(ConstantExpr *E) { |
| 6368 | auto Imp = importSeq(E->getSubExpr()); |
| 6369 | if (!Imp) |
| 6370 | return Imp.takeError(); |
| 6371 | |
| 6372 | Expr *ToSubExpr; |
| 6373 | std::tie(ToSubExpr) = *Imp; |
| 6374 | |
Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 6375 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr); |
Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6376 | } |
| 6377 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6378 | ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| 6379 | auto Imp = importSeq(E->getLParen(), E->getRParen(), E->getSubExpr()); |
| 6380 | if (!Imp) |
| 6381 | return Imp.takeError(); |
| 6382 | |
| 6383 | SourceLocation ToLParen, ToRParen; |
| 6384 | Expr *ToSubExpr; |
| 6385 | std::tie(ToLParen, ToRParen, ToSubExpr) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6386 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6387 | return new (Importer.getToContext()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6388 | ParenExpr(ToLParen, ToRParen, ToSubExpr); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6389 | } |
| 6390 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6391 | ExpectedStmt ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 6392 | SmallVector<Expr *, 4> ToExprs(E->getNumExprs()); |
| 6393 | if (Error Err = ImportContainerChecked(E->exprs(), ToExprs)) |
| 6394 | return std::move(Err); |
| 6395 | |
| 6396 | ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc()); |
| 6397 | if (!ToLParenLocOrErr) |
| 6398 | return ToLParenLocOrErr.takeError(); |
| 6399 | |
| 6400 | ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc()); |
| 6401 | if (!ToRParenLocOrErr) |
| 6402 | return ToRParenLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6403 | |
Bruno Ricci | f49e1ca | 2018-11-20 16:20:40 +0000 | [diff] [blame] | 6404 | return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr, |
| 6405 | ToExprs, *ToRParenLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6406 | } |
| 6407 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6408 | ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| 6409 | auto Imp = importSeq( |
| 6410 | E->getSubStmt(), E->getType(), E->getLParenLoc(), E->getRParenLoc()); |
| 6411 | if (!Imp) |
| 6412 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6413 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6414 | CompoundStmt *ToSubStmt; |
| 6415 | QualType ToType; |
| 6416 | SourceLocation ToLParenLoc, ToRParenLoc; |
| 6417 | std::tie(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6418 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6419 | return new (Importer.getToContext()) StmtExpr( |
| 6420 | ToSubStmt, ToType, ToLParenLoc, ToRParenLoc); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6421 | } |
| 6422 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6423 | ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| 6424 | auto Imp = importSeq( |
| 6425 | E->getSubExpr(), E->getType(), E->getOperatorLoc()); |
| 6426 | if (!Imp) |
| 6427 | return Imp.takeError(); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6428 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6429 | Expr *ToSubExpr; |
| 6430 | QualType ToType; |
| 6431 | SourceLocation ToOperatorLoc; |
| 6432 | std::tie(ToSubExpr, ToType, ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6433 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6434 | return new (Importer.getToContext()) UnaryOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6435 | ToSubExpr, E->getOpcode(), ToType, E->getValueKind(), E->getObjectKind(), |
| 6436 | ToOperatorLoc, E->canOverflow()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6437 | } |
| 6438 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6439 | ExpectedStmt |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6440 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6441 | auto Imp = importSeq(E->getType(), E->getOperatorLoc(), E->getRParenLoc()); |
| 6442 | if (!Imp) |
| 6443 | return Imp.takeError(); |
| 6444 | |
| 6445 | QualType ToType; |
| 6446 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 6447 | std::tie(ToType, ToOperatorLoc, ToRParenLoc) = *Imp; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6448 | |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6449 | if (E->isArgumentType()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6450 | Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr = |
| 6451 | import(E->getArgumentTypeInfo()); |
| 6452 | if (!ToArgumentTypeInfoOrErr) |
| 6453 | return ToArgumentTypeInfoOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6454 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6455 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6456 | E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc, |
| 6457 | ToRParenLoc); |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6458 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6459 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6460 | ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr()); |
| 6461 | if (!ToArgumentExprOrErr) |
| 6462 | return ToArgumentExprOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6463 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6464 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6465 | E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc); |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6466 | } |
| 6467 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6468 | ExpectedStmt ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| 6469 | auto Imp = importSeq( |
| 6470 | E->getLHS(), E->getRHS(), E->getType(), E->getOperatorLoc()); |
| 6471 | if (!Imp) |
| 6472 | return Imp.takeError(); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6473 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6474 | Expr *ToLHS, *ToRHS; |
| 6475 | QualType ToType; |
| 6476 | SourceLocation ToOperatorLoc; |
| 6477 | std::tie(ToLHS, ToRHS, ToType, ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6478 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6479 | return new (Importer.getToContext()) BinaryOperator( |
| 6480 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6481 | E->getObjectKind(), ToOperatorLoc, E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6482 | } |
| 6483 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6484 | ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| 6485 | auto Imp = importSeq( |
| 6486 | E->getCond(), E->getQuestionLoc(), E->getLHS(), E->getColonLoc(), |
| 6487 | E->getRHS(), E->getType()); |
| 6488 | if (!Imp) |
| 6489 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6490 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6491 | Expr *ToCond, *ToLHS, *ToRHS; |
| 6492 | SourceLocation ToQuestionLoc, ToColonLoc; |
| 6493 | QualType ToType; |
| 6494 | std::tie(ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6495 | |
| 6496 | return new (Importer.getToContext()) ConditionalOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6497 | ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType, |
| 6498 | E->getValueKind(), E->getObjectKind()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6499 | } |
| 6500 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6501 | ExpectedStmt ASTNodeImporter::VisitBinaryConditionalOperator( |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6502 | BinaryConditionalOperator *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6503 | auto Imp = importSeq( |
| 6504 | E->getCommon(), E->getOpaqueValue(), E->getCond(), E->getTrueExpr(), |
| 6505 | E->getFalseExpr(), E->getQuestionLoc(), E->getColonLoc(), E->getType()); |
| 6506 | if (!Imp) |
| 6507 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6508 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6509 | Expr *ToCommon, *ToCond, *ToTrueExpr, *ToFalseExpr; |
| 6510 | OpaqueValueExpr *ToOpaqueValue; |
| 6511 | SourceLocation ToQuestionLoc, ToColonLoc; |
| 6512 | QualType ToType; |
| 6513 | std::tie( |
| 6514 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, ToQuestionLoc, |
| 6515 | ToColonLoc, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6516 | |
| 6517 | return new (Importer.getToContext()) BinaryConditionalOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6518 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, |
| 6519 | ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(), |
| 6520 | E->getObjectKind()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6521 | } |
| 6522 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6523 | ExpectedStmt ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 6524 | auto Imp = importSeq( |
| 6525 | E->getBeginLoc(), E->getQueriedTypeSourceInfo(), |
| 6526 | E->getDimensionExpression(), E->getEndLoc(), E->getType()); |
| 6527 | if (!Imp) |
| 6528 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6529 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6530 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6531 | TypeSourceInfo *ToQueriedTypeSourceInfo; |
| 6532 | Expr *ToDimensionExpression; |
| 6533 | QualType ToType; |
| 6534 | std::tie( |
| 6535 | ToBeginLoc, ToQueriedTypeSourceInfo, ToDimensionExpression, ToEndLoc, |
| 6536 | ToType) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6537 | |
| 6538 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6539 | ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(), |
| 6540 | ToDimensionExpression, ToEndLoc, ToType); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6541 | } |
| 6542 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6543 | ExpectedStmt ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 6544 | auto Imp = importSeq( |
| 6545 | E->getBeginLoc(), E->getQueriedExpression(), E->getEndLoc(), E->getType()); |
| 6546 | if (!Imp) |
| 6547 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6548 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6549 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6550 | Expr *ToQueriedExpression; |
| 6551 | QualType ToType; |
| 6552 | std::tie(ToBeginLoc, ToQueriedExpression, ToEndLoc, ToType) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6553 | |
| 6554 | return new (Importer.getToContext()) ExpressionTraitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6555 | ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(), |
| 6556 | ToEndLoc, ToType); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6557 | } |
| 6558 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6559 | ExpectedStmt ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| 6560 | auto Imp = importSeq( |
| 6561 | E->getLocation(), E->getType(), E->getSourceExpr()); |
| 6562 | if (!Imp) |
| 6563 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6564 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6565 | SourceLocation ToLocation; |
| 6566 | QualType ToType; |
| 6567 | Expr *ToSourceExpr; |
| 6568 | std::tie(ToLocation, ToType, ToSourceExpr) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6569 | |
| 6570 | return new (Importer.getToContext()) OpaqueValueExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6571 | ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6572 | } |
| 6573 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6574 | ExpectedStmt ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 6575 | auto Imp = importSeq( |
| 6576 | E->getLHS(), E->getRHS(), E->getType(), E->getRBracketLoc()); |
| 6577 | if (!Imp) |
| 6578 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6579 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6580 | Expr *ToLHS, *ToRHS; |
| 6581 | SourceLocation ToRBracketLoc; |
| 6582 | QualType ToType; |
| 6583 | std::tie(ToLHS, ToRHS, ToType, ToRBracketLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6584 | |
| 6585 | return new (Importer.getToContext()) ArraySubscriptExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6586 | ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(), |
| 6587 | ToRBracketLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6588 | } |
| 6589 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6590 | ExpectedStmt |
| 6591 | ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 6592 | auto Imp = importSeq( |
| 6593 | E->getLHS(), E->getRHS(), E->getType(), E->getComputationLHSType(), |
| 6594 | E->getComputationResultType(), E->getOperatorLoc()); |
| 6595 | if (!Imp) |
| 6596 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6597 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6598 | Expr *ToLHS, *ToRHS; |
| 6599 | QualType ToType, ToComputationLHSType, ToComputationResultType; |
| 6600 | SourceLocation ToOperatorLoc; |
| 6601 | std::tie(ToLHS, ToRHS, ToType, ToComputationLHSType, ToComputationResultType, |
| 6602 | ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6603 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6604 | return new (Importer.getToContext()) CompoundAssignOperator( |
| 6605 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6606 | E->getObjectKind(), ToComputationLHSType, ToComputationResultType, |
| 6607 | ToOperatorLoc, E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6608 | } |
| 6609 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6610 | Expected<CXXCastPath> |
| 6611 | ASTNodeImporter::ImportCastPath(CastExpr *CE) { |
| 6612 | CXXCastPath Path; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6613 | 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] | 6614 | if (auto SpecOrErr = import(*I)) |
| 6615 | Path.push_back(*SpecOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6616 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6617 | return SpecOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6618 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6619 | return Path; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6620 | } |
| 6621 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6622 | ExpectedStmt ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 6623 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6624 | if (!ToTypeOrErr) |
| 6625 | return ToTypeOrErr.takeError(); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6626 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6627 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6628 | if (!ToSubExprOrErr) |
| 6629 | return ToSubExprOrErr.takeError(); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6630 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6631 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6632 | if (!ToBasePathOrErr) |
| 6633 | return ToBasePathOrErr.takeError(); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6634 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6635 | return ImplicitCastExpr::Create( |
| 6636 | Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr, |
| 6637 | &(*ToBasePathOrErr), E->getValueKind()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6638 | } |
| 6639 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6640 | ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
| 6641 | auto Imp1 = importSeq( |
| 6642 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten()); |
| 6643 | if (!Imp1) |
| 6644 | return Imp1.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6645 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6646 | QualType ToType; |
| 6647 | Expr *ToSubExpr; |
| 6648 | TypeSourceInfo *ToTypeInfoAsWritten; |
| 6649 | std::tie(ToType, ToSubExpr, ToTypeInfoAsWritten) = *Imp1; |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6650 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6651 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6652 | if (!ToBasePathOrErr) |
| 6653 | return ToBasePathOrErr.takeError(); |
| 6654 | CXXCastPath *ToBasePath = &(*ToBasePathOrErr); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6655 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6656 | switch (E->getStmtClass()) { |
| 6657 | case Stmt::CStyleCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6658 | auto *CCE = cast<CStyleCastExpr>(E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6659 | ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc()); |
| 6660 | if (!ToLParenLocOrErr) |
| 6661 | return ToLParenLocOrErr.takeError(); |
| 6662 | ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc()); |
| 6663 | if (!ToRParenLocOrErr) |
| 6664 | return ToRParenLocOrErr.takeError(); |
| 6665 | return CStyleCastExpr::Create( |
| 6666 | Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(), |
| 6667 | ToSubExpr, ToBasePath, ToTypeInfoAsWritten, *ToLParenLocOrErr, |
| 6668 | *ToRParenLocOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6669 | } |
| 6670 | |
| 6671 | case Stmt::CXXFunctionalCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6672 | auto *FCE = cast<CXXFunctionalCastExpr>(E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6673 | ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc()); |
| 6674 | if (!ToLParenLocOrErr) |
| 6675 | return ToLParenLocOrErr.takeError(); |
| 6676 | ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc()); |
| 6677 | if (!ToRParenLocOrErr) |
| 6678 | return ToRParenLocOrErr.takeError(); |
| 6679 | return CXXFunctionalCastExpr::Create( |
| 6680 | Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten, |
| 6681 | E->getCastKind(), ToSubExpr, ToBasePath, *ToLParenLocOrErr, |
| 6682 | *ToRParenLocOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6683 | } |
| 6684 | |
| 6685 | case Stmt::ObjCBridgedCastExprClass: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6686 | auto *OCE = cast<ObjCBridgedCastExpr>(E); |
| 6687 | ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc()); |
| 6688 | if (!ToLParenLocOrErr) |
| 6689 | return ToLParenLocOrErr.takeError(); |
| 6690 | ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc()); |
| 6691 | if (!ToBridgeKeywordLocOrErr) |
| 6692 | return ToBridgeKeywordLocOrErr.takeError(); |
| 6693 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 6694 | *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), |
| 6695 | *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6696 | } |
| 6697 | default: |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6698 | llvm_unreachable("Cast expression of unsupported type!"); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6699 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6700 | } |
| 6701 | } |
| 6702 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6703 | ExpectedStmt ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *E) { |
| 6704 | SmallVector<OffsetOfNode, 4> ToNodes; |
| 6705 | for (int I = 0, N = E->getNumComponents(); I < N; ++I) { |
| 6706 | const OffsetOfNode &FromNode = E->getComponent(I); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6707 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6708 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6709 | if (FromNode.getKind() != OffsetOfNode::Base) { |
| 6710 | auto Imp = importSeq(FromNode.getBeginLoc(), FromNode.getEndLoc()); |
| 6711 | if (!Imp) |
| 6712 | return Imp.takeError(); |
| 6713 | std::tie(ToBeginLoc, ToEndLoc) = *Imp; |
| 6714 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6715 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6716 | switch (FromNode.getKind()) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6717 | case OffsetOfNode::Array: |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6718 | ToNodes.push_back( |
| 6719 | OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6720 | break; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6721 | case OffsetOfNode::Base: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6722 | auto ToBSOrErr = import(FromNode.getBase()); |
| 6723 | if (!ToBSOrErr) |
| 6724 | return ToBSOrErr.takeError(); |
| 6725 | ToNodes.push_back(OffsetOfNode(*ToBSOrErr)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6726 | break; |
| 6727 | } |
| 6728 | case OffsetOfNode::Field: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6729 | auto ToFieldOrErr = import(FromNode.getField()); |
| 6730 | if (!ToFieldOrErr) |
| 6731 | return ToFieldOrErr.takeError(); |
| 6732 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6733 | break; |
| 6734 | } |
| 6735 | case OffsetOfNode::Identifier: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6736 | IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName()); |
| 6737 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6738 | break; |
| 6739 | } |
| 6740 | } |
| 6741 | } |
| 6742 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6743 | SmallVector<Expr *, 4> ToExprs(E->getNumExpressions()); |
| 6744 | for (int I = 0, N = E->getNumExpressions(); I < N; ++I) { |
| 6745 | ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I)); |
| 6746 | if (!ToIndexExprOrErr) |
| 6747 | return ToIndexExprOrErr.takeError(); |
| 6748 | ToExprs[I] = *ToIndexExprOrErr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6749 | } |
| 6750 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6751 | auto Imp = importSeq( |
| 6752 | E->getType(), E->getTypeSourceInfo(), E->getOperatorLoc(), |
| 6753 | E->getRParenLoc()); |
| 6754 | if (!Imp) |
| 6755 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6756 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6757 | QualType ToType; |
| 6758 | TypeSourceInfo *ToTypeSourceInfo; |
| 6759 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 6760 | std::tie(ToType, ToTypeSourceInfo, ToOperatorLoc, ToRParenLoc) = *Imp; |
| 6761 | |
| 6762 | return OffsetOfExpr::Create( |
| 6763 | Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes, |
| 6764 | ToExprs, ToRParenLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6765 | } |
| 6766 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6767 | ExpectedStmt ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 6768 | auto Imp = importSeq( |
| 6769 | E->getType(), E->getOperand(), E->getBeginLoc(), E->getEndLoc()); |
| 6770 | if (!Imp) |
| 6771 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6772 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6773 | QualType ToType; |
| 6774 | Expr *ToOperand; |
| 6775 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6776 | std::tie(ToType, ToOperand, ToBeginLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6777 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6778 | CanThrowResult ToCanThrow; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6779 | if (E->isValueDependent()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6780 | ToCanThrow = CT_Dependent; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6781 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6782 | ToCanThrow = E->getValue() ? CT_Can : CT_Cannot; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6783 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6784 | return new (Importer.getToContext()) CXXNoexceptExpr( |
| 6785 | ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6786 | } |
| 6787 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6788 | ExpectedStmt ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| 6789 | auto Imp = importSeq(E->getSubExpr(), E->getType(), E->getThrowLoc()); |
| 6790 | if (!Imp) |
| 6791 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6792 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6793 | Expr *ToSubExpr; |
| 6794 | QualType ToType; |
| 6795 | SourceLocation ToThrowLoc; |
| 6796 | std::tie(ToSubExpr, ToType, ToThrowLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6797 | |
| 6798 | return new (Importer.getToContext()) CXXThrowExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6799 | ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6800 | } |
| 6801 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6802 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| 6803 | ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation()); |
| 6804 | if (!ToUsedLocOrErr) |
| 6805 | return ToUsedLocOrErr.takeError(); |
| 6806 | |
| 6807 | auto ToParamOrErr = import(E->getParam()); |
| 6808 | if (!ToParamOrErr) |
| 6809 | return ToParamOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6810 | |
| 6811 | return CXXDefaultArgExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6812 | Importer.getToContext(), *ToUsedLocOrErr, *ToParamOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6813 | } |
| 6814 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6815 | ExpectedStmt |
| 6816 | ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| 6817 | auto Imp = importSeq( |
| 6818 | E->getType(), E->getTypeSourceInfo(), E->getRParenLoc()); |
| 6819 | if (!Imp) |
| 6820 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6821 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6822 | QualType ToType; |
| 6823 | TypeSourceInfo *ToTypeSourceInfo; |
| 6824 | SourceLocation ToRParenLoc; |
| 6825 | std::tie(ToType, ToTypeSourceInfo, ToRParenLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6826 | |
| 6827 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6828 | ToType, ToTypeSourceInfo, ToRParenLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6829 | } |
| 6830 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6831 | ExpectedStmt |
| 6832 | ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 6833 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6834 | if (!ToSubExprOrErr) |
| 6835 | return ToSubExprOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6836 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6837 | auto ToDtorOrErr = import(E->getTemporary()->getDestructor()); |
| 6838 | if (!ToDtorOrErr) |
| 6839 | return ToDtorOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6840 | |
| 6841 | ASTContext &ToCtx = Importer.getToContext(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6842 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr); |
| 6843 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6844 | } |
| 6845 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6846 | ExpectedStmt |
| 6847 | ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { |
| 6848 | auto Imp = importSeq( |
| 6849 | E->getConstructor(), E->getType(), E->getTypeSourceInfo(), |
| 6850 | E->getParenOrBraceRange()); |
| 6851 | if (!Imp) |
| 6852 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6853 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6854 | CXXConstructorDecl *ToConstructor; |
| 6855 | QualType ToType; |
| 6856 | TypeSourceInfo *ToTypeSourceInfo; |
| 6857 | SourceRange ToParenOrBraceRange; |
| 6858 | std::tie(ToConstructor, ToType, ToTypeSourceInfo, ToParenOrBraceRange) = *Imp; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6859 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6860 | SmallVector<Expr *, 8> ToArgs(E->getNumArgs()); |
| 6861 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 6862 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6863 | |
Bruno Ricci | ddb8f6b | 2018-12-22 14:39:30 +0000 | [diff] [blame] | 6864 | return CXXTemporaryObjectExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6865 | Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs, |
| 6866 | ToParenOrBraceRange, E->hadMultipleCandidates(), |
| 6867 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 6868 | E->requiresZeroInitialization()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6869 | } |
| 6870 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6871 | ExpectedStmt |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6872 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6873 | auto Imp = importSeq( |
| 6874 | E->getType(), E->GetTemporaryExpr(), E->getExtendingDecl()); |
| 6875 | if (!Imp) |
| 6876 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6877 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6878 | QualType ToType; |
| 6879 | Expr *ToTemporaryExpr; |
| 6880 | const ValueDecl *ToExtendingDecl; |
| 6881 | std::tie(ToType, ToTemporaryExpr, ToExtendingDecl) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6882 | |
| 6883 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6884 | ToType, ToTemporaryExpr, E->isBoundToLvalueReference()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6885 | |
| 6886 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6887 | ToMTE->setExtendingDecl(ToExtendingDecl, E->getManglingNumber()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6888 | return ToMTE; |
| 6889 | } |
| 6890 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6891 | ExpectedStmt ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { |
| 6892 | auto Imp = importSeq( |
| 6893 | E->getType(), E->getPattern(), E->getEllipsisLoc()); |
| 6894 | if (!Imp) |
| 6895 | return Imp.takeError(); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6896 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6897 | QualType ToType; |
| 6898 | Expr *ToPattern; |
| 6899 | SourceLocation ToEllipsisLoc; |
| 6900 | std::tie(ToType, ToPattern, ToEllipsisLoc) = *Imp; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6901 | |
| 6902 | return new (Importer.getToContext()) PackExpansionExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6903 | ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions()); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6904 | } |
| 6905 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6906 | ExpectedStmt ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { |
| 6907 | auto Imp = importSeq( |
| 6908 | E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc()); |
| 6909 | if (!Imp) |
| 6910 | return Imp.takeError(); |
| 6911 | |
| 6912 | SourceLocation ToOperatorLoc, ToPackLoc, ToRParenLoc; |
| 6913 | NamedDecl *ToPack; |
| 6914 | std::tie(ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc) = *Imp; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6915 | |
| 6916 | Optional<unsigned> Length; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6917 | if (!E->isValueDependent()) |
| 6918 | Length = E->getPackLength(); |
| 6919 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6920 | SmallVector<TemplateArgument, 8> ToPartialArguments; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6921 | if (E->isPartiallySubstituted()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6922 | if (Error Err = ImportTemplateArguments( |
| 6923 | E->getPartialArguments().data(), |
| 6924 | E->getPartialArguments().size(), |
| 6925 | ToPartialArguments)) |
| 6926 | return std::move(Err); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6927 | } |
| 6928 | |
| 6929 | return SizeOfPackExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6930 | Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc, |
| 6931 | Length, ToPartialArguments); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6932 | } |
| 6933 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6934 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6935 | ExpectedStmt ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) { |
| 6936 | auto Imp = importSeq( |
| 6937 | E->getOperatorNew(), E->getOperatorDelete(), E->getTypeIdParens(), |
| 6938 | E->getArraySize(), E->getInitializer(), E->getType(), |
| 6939 | E->getAllocatedTypeSourceInfo(), E->getSourceRange(), |
| 6940 | E->getDirectInitRange()); |
| 6941 | if (!Imp) |
| 6942 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6943 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6944 | FunctionDecl *ToOperatorNew, *ToOperatorDelete; |
| 6945 | SourceRange ToTypeIdParens, ToSourceRange, ToDirectInitRange; |
| 6946 | Expr *ToArraySize, *ToInitializer; |
| 6947 | QualType ToType; |
| 6948 | TypeSourceInfo *ToAllocatedTypeSourceInfo; |
| 6949 | std::tie( |
| 6950 | ToOperatorNew, ToOperatorDelete, ToTypeIdParens, ToArraySize, ToInitializer, |
| 6951 | ToType, ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6952 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6953 | SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs()); |
| 6954 | if (Error Err = |
| 6955 | ImportContainerChecked(E->placement_arguments(), ToPlacementArgs)) |
| 6956 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6957 | |
Bruno Ricci | 9b6dfac | 2019-01-07 15:04:45 +0000 | [diff] [blame] | 6958 | return CXXNewExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6959 | Importer.getToContext(), E->isGlobalNew(), ToOperatorNew, |
| 6960 | ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(), |
| 6961 | ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(), |
| 6962 | ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange, |
| 6963 | ToDirectInitRange); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6964 | } |
| 6965 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6966 | ExpectedStmt ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 6967 | auto Imp = importSeq( |
| 6968 | E->getType(), E->getOperatorDelete(), E->getArgument(), E->getBeginLoc()); |
| 6969 | if (!Imp) |
| 6970 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6971 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6972 | QualType ToType; |
| 6973 | FunctionDecl *ToOperatorDelete; |
| 6974 | Expr *ToArgument; |
| 6975 | SourceLocation ToBeginLoc; |
| 6976 | std::tie(ToType, ToOperatorDelete, ToArgument, ToBeginLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6977 | |
| 6978 | return new (Importer.getToContext()) CXXDeleteExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6979 | ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(), |
| 6980 | E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument, |
| 6981 | ToBeginLoc); |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6982 | } |
| 6983 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6984 | ExpectedStmt ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| 6985 | auto Imp = importSeq( |
| 6986 | E->getType(), E->getLocation(), E->getConstructor(), |
| 6987 | E->getParenOrBraceRange()); |
| 6988 | if (!Imp) |
| 6989 | return Imp.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6990 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6991 | QualType ToType; |
| 6992 | SourceLocation ToLocation; |
| 6993 | CXXConstructorDecl *ToConstructor; |
| 6994 | SourceRange ToParenOrBraceRange; |
| 6995 | std::tie(ToType, ToLocation, ToConstructor, ToParenOrBraceRange) = *Imp; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6996 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6997 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6998 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 6999 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7000 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7001 | return CXXConstructExpr::Create( |
| 7002 | Importer.getToContext(), ToType, ToLocation, ToConstructor, |
| 7003 | E->isElidable(), ToArgs, E->hadMultipleCandidates(), |
| 7004 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 7005 | E->requiresZeroInitialization(), E->getConstructionKind(), |
| 7006 | ToParenOrBraceRange); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7007 | } |
| 7008 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7009 | ExpectedStmt ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *E) { |
| 7010 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7011 | if (!ToSubExprOrErr) |
| 7012 | return ToSubExprOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7013 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7014 | SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects()); |
| 7015 | if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects)) |
| 7016 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7017 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7018 | return ExprWithCleanups::Create( |
| 7019 | Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(), |
| 7020 | ToObjects); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7021 | } |
| 7022 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7023 | ExpectedStmt ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 7024 | auto Imp = importSeq( |
| 7025 | E->getCallee(), E->getType(), E->getRParenLoc()); |
| 7026 | if (!Imp) |
| 7027 | return Imp.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7028 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7029 | Expr *ToCallee; |
| 7030 | QualType ToType; |
| 7031 | SourceLocation ToRParenLoc; |
| 7032 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7033 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7034 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7035 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7036 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7037 | |
Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7038 | return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, |
| 7039 | ToType, E->getValueKind(), ToRParenLoc); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7040 | } |
| 7041 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7042 | ExpectedStmt ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 7043 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7044 | if (!ToTypeOrErr) |
| 7045 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7046 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7047 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7048 | if (!ToLocationOrErr) |
| 7049 | return ToLocationOrErr.takeError(); |
| 7050 | |
| 7051 | return new (Importer.getToContext()) CXXThisExpr( |
| 7052 | *ToLocationOrErr, *ToTypeOrErr, E->isImplicit()); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7053 | } |
| 7054 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7055 | ExpectedStmt ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 7056 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7057 | if (!ToTypeOrErr) |
| 7058 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7059 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7060 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7061 | if (!ToLocationOrErr) |
| 7062 | return ToLocationOrErr.takeError(); |
| 7063 | |
| 7064 | return new (Importer.getToContext()) CXXBoolLiteralExpr( |
| 7065 | E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7066 | } |
| 7067 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7068 | ExpectedStmt ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| 7069 | auto Imp1 = importSeq( |
| 7070 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7071 | E->getTemplateKeywordLoc(), E->getMemberDecl(), E->getType()); |
| 7072 | if (!Imp1) |
| 7073 | return Imp1.takeError(); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7074 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7075 | Expr *ToBase; |
| 7076 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7077 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7078 | ValueDecl *ToMemberDecl; |
| 7079 | QualType ToType; |
| 7080 | std::tie( |
| 7081 | ToBase, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, |
| 7082 | ToType) = *Imp1; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7083 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7084 | auto Imp2 = importSeq( |
| 7085 | E->getFoundDecl().getDecl(), E->getMemberNameInfo().getName(), |
| 7086 | E->getMemberNameInfo().getLoc(), E->getLAngleLoc(), E->getRAngleLoc()); |
| 7087 | if (!Imp2) |
| 7088 | return Imp2.takeError(); |
| 7089 | NamedDecl *ToDecl; |
| 7090 | DeclarationName ToName; |
| 7091 | SourceLocation ToLoc, ToLAngleLoc, ToRAngleLoc; |
| 7092 | std::tie(ToDecl, ToName, ToLoc, ToLAngleLoc, ToRAngleLoc) = *Imp2; |
Peter Szecsi | ef97252 | 2018-05-02 11:52:54 +0000 | [diff] [blame] | 7093 | |
| 7094 | DeclAccessPair ToFoundDecl = |
| 7095 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7096 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7097 | DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7098 | |
| 7099 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7100 | // FIXME: handle template arguments |
| 7101 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7102 | } |
| 7103 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7104 | return MemberExpr::Create( |
| 7105 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, |
| 7106 | ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, ToFoundDecl, |
| 7107 | ToMemberNameInfo, nullptr, ToType, E->getValueKind(), E->getObjectKind()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7108 | } |
| 7109 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7110 | ExpectedStmt |
| 7111 | ASTNodeImporter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { |
| 7112 | auto Imp = importSeq( |
| 7113 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7114 | E->getScopeTypeInfo(), E->getColonColonLoc(), E->getTildeLoc()); |
| 7115 | if (!Imp) |
| 7116 | return Imp.takeError(); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7117 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7118 | Expr *ToBase; |
| 7119 | SourceLocation ToOperatorLoc, ToColonColonLoc, ToTildeLoc; |
| 7120 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7121 | TypeSourceInfo *ToScopeTypeInfo; |
| 7122 | std::tie( |
| 7123 | ToBase, ToOperatorLoc, ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, |
| 7124 | ToTildeLoc) = *Imp; |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7125 | |
| 7126 | PseudoDestructorTypeStorage Storage; |
| 7127 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { |
| 7128 | IdentifierInfo *ToII = Importer.Import(FromII); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7129 | ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc()); |
| 7130 | if (!ToDestroyedTypeLocOrErr) |
| 7131 | return ToDestroyedTypeLocOrErr.takeError(); |
| 7132 | Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7133 | } else { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7134 | if (auto ToTIOrErr = import(E->getDestroyedTypeInfo())) |
| 7135 | Storage = PseudoDestructorTypeStorage(*ToTIOrErr); |
| 7136 | else |
| 7137 | return ToTIOrErr.takeError(); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7138 | } |
| 7139 | |
| 7140 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7141 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, |
| 7142 | ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7143 | } |
| 7144 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7145 | ExpectedStmt ASTNodeImporter::VisitCXXDependentScopeMemberExpr( |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7146 | CXXDependentScopeMemberExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7147 | auto Imp = importSeq( |
| 7148 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7149 | E->getTemplateKeywordLoc(), E->getFirstQualifierFoundInScope()); |
| 7150 | if (!Imp) |
| 7151 | return Imp.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7152 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7153 | QualType ToType; |
| 7154 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7155 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7156 | NamedDecl *ToFirstQualifierFoundInScope; |
| 7157 | std::tie( |
| 7158 | ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7159 | ToFirstQualifierFoundInScope) = *Imp; |
| 7160 | |
| 7161 | Expr *ToBase = nullptr; |
| 7162 | if (!E->isImplicitAccess()) { |
| 7163 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7164 | ToBase = *ToBaseOrErr; |
| 7165 | else |
| 7166 | return ToBaseOrErr.takeError(); |
| 7167 | } |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7168 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7169 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7170 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7171 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7172 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7173 | ToTAInfo)) |
| 7174 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7175 | ResInfo = &ToTAInfo; |
| 7176 | } |
| 7177 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7178 | auto ToMemberNameInfoOrErr = importSeq(E->getMember(), E->getMemberLoc()); |
| 7179 | if (!ToMemberNameInfoOrErr) |
| 7180 | return ToMemberNameInfoOrErr.takeError(); |
| 7181 | DeclarationNameInfo ToMemberNameInfo( |
| 7182 | std::get<0>(*ToMemberNameInfoOrErr), std::get<1>(*ToMemberNameInfoOrErr)); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7183 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7184 | if (Error Err = ImportDeclarationNameLoc( |
| 7185 | E->getMemberNameInfo(), ToMemberNameInfo)) |
| 7186 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7187 | |
| 7188 | return CXXDependentScopeMemberExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7189 | Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc, |
| 7190 | ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope, |
| 7191 | ToMemberNameInfo, ResInfo); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7192 | } |
| 7193 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7194 | ExpectedStmt |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7195 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7196 | auto Imp = importSeq( |
| 7197 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDeclName(), |
| 7198 | E->getExprLoc(), E->getLAngleLoc(), E->getRAngleLoc()); |
| 7199 | if (!Imp) |
| 7200 | return Imp.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7201 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7202 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7203 | SourceLocation ToTemplateKeywordLoc, ToExprLoc, ToLAngleLoc, ToRAngleLoc; |
| 7204 | DeclarationName ToDeclName; |
| 7205 | std::tie( |
| 7206 | ToQualifierLoc, ToTemplateKeywordLoc, ToDeclName, ToExprLoc, |
| 7207 | ToLAngleLoc, ToRAngleLoc) = *Imp; |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7208 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7209 | DeclarationNameInfo ToNameInfo(ToDeclName, ToExprLoc); |
| 7210 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7211 | return std::move(Err); |
| 7212 | |
| 7213 | TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7214 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7215 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7216 | if (Error Err = |
| 7217 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 7218 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7219 | ResInfo = &ToTAInfo; |
| 7220 | } |
| 7221 | |
| 7222 | return DependentScopeDeclRefExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7223 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, |
| 7224 | ToNameInfo, ResInfo); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7225 | } |
| 7226 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7227 | ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr( |
| 7228 | CXXUnresolvedConstructExpr *E) { |
| 7229 | auto Imp = importSeq( |
| 7230 | E->getLParenLoc(), E->getRParenLoc(), E->getTypeSourceInfo()); |
| 7231 | if (!Imp) |
| 7232 | return Imp.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7233 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7234 | SourceLocation ToLParenLoc, ToRParenLoc; |
| 7235 | TypeSourceInfo *ToTypeSourceInfo; |
| 7236 | std::tie(ToLParenLoc, ToRParenLoc, ToTypeSourceInfo) = *Imp; |
| 7237 | |
| 7238 | SmallVector<Expr *, 8> ToArgs(E->arg_size()); |
| 7239 | if (Error Err = |
| 7240 | ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin())) |
| 7241 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7242 | |
| 7243 | return CXXUnresolvedConstructExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7244 | Importer.getToContext(), ToTypeSourceInfo, ToLParenLoc, |
| 7245 | llvm::makeArrayRef(ToArgs), ToRParenLoc); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7246 | } |
| 7247 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7248 | ExpectedStmt |
| 7249 | ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { |
| 7250 | Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass()); |
| 7251 | if (!ToNamingClassOrErr) |
| 7252 | return ToNamingClassOrErr.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7253 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7254 | auto ToQualifierLocOrErr = import(E->getQualifierLoc()); |
| 7255 | if (!ToQualifierLocOrErr) |
| 7256 | return ToQualifierLocOrErr.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7257 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7258 | auto ToNameInfoOrErr = importSeq(E->getName(), E->getNameLoc()); |
| 7259 | if (!ToNameInfoOrErr) |
| 7260 | return ToNameInfoOrErr.takeError(); |
| 7261 | DeclarationNameInfo ToNameInfo( |
| 7262 | std::get<0>(*ToNameInfoOrErr), std::get<1>(*ToNameInfoOrErr)); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7263 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7264 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7265 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7266 | |
| 7267 | UnresolvedSet<8> ToDecls; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7268 | for (auto *D : E->decls()) |
| 7269 | if (auto ToDOrErr = import(D)) |
| 7270 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7271 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7272 | return ToDOrErr.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7273 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7274 | if (E->hasExplicitTemplateArgs() && E->getTemplateKeywordLoc().isValid()) { |
| 7275 | TemplateArgumentListInfo ToTAInfo; |
| 7276 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7277 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7278 | ToTAInfo)) |
| 7279 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7280 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7281 | ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc()); |
| 7282 | if (!ToTemplateKeywordLocOrErr) |
| 7283 | return ToTemplateKeywordLocOrErr.takeError(); |
| 7284 | |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7285 | return UnresolvedLookupExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7286 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7287 | *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo, |
| 7288 | ToDecls.begin(), ToDecls.end()); |
| 7289 | } |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7290 | |
| 7291 | return UnresolvedLookupExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7292 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7293 | ToNameInfo, E->requiresADL(), E->isOverloaded(), ToDecls.begin(), |
| 7294 | ToDecls.end()); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7295 | } |
| 7296 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7297 | ExpectedStmt |
| 7298 | ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { |
| 7299 | auto Imp1 = importSeq( |
| 7300 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7301 | E->getTemplateKeywordLoc()); |
| 7302 | if (!Imp1) |
| 7303 | return Imp1.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7304 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7305 | QualType ToType; |
| 7306 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7307 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7308 | std::tie(ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc) = *Imp1; |
| 7309 | |
| 7310 | auto Imp2 = importSeq(E->getName(), E->getNameLoc()); |
| 7311 | if (!Imp2) |
| 7312 | return Imp2.takeError(); |
| 7313 | DeclarationNameInfo ToNameInfo(std::get<0>(*Imp2), std::get<1>(*Imp2)); |
| 7314 | // Import additional name location/type info. |
| 7315 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7316 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7317 | |
| 7318 | UnresolvedSet<8> ToDecls; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7319 | for (Decl *D : E->decls()) |
| 7320 | if (auto ToDOrErr = import(D)) |
| 7321 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7322 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7323 | return ToDOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7324 | |
| 7325 | TemplateArgumentListInfo ToTAInfo; |
| 7326 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7327 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7328 | if (Error Err = |
| 7329 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 7330 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7331 | ResInfo = &ToTAInfo; |
| 7332 | } |
| 7333 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7334 | Expr *ToBase = nullptr; |
| 7335 | if (!E->isImplicitAccess()) { |
| 7336 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7337 | ToBase = *ToBaseOrErr; |
| 7338 | else |
| 7339 | return ToBaseOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7340 | } |
| 7341 | |
| 7342 | return UnresolvedMemberExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7343 | Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType, |
| 7344 | E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7345 | ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end()); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7346 | } |
| 7347 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7348 | ExpectedStmt ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| 7349 | auto Imp = importSeq(E->getCallee(), E->getType(), E->getRParenLoc()); |
| 7350 | if (!Imp) |
| 7351 | return Imp.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7352 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7353 | Expr *ToCallee; |
| 7354 | QualType ToType; |
| 7355 | SourceLocation ToRParenLoc; |
| 7356 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7357 | |
| 7358 | unsigned NumArgs = E->getNumArgs(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7359 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); |
| 7360 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7361 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7362 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7363 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { |
Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7364 | return CXXOperatorCallExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7365 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType, |
Eric Fiselier | 5cdc2cd | 2018-12-12 21:50:55 +0000 | [diff] [blame] | 7366 | OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(), |
| 7367 | OCE->getADLCallKind()); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7368 | } |
| 7369 | |
Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7370 | return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType, |
| 7371 | E->getValueKind(), ToRParenLoc, /*MinNumArgs=*/0, |
| 7372 | E->getADLCallKind()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7373 | } |
| 7374 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7375 | ExpectedStmt ASTNodeImporter::VisitLambdaExpr(LambdaExpr *E) { |
| 7376 | CXXRecordDecl *FromClass = E->getLambdaClass(); |
| 7377 | auto ToClassOrErr = import(FromClass); |
| 7378 | if (!ToClassOrErr) |
| 7379 | return ToClassOrErr.takeError(); |
| 7380 | CXXRecordDecl *ToClass = *ToClassOrErr; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7381 | |
| 7382 | // NOTE: lambda classes are created with BeingDefined flag set up. |
| 7383 | // It means that ImportDefinition doesn't work for them and we should fill it |
| 7384 | // manually. |
| 7385 | if (ToClass->isBeingDefined()) { |
| 7386 | for (auto FromField : FromClass->fields()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7387 | auto ToFieldOrErr = import(FromField); |
| 7388 | if (!ToFieldOrErr) |
| 7389 | return ToFieldOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7390 | } |
| 7391 | } |
| 7392 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7393 | auto ToCallOpOrErr = import(E->getCallOperator()); |
| 7394 | if (!ToCallOpOrErr) |
| 7395 | return ToCallOpOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7396 | |
| 7397 | ToClass->completeDefinition(); |
| 7398 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7399 | SmallVector<LambdaCapture, 8> ToCaptures; |
| 7400 | ToCaptures.reserve(E->capture_size()); |
| 7401 | for (const auto &FromCapture : E->captures()) { |
| 7402 | if (auto ToCaptureOrErr = import(FromCapture)) |
| 7403 | ToCaptures.push_back(*ToCaptureOrErr); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7404 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7405 | return ToCaptureOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7406 | } |
| 7407 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7408 | SmallVector<Expr *, 8> ToCaptureInits(E->capture_size()); |
| 7409 | if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits)) |
| 7410 | return std::move(Err); |
| 7411 | |
| 7412 | auto Imp = importSeq( |
| 7413 | E->getIntroducerRange(), E->getCaptureDefaultLoc(), E->getEndLoc()); |
| 7414 | if (!Imp) |
| 7415 | return Imp.takeError(); |
| 7416 | |
| 7417 | SourceRange ToIntroducerRange; |
| 7418 | SourceLocation ToCaptureDefaultLoc, ToEndLoc; |
| 7419 | std::tie(ToIntroducerRange, ToCaptureDefaultLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7420 | |
Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 7421 | return LambdaExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7422 | Importer.getToContext(), ToClass, ToIntroducerRange, |
| 7423 | E->getCaptureDefault(), ToCaptureDefaultLoc, ToCaptures, |
| 7424 | E->hasExplicitParameters(), E->hasExplicitResultType(), ToCaptureInits, |
| 7425 | ToEndLoc, E->containsUnexpandedParameterPack()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7426 | } |
| 7427 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7428 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7429 | ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) { |
| 7430 | auto Imp = importSeq(E->getLBraceLoc(), E->getRBraceLoc(), E->getType()); |
| 7431 | if (!Imp) |
| 7432 | return Imp.takeError(); |
| 7433 | |
| 7434 | SourceLocation ToLBraceLoc, ToRBraceLoc; |
| 7435 | QualType ToType; |
| 7436 | std::tie(ToLBraceLoc, ToRBraceLoc, ToType) = *Imp; |
| 7437 | |
| 7438 | SmallVector<Expr *, 4> ToExprs(E->getNumInits()); |
| 7439 | if (Error Err = ImportContainerChecked(E->inits(), ToExprs)) |
| 7440 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7441 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7442 | ASTContext &ToCtx = Importer.getToContext(); |
| 7443 | InitListExpr *To = new (ToCtx) InitListExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7444 | ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc); |
| 7445 | To->setType(ToType); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7446 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7447 | if (E->hasArrayFiller()) { |
| 7448 | if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller())) |
| 7449 | To->setArrayFiller(*ToFillerOrErr); |
| 7450 | else |
| 7451 | return ToFillerOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7452 | } |
| 7453 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7454 | if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) { |
| 7455 | if (auto ToFDOrErr = import(FromFD)) |
| 7456 | To->setInitializedFieldInUnion(*ToFDOrErr); |
| 7457 | else |
| 7458 | return ToFDOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7459 | } |
| 7460 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7461 | if (InitListExpr *SyntForm = E->getSyntacticForm()) { |
| 7462 | if (auto ToSyntFormOrErr = import(SyntForm)) |
| 7463 | To->setSyntacticForm(*ToSyntFormOrErr); |
| 7464 | else |
| 7465 | return ToSyntFormOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7466 | } |
| 7467 | |
Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7468 | // Copy InitListExprBitfields, which are not handled in the ctor of |
| 7469 | // InitListExpr. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7470 | To->sawArrayRangeDesignator(E->hadArrayRangeDesignator()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7471 | |
| 7472 | return To; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7473 | } |
| 7474 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7475 | ExpectedStmt ASTNodeImporter::VisitCXXStdInitializerListExpr( |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7476 | CXXStdInitializerListExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7477 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7478 | if (!ToTypeOrErr) |
| 7479 | return ToTypeOrErr.takeError(); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7480 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7481 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7482 | if (!ToSubExprOrErr) |
| 7483 | return ToSubExprOrErr.takeError(); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7484 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7485 | return new (Importer.getToContext()) CXXStdInitializerListExpr( |
| 7486 | *ToTypeOrErr, *ToSubExprOrErr); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7487 | } |
| 7488 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7489 | ExpectedStmt ASTNodeImporter::VisitCXXInheritedCtorInitExpr( |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7490 | CXXInheritedCtorInitExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7491 | auto Imp = importSeq(E->getLocation(), E->getType(), E->getConstructor()); |
| 7492 | if (!Imp) |
| 7493 | return Imp.takeError(); |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7494 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7495 | SourceLocation ToLocation; |
| 7496 | QualType ToType; |
| 7497 | CXXConstructorDecl *ToConstructor; |
| 7498 | std::tie(ToLocation, ToType, ToConstructor) = *Imp; |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7499 | |
| 7500 | return new (Importer.getToContext()) CXXInheritedCtorInitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7501 | ToLocation, ToType, ToConstructor, E->constructsVBase(), |
| 7502 | E->inheritedFromVBase()); |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7503 | } |
| 7504 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7505 | ExpectedStmt ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 7506 | auto Imp = importSeq(E->getType(), E->getCommonExpr(), E->getSubExpr()); |
| 7507 | if (!Imp) |
| 7508 | return Imp.takeError(); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7509 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7510 | QualType ToType; |
| 7511 | Expr *ToCommonExpr, *ToSubExpr; |
| 7512 | std::tie(ToType, ToCommonExpr, ToSubExpr) = *Imp; |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7513 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7514 | return new (Importer.getToContext()) ArrayInitLoopExpr( |
| 7515 | ToType, ToCommonExpr, ToSubExpr); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7516 | } |
| 7517 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7518 | ExpectedStmt ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 7519 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7520 | if (!ToTypeOrErr) |
| 7521 | return ToTypeOrErr.takeError(); |
| 7522 | return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7523 | } |
| 7524 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7525 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 7526 | ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc()); |
| 7527 | if (!ToBeginLocOrErr) |
| 7528 | return ToBeginLocOrErr.takeError(); |
| 7529 | |
| 7530 | auto ToFieldOrErr = import(E->getField()); |
| 7531 | if (!ToFieldOrErr) |
| 7532 | return ToFieldOrErr.takeError(); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7533 | |
| 7534 | return CXXDefaultInitExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7535 | Importer.getToContext(), *ToBeginLocOrErr, *ToFieldOrErr); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7536 | } |
| 7537 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7538 | ExpectedStmt ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 7539 | auto Imp = importSeq( |
| 7540 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten(), |
| 7541 | E->getOperatorLoc(), E->getRParenLoc(), E->getAngleBrackets()); |
| 7542 | if (!Imp) |
| 7543 | return Imp.takeError(); |
| 7544 | |
| 7545 | QualType ToType; |
| 7546 | Expr *ToSubExpr; |
| 7547 | TypeSourceInfo *ToTypeInfoAsWritten; |
| 7548 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 7549 | SourceRange ToAngleBrackets; |
| 7550 | std::tie( |
| 7551 | ToType, ToSubExpr, ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, |
| 7552 | ToAngleBrackets) = *Imp; |
| 7553 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7554 | ExprValueKind VK = E->getValueKind(); |
| 7555 | CastKind CK = E->getCastKind(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7556 | auto ToBasePathOrErr = ImportCastPath(E); |
| 7557 | if (!ToBasePathOrErr) |
| 7558 | return ToBasePathOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7559 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7560 | if (isa<CXXStaticCastExpr>(E)) { |
| 7561 | return CXXStaticCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7562 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7563 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7564 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 7565 | return CXXDynamicCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7566 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7567 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7568 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 7569 | return CXXReinterpretCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7570 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7571 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Raphael Isemann | c705bb8 | 2018-08-20 16:20:01 +0000 | [diff] [blame] | 7572 | } else if (isa<CXXConstCastExpr>(E)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7573 | return CXXConstCastExpr::Create( |
| 7574 | Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten, |
| 7575 | ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7576 | } else { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7577 | llvm_unreachable("Unknown cast type"); |
| 7578 | return make_error<ImportError>(); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7579 | } |
| 7580 | } |
| 7581 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7582 | ExpectedStmt ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7583 | SubstNonTypeTemplateParmExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7584 | auto Imp = importSeq( |
| 7585 | E->getType(), E->getExprLoc(), E->getParameter(), E->getReplacement()); |
| 7586 | if (!Imp) |
| 7587 | return Imp.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7588 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7589 | QualType ToType; |
| 7590 | SourceLocation ToExprLoc; |
| 7591 | NonTypeTemplateParmDecl *ToParameter; |
| 7592 | Expr *ToReplacement; |
| 7593 | std::tie(ToType, ToExprLoc, ToParameter, ToReplacement) = *Imp; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7594 | |
| 7595 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7596 | ToType, E->getValueKind(), ToExprLoc, ToParameter, ToReplacement); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7597 | } |
| 7598 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7599 | ExpectedStmt ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { |
| 7600 | auto Imp = importSeq( |
| 7601 | E->getType(), E->getBeginLoc(), E->getEndLoc()); |
| 7602 | if (!Imp) |
| 7603 | return Imp.takeError(); |
| 7604 | |
| 7605 | QualType ToType; |
| 7606 | SourceLocation ToBeginLoc, ToEndLoc; |
| 7607 | std::tie(ToType, ToBeginLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7608 | |
| 7609 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7610 | if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs)) |
| 7611 | return std::move(Err); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7612 | |
| 7613 | // According to Sema::BuildTypeTrait(), if E is value-dependent, |
| 7614 | // Value is always false. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7615 | bool ToValue = (E->isValueDependent() ? false : E->getValue()); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7616 | |
| 7617 | return TypeTraitExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7618 | Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs, |
| 7619 | ToEndLoc, ToValue); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7620 | } |
| 7621 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7622 | ExpectedStmt ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { |
| 7623 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7624 | if (!ToTypeOrErr) |
| 7625 | return ToTypeOrErr.takeError(); |
| 7626 | |
| 7627 | auto ToSourceRangeOrErr = import(E->getSourceRange()); |
| 7628 | if (!ToSourceRangeOrErr) |
| 7629 | return ToSourceRangeOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7630 | |
| 7631 | if (E->isTypeOperand()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7632 | if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo())) |
| 7633 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7634 | *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr); |
| 7635 | else |
| 7636 | return ToTSIOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7637 | } |
| 7638 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7639 | ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand()); |
| 7640 | if (!ToExprOperandOrErr) |
| 7641 | return ToExprOperandOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7642 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7643 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7644 | *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7645 | } |
| 7646 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7647 | void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod, |
| 7648 | CXXMethodDecl *FromMethod) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7649 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) { |
| 7650 | if (auto ImportedOrErr = import(FromOverriddenMethod)) |
| 7651 | ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>( |
| 7652 | (*ImportedOrErr)->getCanonicalDecl())); |
| 7653 | else |
| 7654 | consumeError(ImportedOrErr.takeError()); |
| 7655 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7656 | } |
| 7657 | |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7658 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7659 | ASTContext &FromContext, FileManager &FromFileManager, |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7660 | bool MinimalImport, |
| 7661 | ASTImporterLookupTable *LookupTable) |
| 7662 | : LookupTable(LookupTable), ToContext(ToContext), FromContext(FromContext), |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7663 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
| 7664 | Minimal(MinimalImport) { |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7665 | |
| 7666 | ImportedDecls[FromContext.getTranslationUnitDecl()] = |
| 7667 | ToContext.getTranslationUnitDecl(); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7668 | } |
| 7669 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7670 | ASTImporter::~ASTImporter() = default; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7671 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7672 | Expected<QualType> ASTImporter::Import_New(QualType FromT) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7673 | QualType ToT = Import(FromT); |
| 7674 | if (ToT.isNull() && !FromT.isNull()) |
| 7675 | return make_error<ImportError>(); |
| 7676 | return ToT; |
| 7677 | } |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7678 | |
| 7679 | Optional<unsigned> ASTImporter::getFieldIndex(Decl *F) { |
| 7680 | assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) && |
| 7681 | "Try to get field index for non-field."); |
| 7682 | |
| 7683 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); |
| 7684 | if (!Owner) |
| 7685 | return None; |
| 7686 | |
| 7687 | unsigned Index = 0; |
| 7688 | for (const auto *D : Owner->decls()) { |
| 7689 | if (D == F) |
| 7690 | return Index; |
| 7691 | |
| 7692 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) |
| 7693 | ++Index; |
| 7694 | } |
| 7695 | |
| 7696 | llvm_unreachable("Field was not found in its parent context."); |
| 7697 | |
| 7698 | return None; |
| 7699 | } |
| 7700 | |
| 7701 | ASTImporter::FoundDeclsTy |
| 7702 | ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) { |
| 7703 | // We search in the redecl context because of transparent contexts. |
| 7704 | // E.g. a simple C language enum is a transparent context: |
| 7705 | // enum E { A, B }; |
| 7706 | // Now if we had a global variable in the TU |
| 7707 | // int A; |
| 7708 | // then the enum constant 'A' and the variable 'A' violates ODR. |
| 7709 | // We can diagnose this only if we search in the redecl context. |
| 7710 | DeclContext *ReDC = DC->getRedeclContext(); |
| 7711 | if (LookupTable) { |
| 7712 | ASTImporterLookupTable::LookupResult LookupResult = |
| 7713 | LookupTable->lookup(ReDC, Name); |
| 7714 | return FoundDeclsTy(LookupResult.begin(), LookupResult.end()); |
| 7715 | } else { |
| 7716 | // FIXME Can we remove this kind of lookup? |
| 7717 | // Or lldb really needs this C/C++ lookup? |
| 7718 | FoundDeclsTy Result; |
| 7719 | ReDC->localUncachedLookup(Name, Result); |
| 7720 | return Result; |
| 7721 | } |
| 7722 | } |
| 7723 | |
| 7724 | void ASTImporter::AddToLookupTable(Decl *ToD) { |
| 7725 | if (LookupTable) |
| 7726 | if (auto *ToND = dyn_cast<NamedDecl>(ToD)) |
| 7727 | LookupTable->add(ToND); |
| 7728 | } |
| 7729 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7730 | QualType ASTImporter::Import(QualType FromT) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7731 | if (FromT.isNull()) |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7732 | return {}; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7733 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7734 | const Type *FromTy = FromT.getTypePtr(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7735 | |
| 7736 | // Check whether we've already imported this type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7737 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7738 | = ImportedTypes.find(FromTy); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7739 | if (Pos != ImportedTypes.end()) |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7740 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7741 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7742 | // Import the type |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7743 | ASTNodeImporter Importer(*this); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7744 | ExpectedType ToTOrErr = Importer.Visit(FromTy); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7745 | if (!ToTOrErr) { |
| 7746 | llvm::consumeError(ToTOrErr.takeError()); |
| 7747 | return {}; |
| 7748 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7749 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7750 | // Record the imported type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7751 | ImportedTypes[FromTy] = (*ToTOrErr).getTypePtr(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7752 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7753 | return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7754 | } |
| 7755 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7756 | Expected<TypeSourceInfo *> ASTImporter::Import_New(TypeSourceInfo *FromTSI) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7757 | TypeSourceInfo *ToTSI = Import(FromTSI); |
| 7758 | if (!ToTSI && FromTSI) |
| 7759 | return llvm::make_error<ImportError>(); |
| 7760 | return ToTSI; |
| 7761 | } |
| 7762 | TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) { |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7763 | if (!FromTSI) |
| 7764 | return FromTSI; |
| 7765 | |
| 7766 | // FIXME: For now we just create a "trivial" type source info based |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 7767 | // on the type and a single location. Implement a real version of this. |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7768 | QualType T = Import(FromTSI->getType()); |
| 7769 | if (T.isNull()) |
| 7770 | return nullptr; |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7771 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7772 | return ToContext.getTrivialTypeSourceInfo( |
| 7773 | T, Import(FromTSI->getTypeLoc().getBeginLoc())); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7774 | } |
| 7775 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7776 | Expected<Attr *> ASTImporter::Import_New(const Attr *FromAttr) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7777 | return Import(FromAttr); |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 7778 | } |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7779 | Attr *ASTImporter::Import(const Attr *FromAttr) { |
| 7780 | Attr *ToAttr = FromAttr->clone(ToContext); |
| 7781 | // NOTE: Import of SourceRange may fail. |
| 7782 | ToAttr->setRange(Import(FromAttr->getRange())); |
| 7783 | return ToAttr; |
Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 7784 | } |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 7785 | |
Gabor Marton | be77a98 | 2018-12-12 11:22:55 +0000 | [diff] [blame] | 7786 | Decl *ASTImporter::GetAlreadyImportedOrNull(const Decl *FromD) const { |
| 7787 | auto Pos = ImportedDecls.find(FromD); |
| 7788 | if (Pos != ImportedDecls.end()) |
| 7789 | return Pos->second; |
| 7790 | else |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7791 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7792 | } |
| 7793 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7794 | Expected<Decl *> ASTImporter::Import_New(Decl *FromD) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7795 | Decl *ToD = Import(FromD); |
| 7796 | if (!ToD && FromD) |
| 7797 | return llvm::make_error<ImportError>(); |
| 7798 | return ToD; |
| 7799 | } |
| 7800 | Decl *ASTImporter::Import(Decl *FromD) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7801 | if (!FromD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7802 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7803 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7804 | ASTNodeImporter Importer(*this); |
| 7805 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7806 | // Check whether we've already imported this declaration. |
| 7807 | Decl *ToD = GetAlreadyImportedOrNull(FromD); |
| 7808 | if (ToD) { |
| 7809 | // If FromD has some updated flags after last import, apply it |
| 7810 | updateFlags(FromD, ToD); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7811 | return ToD; |
| 7812 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7813 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7814 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7815 | ExpectedDecl ToDOrErr = Importer.Visit(FromD); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7816 | if (!ToDOrErr) { |
| 7817 | llvm::consumeError(ToDOrErr.takeError()); |
| 7818 | return nullptr; |
| 7819 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7820 | ToD = *ToDOrErr; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7821 | |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7822 | // Once the decl is connected to the existing declarations, i.e. when the |
| 7823 | // redecl chain is properly set then we populate the lookup again. |
| 7824 | // This way the primary context will be able to find all decls. |
| 7825 | AddToLookupTable(ToD); |
| 7826 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7827 | // Notify subclasses. |
| 7828 | Imported(FromD, ToD); |
| 7829 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 7830 | updateFlags(FromD, ToD); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7831 | return ToD; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7832 | } |
| 7833 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7834 | Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7835 | if (!FromDC) |
| 7836 | return FromDC; |
| 7837 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7838 | auto *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC))); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7839 | if (!ToDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7840 | return nullptr; |
| 7841 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7842 | // 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] | 7843 | // need it to have a definition. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7844 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
| 7845 | auto *FromRecord = cast<RecordDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7846 | if (ToRecord->isCompleteDefinition()) { |
| 7847 | // Do nothing. |
| 7848 | } else if (FromRecord->isCompleteDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7849 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7850 | FromRecord, ToRecord, ASTNodeImporter::IDK_Basic)) |
| 7851 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7852 | } else { |
| 7853 | CompleteDecl(ToRecord); |
| 7854 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7855 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 7856 | auto *FromEnum = cast<EnumDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7857 | if (ToEnum->isCompleteDefinition()) { |
| 7858 | // Do nothing. |
| 7859 | } else if (FromEnum->isCompleteDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7860 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7861 | FromEnum, ToEnum, ASTNodeImporter::IDK_Basic)) |
| 7862 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7863 | } else { |
| 7864 | CompleteDecl(ToEnum); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7865 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7866 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 7867 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7868 | if (ToClass->getDefinition()) { |
| 7869 | // Do nothing. |
| 7870 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7871 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7872 | FromDef, ToClass, ASTNodeImporter::IDK_Basic)) |
| 7873 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7874 | } else { |
| 7875 | CompleteDecl(ToClass); |
| 7876 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7877 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 7878 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7879 | if (ToProto->getDefinition()) { |
| 7880 | // Do nothing. |
| 7881 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7882 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7883 | FromDef, ToProto, ASTNodeImporter::IDK_Basic)) |
| 7884 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7885 | } else { |
| 7886 | CompleteDecl(ToProto); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7887 | } |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7888 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7889 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7890 | return ToDC; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7891 | } |
| 7892 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7893 | Expected<Expr *> ASTImporter::Import_New(Expr *FromE) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7894 | Expr *ToE = Import(FromE); |
| 7895 | if (!ToE && FromE) |
| 7896 | return llvm::make_error<ImportError>(); |
| 7897 | return ToE; |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7898 | } |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7899 | Expr *ASTImporter::Import(Expr *FromE) { |
| 7900 | if (!FromE) |
| 7901 | return nullptr; |
| 7902 | |
| 7903 | return cast_or_null<Expr>(Import(cast<Stmt>(FromE))); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7904 | } |
| 7905 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7906 | Expected<Stmt *> ASTImporter::Import_New(Stmt *FromS) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7907 | Stmt *ToS = Import(FromS); |
| 7908 | if (!ToS && FromS) |
| 7909 | return llvm::make_error<ImportError>(); |
| 7910 | return ToS; |
| 7911 | } |
| 7912 | Stmt *ASTImporter::Import(Stmt *FromS) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7913 | if (!FromS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7914 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7915 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7916 | // Check whether we've already imported this declaration. |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7917 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 7918 | if (Pos != ImportedStmts.end()) |
| 7919 | return Pos->second; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7920 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7921 | // Import the statement. |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7922 | ASTNodeImporter Importer(*this); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7923 | ExpectedStmt ToSOrErr = Importer.Visit(FromS); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7924 | if (!ToSOrErr) { |
| 7925 | llvm::consumeError(ToSOrErr.takeError()); |
| 7926 | return nullptr; |
| 7927 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7928 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7929 | if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) { |
Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7930 | auto *FromE = cast<Expr>(FromS); |
| 7931 | // Copy ExprBitfields, which may not be handled in Expr subclasses |
| 7932 | // constructors. |
| 7933 | ToE->setValueKind(FromE->getValueKind()); |
| 7934 | ToE->setObjectKind(FromE->getObjectKind()); |
| 7935 | ToE->setTypeDependent(FromE->isTypeDependent()); |
| 7936 | ToE->setValueDependent(FromE->isValueDependent()); |
| 7937 | ToE->setInstantiationDependent(FromE->isInstantiationDependent()); |
| 7938 | ToE->setContainsUnexpandedParameterPack( |
| 7939 | FromE->containsUnexpandedParameterPack()); |
| 7940 | } |
| 7941 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7942 | // Record the imported declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7943 | ImportedStmts[FromS] = *ToSOrErr; |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7944 | return *ToSOrErr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7945 | } |
| 7946 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7947 | Expected<NestedNameSpecifier *> |
| 7948 | ASTImporter::Import_New(NestedNameSpecifier *FromNNS) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7949 | NestedNameSpecifier *ToNNS = Import(FromNNS); |
| 7950 | if (!ToNNS && FromNNS) |
| 7951 | return llvm::make_error<ImportError>(); |
| 7952 | return ToNNS; |
| 7953 | } |
| 7954 | NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7955 | if (!FromNNS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7956 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7957 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7958 | NestedNameSpecifier *prefix = Import(FromNNS->getPrefix()); |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7959 | |
| 7960 | switch (FromNNS->getKind()) { |
| 7961 | case NestedNameSpecifier::Identifier: |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7962 | if (IdentifierInfo *II = Import(FromNNS->getAsIdentifier())) { |
| 7963 | return NestedNameSpecifier::Create(ToContext, prefix, II); |
| 7964 | } |
| 7965 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7966 | |
| 7967 | case NestedNameSpecifier::Namespace: |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7968 | if (auto *NS = |
| 7969 | cast_or_null<NamespaceDecl>(Import(FromNNS->getAsNamespace()))) { |
| 7970 | return NestedNameSpecifier::Create(ToContext, prefix, NS); |
| 7971 | } |
| 7972 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7973 | |
| 7974 | case NestedNameSpecifier::NamespaceAlias: |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7975 | if (auto *NSAD = |
| 7976 | cast_or_null<NamespaceAliasDecl>(Import(FromNNS->getAsNamespaceAlias()))) { |
| 7977 | return NestedNameSpecifier::Create(ToContext, prefix, NSAD); |
| 7978 | } |
| 7979 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7980 | |
| 7981 | case NestedNameSpecifier::Global: |
| 7982 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 7983 | |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7984 | case NestedNameSpecifier::Super: |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7985 | if (auto *RD = |
| 7986 | cast_or_null<CXXRecordDecl>(Import(FromNNS->getAsRecordDecl()))) { |
| 7987 | return NestedNameSpecifier::SuperSpecifier(ToContext, RD); |
| 7988 | } |
| 7989 | return nullptr; |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7990 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7991 | case NestedNameSpecifier::TypeSpec: |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7992 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 7993 | QualType T = Import(QualType(FromNNS->getAsType(), 0u)); |
| 7994 | if (!T.isNull()) { |
| 7995 | bool bTemplate = FromNNS->getKind() == |
| 7996 | NestedNameSpecifier::TypeSpecWithTemplate; |
| 7997 | return NestedNameSpecifier::Create(ToContext, prefix, |
| 7998 | bTemplate, T.getTypePtr()); |
| 7999 | } |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8000 | } |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8001 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8002 | } |
| 8003 | |
| 8004 | llvm_unreachable("Invalid nested name specifier kind"); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8005 | } |
| 8006 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8007 | Expected<NestedNameSpecifierLoc> |
| 8008 | ASTImporter::Import_New(NestedNameSpecifierLoc FromNNS) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8009 | NestedNameSpecifierLoc ToNNS = Import(FromNNS); |
| 8010 | return ToNNS; |
| 8011 | } |
| 8012 | NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8013 | // Copied from NestedNameSpecifier mostly. |
| 8014 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 8015 | NestedNameSpecifierLoc NNS = FromNNS; |
| 8016 | |
| 8017 | // Push each of the nested-name-specifiers's onto a stack for |
| 8018 | // serialization in reverse order. |
| 8019 | while (NNS) { |
| 8020 | NestedNames.push_back(NNS); |
| 8021 | NNS = NNS.getPrefix(); |
| 8022 | } |
| 8023 | |
| 8024 | NestedNameSpecifierLocBuilder Builder; |
| 8025 | |
| 8026 | while (!NestedNames.empty()) { |
| 8027 | NNS = NestedNames.pop_back_val(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8028 | NestedNameSpecifier *Spec = Import(NNS.getNestedNameSpecifier()); |
| 8029 | if (!Spec) |
| 8030 | return NestedNameSpecifierLoc(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8031 | |
| 8032 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
| 8033 | switch (Kind) { |
| 8034 | case NestedNameSpecifier::Identifier: |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8035 | Builder.Extend(getToContext(), |
| 8036 | Spec->getAsIdentifier(), |
| 8037 | Import(NNS.getLocalBeginLoc()), |
| 8038 | Import(NNS.getLocalEndLoc())); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8039 | break; |
| 8040 | |
| 8041 | case NestedNameSpecifier::Namespace: |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8042 | Builder.Extend(getToContext(), |
| 8043 | Spec->getAsNamespace(), |
| 8044 | Import(NNS.getLocalBeginLoc()), |
| 8045 | Import(NNS.getLocalEndLoc())); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8046 | break; |
| 8047 | |
| 8048 | case NestedNameSpecifier::NamespaceAlias: |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8049 | Builder.Extend(getToContext(), |
| 8050 | Spec->getAsNamespaceAlias(), |
| 8051 | Import(NNS.getLocalBeginLoc()), |
| 8052 | Import(NNS.getLocalEndLoc())); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8053 | break; |
| 8054 | |
| 8055 | case NestedNameSpecifier::TypeSpec: |
| 8056 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 8057 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
| 8058 | QualType(Spec->getAsType(), 0)); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8059 | Builder.Extend(getToContext(), |
| 8060 | Import(NNS.getLocalBeginLoc()), |
| 8061 | TSI->getTypeLoc(), |
| 8062 | Import(NNS.getLocalEndLoc())); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8063 | break; |
| 8064 | } |
| 8065 | |
| 8066 | case NestedNameSpecifier::Global: |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8067 | Builder.MakeGlobal(getToContext(), Import(NNS.getLocalBeginLoc())); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8068 | break; |
| 8069 | |
| 8070 | case NestedNameSpecifier::Super: { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8071 | SourceRange ToRange = Import(NNS.getSourceRange()); |
| 8072 | Builder.MakeSuper(getToContext(), |
| 8073 | Spec->getAsRecordDecl(), |
| 8074 | ToRange.getBegin(), |
| 8075 | ToRange.getEnd()); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8076 | } |
| 8077 | } |
| 8078 | } |
| 8079 | |
| 8080 | return Builder.getWithLocInContext(getToContext()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 8081 | } |
| 8082 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8083 | Expected<TemplateName> ASTImporter::Import_New(TemplateName From) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8084 | TemplateName To = Import(From); |
| 8085 | if (To.isNull() && !From.isNull()) |
| 8086 | return llvm::make_error<ImportError>(); |
| 8087 | return To; |
| 8088 | } |
| 8089 | TemplateName ASTImporter::Import(TemplateName From) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8090 | switch (From.getKind()) { |
| 8091 | case TemplateName::Template: |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8092 | if (auto *ToTemplate = |
| 8093 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
| 8094 | return TemplateName(ToTemplate); |
| 8095 | |
| 8096 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8097 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8098 | case TemplateName::OverloadedTemplate: { |
| 8099 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 8100 | UnresolvedSet<2> ToTemplates; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8101 | for (auto *I : *FromStorage) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8102 | if (auto *To = cast_or_null<NamedDecl>(Import(I))) |
| 8103 | ToTemplates.addDecl(To); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8104 | else |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8105 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8106 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8107 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8108 | ToTemplates.end()); |
| 8109 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8110 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8111 | case TemplateName::QualifiedTemplate: { |
| 8112 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8113 | NestedNameSpecifier *Qualifier = Import(QTN->getQualifier()); |
| 8114 | if (!Qualifier) |
| 8115 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8116 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8117 | if (auto *ToTemplate = |
| 8118 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
| 8119 | return ToContext.getQualifiedTemplateName(Qualifier, |
| 8120 | QTN->hasTemplateKeyword(), |
| 8121 | ToTemplate); |
| 8122 | |
| 8123 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8124 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8125 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8126 | case TemplateName::DependentTemplate: { |
| 8127 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8128 | NestedNameSpecifier *Qualifier = Import(DTN->getQualifier()); |
| 8129 | if (!Qualifier) |
| 8130 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8131 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8132 | if (DTN->isIdentifier()) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8133 | return ToContext.getDependentTemplateName(Qualifier, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8134 | Import(DTN->getIdentifier())); |
| 8135 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8136 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8137 | return ToContext.getDependentTemplateName(Qualifier, DTN->getOperator()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8138 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8139 | |
| 8140 | case TemplateName::SubstTemplateTemplateParm: { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8141 | SubstTemplateTemplateParmStorage *subst |
| 8142 | = From.getAsSubstTemplateTemplateParm(); |
| 8143 | auto *param = |
| 8144 | cast_or_null<TemplateTemplateParmDecl>(Import(subst->getParameter())); |
| 8145 | if (!param) |
| 8146 | return {}; |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8147 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8148 | TemplateName replacement = Import(subst->getReplacement()); |
| 8149 | if (replacement.isNull()) |
| 8150 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8151 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8152 | return ToContext.getSubstTemplateTemplateParm(param, replacement); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8153 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8154 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8155 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 8156 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 8157 | = From.getAsSubstTemplateTemplateParmPack(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8158 | auto *Param = |
| 8159 | cast_or_null<TemplateTemplateParmDecl>( |
| 8160 | Import(SubstPack->getParameterPack())); |
| 8161 | if (!Param) |
| 8162 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8163 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8164 | ASTNodeImporter Importer(*this); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8165 | Expected<TemplateArgument> ArgPack |
| 8166 | = Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
| 8167 | if (!ArgPack) { |
| 8168 | llvm::consumeError(ArgPack.takeError()); |
| 8169 | return {}; |
| 8170 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8171 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8172 | return ToContext.getSubstTemplateTemplateParmPack(Param, *ArgPack); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8173 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8174 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8175 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8176 | llvm_unreachable("Invalid template name kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8177 | } |
| 8178 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8179 | Expected<SourceLocation> ASTImporter::Import_New(SourceLocation FromLoc) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8180 | SourceLocation ToLoc = Import(FromLoc); |
| 8181 | if (ToLoc.isInvalid() && !FromLoc.isInvalid()) |
| 8182 | return llvm::make_error<ImportError>(); |
| 8183 | return ToLoc; |
| 8184 | } |
| 8185 | SourceLocation ASTImporter::Import(SourceLocation FromLoc) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8186 | if (FromLoc.isInvalid()) |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8187 | return {}; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8188 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8189 | SourceManager &FromSM = FromContext.getSourceManager(); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8190 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8191 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8192 | FileID ToFileID = Import(Decomposed.first); |
| 8193 | if (ToFileID.isInvalid()) |
| 8194 | return {}; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8195 | SourceManager &ToSM = ToContext.getSourceManager(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8196 | return ToSM.getComposedLoc(ToFileID, Decomposed.second); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8197 | } |
| 8198 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8199 | Expected<SourceRange> ASTImporter::Import_New(SourceRange FromRange) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8200 | SourceRange ToRange = Import(FromRange); |
| 8201 | return ToRange; |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8202 | } |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8203 | SourceRange ASTImporter::Import(SourceRange FromRange) { |
| 8204 | return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd())); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8205 | } |
| 8206 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8207 | Expected<FileID> ASTImporter::Import_New(FileID FromID) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8208 | FileID ToID = Import(FromID); |
| 8209 | if (ToID.isInvalid() && FromID.isValid()) |
| 8210 | return llvm::make_error<ImportError>(); |
| 8211 | return ToID; |
| 8212 | } |
| 8213 | FileID ASTImporter::Import(FileID FromID) { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8214 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8215 | if (Pos != ImportedFileIDs.end()) |
| 8216 | return Pos->second; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8217 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8218 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 8219 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 8220 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8221 | |
| 8222 | // Map the FromID to the "to" source manager. |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8223 | FileID ToID; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8224 | if (FromSLoc.isExpansion()) { |
| 8225 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8226 | SourceLocation ToSpLoc = Import(FromEx.getSpellingLoc()); |
| 8227 | SourceLocation ToExLocS = Import(FromEx.getExpansionLocStart()); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8228 | unsigned TokenLen = FromSM.getFileIDSize(FromID); |
| 8229 | SourceLocation MLoc; |
| 8230 | if (FromEx.isMacroArgExpansion()) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8231 | MLoc = ToSM.createMacroArgExpansionLoc(ToSpLoc, ToExLocS, TokenLen); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8232 | } else { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8233 | SourceLocation ToExLocE = Import(FromEx.getExpansionLocEnd()); |
| 8234 | MLoc = ToSM.createExpansionLoc(ToSpLoc, ToExLocS, ToExLocE, TokenLen, |
| 8235 | FromEx.isExpansionTokenRange()); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8236 | } |
| 8237 | ToID = ToSM.getFileID(MLoc); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8238 | } else { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8239 | // Include location of this file. |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8240 | SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8241 | |
| 8242 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
| 8243 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
| 8244 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 8245 | // disk again |
| 8246 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 8247 | // than mmap the files several times. |
| 8248 | const FileEntry *Entry = |
| 8249 | ToFileManager.getFile(Cache->OrigEntry->getName()); |
| 8250 | if (!Entry) |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8251 | return {}; |
| 8252 | ToID = ToSM.createFileID(Entry, ToIncludeLoc, |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8253 | FromSLoc.getFile().getFileCharacteristic()); |
| 8254 | } else { |
| 8255 | // FIXME: We want to re-use the existing MemoryBuffer! |
| 8256 | const llvm::MemoryBuffer *FromBuf = |
| 8257 | Cache->getBuffer(FromContext.getDiagnostics(), FromSM); |
| 8258 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = |
| 8259 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
| 8260 | FromBuf->getBufferIdentifier()); |
| 8261 | ToID = ToSM.createFileID(std::move(ToBuf), |
| 8262 | FromSLoc.getFile().getFileCharacteristic()); |
| 8263 | } |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8264 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8265 | |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 8266 | ImportedFileIDs[FromID] = ToID; |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8267 | return ToID; |
| 8268 | } |
| 8269 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8270 | Expected<CXXCtorInitializer *> |
| 8271 | ASTImporter::Import_New(CXXCtorInitializer *From) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8272 | CXXCtorInitializer *To = Import(From); |
| 8273 | if (!To && From) |
| 8274 | return llvm::make_error<ImportError>(); |
| 8275 | return To; |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8276 | } |
Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 8277 | CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8278 | Expr *ToExpr = Import(From->getInit()); |
| 8279 | if (!ToExpr && From->getInit()) |
| 8280 | return nullptr; |
| 8281 | |
| 8282 | if (From->isBaseInitializer()) { |
| 8283 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 8284 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 8285 | return nullptr; |
| 8286 | |
| 8287 | return new (ToContext) CXXCtorInitializer( |
| 8288 | ToContext, ToTInfo, From->isBaseVirtual(), Import(From->getLParenLoc()), |
| 8289 | ToExpr, Import(From->getRParenLoc()), |
| 8290 | From->isPackExpansion() ? Import(From->getEllipsisLoc()) |
| 8291 | : SourceLocation()); |
| 8292 | } else if (From->isMemberInitializer()) { |
| 8293 | auto *ToField = cast_or_null<FieldDecl>(Import(From->getMember())); |
| 8294 | if (!ToField && From->getMember()) |
| 8295 | return nullptr; |
| 8296 | |
| 8297 | return new (ToContext) CXXCtorInitializer( |
| 8298 | ToContext, ToField, Import(From->getMemberLocation()), |
| 8299 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 8300 | } else if (From->isIndirectMemberInitializer()) { |
| 8301 | auto *ToIField = cast_or_null<IndirectFieldDecl>( |
| 8302 | Import(From->getIndirectMember())); |
| 8303 | if (!ToIField && From->getIndirectMember()) |
| 8304 | return nullptr; |
| 8305 | |
| 8306 | return new (ToContext) CXXCtorInitializer( |
| 8307 | ToContext, ToIField, Import(From->getMemberLocation()), |
| 8308 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 8309 | } else if (From->isDelegatingInitializer()) { |
| 8310 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 8311 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 8312 | return nullptr; |
| 8313 | |
| 8314 | return new (ToContext) |
| 8315 | CXXCtorInitializer(ToContext, ToTInfo, Import(From->getLParenLoc()), |
| 8316 | ToExpr, Import(From->getRParenLoc())); |
| 8317 | } else { |
| 8318 | return nullptr; |
| 8319 | } |
Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 8320 | } |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8321 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8322 | Expected<CXXBaseSpecifier *> |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8323 | ASTImporter::Import_New(const CXXBaseSpecifier *From) { |
| 8324 | CXXBaseSpecifier *To = Import(From); |
| 8325 | if (!To && From) |
| 8326 | return llvm::make_error<ImportError>(); |
| 8327 | return To; |
| 8328 | } |
| 8329 | CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8330 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 8331 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 8332 | return Pos->second; |
| 8333 | |
| 8334 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8335 | Import(BaseSpec->getSourceRange()), |
| 8336 | BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 8337 | BaseSpec->getAccessSpecifierAsWritten(), |
| 8338 | Import(BaseSpec->getTypeSourceInfo()), |
| 8339 | Import(BaseSpec->getEllipsisLoc())); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8340 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 8341 | return Imported; |
| 8342 | } |
| 8343 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8344 | Error ASTImporter::ImportDefinition_New(Decl *From) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8345 | Decl *To = Import(From); |
| 8346 | if (!To) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8347 | return llvm::make_error<ImportError>(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8348 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8349 | if (auto *FromDC = cast<DeclContext>(From)) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8350 | ASTNodeImporter Importer(*this); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8351 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8352 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 8353 | if (!ToRecord->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8354 | return Importer.ImportDefinition( |
| 8355 | cast<RecordDecl>(FromDC), ToRecord, |
| 8356 | ASTNodeImporter::IDK_Everything); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8357 | } |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 8358 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8359 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8360 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8361 | if (!ToEnum->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8362 | return Importer.ImportDefinition( |
| 8363 | cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8364 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8365 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8366 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8367 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 8368 | if (!ToIFace->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8369 | return Importer.ImportDefinition( |
| 8370 | cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
| 8371 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 8372 | } |
| 8373 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8374 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8375 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 8376 | if (!ToProto->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8377 | return Importer.ImportDefinition( |
| 8378 | cast<ObjCProtocolDecl>(FromDC), ToProto, |
| 8379 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 8380 | } |
| 8381 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8382 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8383 | return Importer.ImportDeclContext(FromDC, true); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8384 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8385 | |
| 8386 | return Error::success(); |
| 8387 | } |
| 8388 | |
| 8389 | void ASTImporter::ImportDefinition(Decl *From) { |
| 8390 | Error Err = ImportDefinition_New(From); |
| 8391 | llvm::consumeError(std::move(Err)); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8392 | } |
| 8393 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8394 | Expected<DeclarationName> ASTImporter::Import_New(DeclarationName FromName) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8395 | DeclarationName ToName = Import(FromName); |
| 8396 | if (!ToName && FromName) |
| 8397 | return llvm::make_error<ImportError>(); |
| 8398 | return ToName; |
| 8399 | } |
| 8400 | DeclarationName ASTImporter::Import(DeclarationName FromName) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8401 | if (!FromName) |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8402 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8403 | |
| 8404 | switch (FromName.getNameKind()) { |
| 8405 | case DeclarationName::Identifier: |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8406 | return Import(FromName.getAsIdentifierInfo()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8407 | |
| 8408 | case DeclarationName::ObjCZeroArgSelector: |
| 8409 | case DeclarationName::ObjCOneArgSelector: |
| 8410 | case DeclarationName::ObjCMultiArgSelector: |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8411 | return Import(FromName.getObjCSelector()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8412 | |
| 8413 | case DeclarationName::CXXConstructorName: { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8414 | QualType T = Import(FromName.getCXXNameType()); |
| 8415 | if (T.isNull()) |
| 8416 | return {}; |
| 8417 | |
| 8418 | return ToContext.DeclarationNames.getCXXConstructorName( |
| 8419 | ToContext.getCanonicalType(T)); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8420 | } |
| 8421 | |
| 8422 | case DeclarationName::CXXDestructorName: { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8423 | QualType T = Import(FromName.getCXXNameType()); |
| 8424 | if (T.isNull()) |
| 8425 | return {}; |
| 8426 | |
| 8427 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 8428 | ToContext.getCanonicalType(T)); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8429 | } |
| 8430 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8431 | case DeclarationName::CXXDeductionGuideName: { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8432 | auto *Template = cast_or_null<TemplateDecl>( |
| 8433 | Import(FromName.getCXXDeductionGuideTemplate())); |
| 8434 | if (!Template) |
| 8435 | return {}; |
| 8436 | return ToContext.DeclarationNames.getCXXDeductionGuideName(Template); |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8437 | } |
| 8438 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8439 | case DeclarationName::CXXConversionFunctionName: { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8440 | QualType T = Import(FromName.getCXXNameType()); |
| 8441 | if (T.isNull()) |
| 8442 | return {}; |
| 8443 | |
| 8444 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 8445 | ToContext.getCanonicalType(T)); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8446 | } |
| 8447 | |
| 8448 | case DeclarationName::CXXOperatorName: |
| 8449 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 8450 | FromName.getCXXOverloadedOperator()); |
| 8451 | |
| 8452 | case DeclarationName::CXXLiteralOperatorName: |
| 8453 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8454 | Import(FromName.getCXXLiteralIdentifier())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8455 | |
| 8456 | case DeclarationName::CXXUsingDirective: |
| 8457 | // FIXME: STATICS! |
| 8458 | return DeclarationName::getUsingDirectiveName(); |
| 8459 | } |
| 8460 | |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 8461 | llvm_unreachable("Invalid DeclarationName Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8462 | } |
| 8463 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8464 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8465 | if (!FromId) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8466 | return nullptr; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8467 | |
Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 8468 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 8469 | |
| 8470 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 8471 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 8472 | |
| 8473 | return ToId; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8474 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8475 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8476 | Expected<Selector> ASTImporter::Import_New(Selector FromSel) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8477 | Selector ToSel = Import(FromSel); |
| 8478 | if (ToSel.isNull() && !FromSel.isNull()) |
| 8479 | return llvm::make_error<ImportError>(); |
| 8480 | return ToSel; |
| 8481 | } |
| 8482 | Selector ASTImporter::Import(Selector FromSel) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8483 | if (FromSel.isNull()) |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8484 | return {}; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8485 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 8486 | SmallVector<IdentifierInfo *, 4> Idents; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8487 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 8488 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 8489 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 8490 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 8491 | } |
| 8492 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8493 | DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, |
| 8494 | DeclContext *DC, |
| 8495 | unsigned IDNS, |
| 8496 | NamedDecl **Decls, |
| 8497 | unsigned NumDecls) { |
| 8498 | return Name; |
| 8499 | } |
| 8500 | |
| 8501 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8502 | if (LastDiagFromFrom) |
| 8503 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8504 | FromContext.getDiagnostics()); |
| 8505 | LastDiagFromFrom = false; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8506 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8507 | } |
| 8508 | |
| 8509 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8510 | if (!LastDiagFromFrom) |
| 8511 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8512 | ToContext.getDiagnostics()); |
| 8513 | LastDiagFromFrom = true; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8514 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8515 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8516 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8517 | void ASTImporter::CompleteDecl (Decl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8518 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8519 | if (!ID->getDefinition()) |
| 8520 | ID->startDefinition(); |
| 8521 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8522 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8523 | if (!PD->getDefinition()) |
| 8524 | PD->startDefinition(); |
| 8525 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8526 | else if (auto *TD = dyn_cast<TagDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8527 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 8528 | TD->startDefinition(); |
| 8529 | TD->setCompleteDefinition(true); |
| 8530 | } |
| 8531 | } |
| 8532 | else { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8533 | assert(0 && "CompleteDecl called on a Decl that can't be completed"); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8534 | } |
| 8535 | } |
| 8536 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8537 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { |
| 8538 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); |
| 8539 | assert((Pos == ImportedDecls.end() || Pos->second == To) && |
| 8540 | "Try to import an already imported Decl"); |
| 8541 | if (Pos != ImportedDecls.end()) |
| 8542 | return Pos->second; |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8543 | ImportedDecls[From] = To; |
| 8544 | return To; |
Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 8545 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8546 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8547 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 8548 | bool Complain) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 8549 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8550 | = ImportedTypes.find(From.getTypePtr()); |
| 8551 | if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To)) |
| 8552 | return true; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 8553 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8554 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8555 | getStructuralEquivalenceKind(*this), false, |
| 8556 | Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 8557 | return Ctx.IsEquivalent(From, To); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8558 | } |