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 | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 442 | template <typename T> |
| 443 | bool hasSameVisibilityContext(T *Found, T *From); |
| 444 | |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 445 | bool IsStructuralMatch(Decl *From, Decl *To, bool Complain); |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 446 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, |
| 447 | bool Complain = true); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 448 | bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 449 | bool Complain = true); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 450 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 451 | bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 452 | bool IsStructuralMatch(FunctionTemplateDecl *From, |
| 453 | FunctionTemplateDecl *To); |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 454 | bool IsStructuralMatch(FunctionDecl *From, FunctionDecl *To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 455 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 456 | bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 457 | ExpectedDecl VisitDecl(Decl *D); |
| 458 | ExpectedDecl VisitImportDecl(ImportDecl *D); |
| 459 | ExpectedDecl VisitEmptyDecl(EmptyDecl *D); |
| 460 | ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D); |
| 461 | ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D); |
| 462 | ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D); |
| 463 | ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D); |
| 464 | ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
| 465 | ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); |
| 466 | ExpectedDecl VisitTypedefDecl(TypedefDecl *D); |
| 467 | ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D); |
| 468 | ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); |
| 469 | ExpectedDecl VisitLabelDecl(LabelDecl *D); |
| 470 | ExpectedDecl VisitEnumDecl(EnumDecl *D); |
| 471 | ExpectedDecl VisitRecordDecl(RecordDecl *D); |
| 472 | ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D); |
| 473 | ExpectedDecl VisitFunctionDecl(FunctionDecl *D); |
| 474 | ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D); |
| 475 | ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 476 | ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 477 | ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D); |
| 478 | ExpectedDecl VisitFieldDecl(FieldDecl *D); |
| 479 | ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D); |
| 480 | ExpectedDecl VisitFriendDecl(FriendDecl *D); |
| 481 | ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D); |
| 482 | ExpectedDecl VisitVarDecl(VarDecl *D); |
| 483 | ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D); |
| 484 | ExpectedDecl VisitParmVarDecl(ParmVarDecl *D); |
| 485 | ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D); |
| 486 | ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
| 487 | ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| 488 | ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| 489 | ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D); |
| 490 | ExpectedDecl VisitUsingDecl(UsingDecl *D); |
| 491 | ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D); |
| 492 | ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 493 | ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
| 494 | ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 495 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 496 | Expected<ObjCTypeParamList *> |
| 497 | ImportObjCTypeParamList(ObjCTypeParamList *list); |
| 498 | |
| 499 | ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
| 500 | ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| 501 | ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| 502 | ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| 503 | ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
| 504 | ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
| 505 | ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 506 | ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
| 507 | ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D); |
| 508 | ExpectedDecl VisitClassTemplateSpecializationDecl( |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 509 | ClassTemplateSpecializationDecl *D); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 510 | ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D); |
| 511 | ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); |
| 512 | ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 513 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 514 | // Importing statements |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 515 | ExpectedStmt VisitStmt(Stmt *S); |
| 516 | ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S); |
| 517 | ExpectedStmt VisitDeclStmt(DeclStmt *S); |
| 518 | ExpectedStmt VisitNullStmt(NullStmt *S); |
| 519 | ExpectedStmt VisitCompoundStmt(CompoundStmt *S); |
| 520 | ExpectedStmt VisitCaseStmt(CaseStmt *S); |
| 521 | ExpectedStmt VisitDefaultStmt(DefaultStmt *S); |
| 522 | ExpectedStmt VisitLabelStmt(LabelStmt *S); |
| 523 | ExpectedStmt VisitAttributedStmt(AttributedStmt *S); |
| 524 | ExpectedStmt VisitIfStmt(IfStmt *S); |
| 525 | ExpectedStmt VisitSwitchStmt(SwitchStmt *S); |
| 526 | ExpectedStmt VisitWhileStmt(WhileStmt *S); |
| 527 | ExpectedStmt VisitDoStmt(DoStmt *S); |
| 528 | ExpectedStmt VisitForStmt(ForStmt *S); |
| 529 | ExpectedStmt VisitGotoStmt(GotoStmt *S); |
| 530 | ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S); |
| 531 | ExpectedStmt VisitContinueStmt(ContinueStmt *S); |
| 532 | ExpectedStmt VisitBreakStmt(BreakStmt *S); |
| 533 | ExpectedStmt VisitReturnStmt(ReturnStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 534 | // FIXME: MSAsmStmt |
| 535 | // FIXME: SEHExceptStmt |
| 536 | // FIXME: SEHFinallyStmt |
| 537 | // FIXME: SEHTryStmt |
| 538 | // FIXME: SEHLeaveStmt |
| 539 | // FIXME: CapturedStmt |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 540 | ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S); |
| 541 | ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S); |
| 542 | ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 543 | // FIXME: MSDependentExistsStmt |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 544 | ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); |
| 545 | ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); |
| 546 | ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); |
| 547 | ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S); |
| 548 | ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); |
| 549 | ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); |
| 550 | ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 551 | |
| 552 | // Importing expressions |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 553 | ExpectedStmt VisitExpr(Expr *E); |
| 554 | ExpectedStmt VisitVAArgExpr(VAArgExpr *E); |
Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 555 | ExpectedStmt VisitChooseExpr(ChooseExpr *E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 556 | ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E); |
| 557 | ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E); |
| 558 | ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E); |
| 559 | ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E); |
| 560 | ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E); |
| 561 | ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); |
| 562 | ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E); |
| 563 | ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E); |
| 564 | ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E); |
| 565 | ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E); |
| 566 | ExpectedStmt VisitStringLiteral(StringLiteral *E); |
| 567 | ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
| 568 | ExpectedStmt VisitAtomicExpr(AtomicExpr *E); |
| 569 | ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E); |
Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 570 | ExpectedStmt VisitConstantExpr(ConstantExpr *E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 571 | ExpectedStmt VisitParenExpr(ParenExpr *E); |
| 572 | ExpectedStmt VisitParenListExpr(ParenListExpr *E); |
| 573 | ExpectedStmt VisitStmtExpr(StmtExpr *E); |
| 574 | ExpectedStmt VisitUnaryOperator(UnaryOperator *E); |
| 575 | ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); |
| 576 | ExpectedStmt VisitBinaryOperator(BinaryOperator *E); |
| 577 | ExpectedStmt VisitConditionalOperator(ConditionalOperator *E); |
| 578 | ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E); |
| 579 | ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E); |
| 580 | ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); |
| 581 | ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E); |
| 582 | ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
| 583 | ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E); |
| 584 | ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E); |
| 585 | ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 586 | ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE); |
| 587 | ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E); |
| 588 | ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E); |
| 589 | ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); |
| 590 | ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); |
| 591 | ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); |
| 592 | ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E); |
| 593 | ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); |
| 594 | ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E); |
| 595 | ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E); |
| 596 | ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E); |
| 597 | ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E); |
| 598 | ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E); |
| 599 | ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E); |
| 600 | ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); |
| 601 | ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E); |
| 602 | ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E); |
| 603 | ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); |
| 604 | ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E); |
| 605 | ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E); |
| 606 | ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E); |
| 607 | ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); |
| 608 | ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); |
| 609 | ExpectedStmt VisitMemberExpr(MemberExpr *E); |
| 610 | ExpectedStmt VisitCallExpr(CallExpr *E); |
| 611 | ExpectedStmt VisitLambdaExpr(LambdaExpr *LE); |
| 612 | ExpectedStmt VisitInitListExpr(InitListExpr *E); |
| 613 | ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E); |
| 614 | ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E); |
| 615 | ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); |
| 616 | ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); |
| 617 | ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); |
| 618 | ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E); |
| 619 | ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); |
| 620 | ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E); |
| 621 | ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 622 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 623 | template<typename IIter, typename OIter> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 624 | Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 625 | using ItemT = typename std::remove_reference<decltype(*Obegin)>::type; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 626 | for (; Ibegin != Iend; ++Ibegin, ++Obegin) { |
| 627 | Expected<ItemT> ToOrErr = import(*Ibegin); |
| 628 | if (!ToOrErr) |
| 629 | return ToOrErr.takeError(); |
| 630 | *Obegin = *ToOrErr; |
| 631 | } |
| 632 | return Error::success(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 633 | } |
| 634 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 635 | // Import every item from a container structure into an output container. |
| 636 | // If error occurs, stops at first error and returns the error. |
| 637 | // The output container should have space for all needed elements (it is not |
| 638 | // expanded, new items are put into from the beginning). |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 639 | template<typename InContainerTy, typename OutContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 640 | Error ImportContainerChecked( |
| 641 | const InContainerTy &InContainer, OutContainerTy &OutContainer) { |
| 642 | return ImportArrayChecked( |
| 643 | InContainer.begin(), InContainer.end(), OutContainer.begin()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | template<typename InContainerTy, typename OIter> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 647 | Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 648 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); |
| 649 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 650 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 651 | void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 652 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 653 | Expected<FunctionDecl *> FindFunctionTemplateSpecialization( |
| 654 | FunctionDecl *FromFD); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 655 | }; |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 656 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 657 | // FIXME: Temporary until every import returns Expected. |
| 658 | template <> |
| 659 | Expected<TemplateName> ASTNodeImporter::import(const TemplateName &From) { |
| 660 | TemplateName To = Importer.Import(From); |
| 661 | if (To.isNull() && !From.isNull()) |
| 662 | return make_error<ImportError>(); |
| 663 | return To; |
| 664 | } |
| 665 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 666 | template <typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 667 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 668 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 669 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 670 | auto ToLAngleLocOrErr = import(FromLAngleLoc); |
| 671 | if (!ToLAngleLocOrErr) |
| 672 | return ToLAngleLocOrErr.takeError(); |
| 673 | auto ToRAngleLocOrErr = import(FromRAngleLoc); |
| 674 | if (!ToRAngleLocOrErr) |
| 675 | return ToRAngleLocOrErr.takeError(); |
| 676 | |
| 677 | TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr); |
| 678 | if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo)) |
| 679 | return Err; |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 680 | Result = ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 681 | return Error::success(); |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 682 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 683 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 684 | template <> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 685 | Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 686 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { |
| 687 | return ImportTemplateArgumentListInfo( |
| 688 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); |
| 689 | } |
| 690 | |
| 691 | template <> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 692 | Error ASTNodeImporter::ImportTemplateArgumentListInfo< |
| 693 | ASTTemplateArgumentListInfo>( |
| 694 | const ASTTemplateArgumentListInfo &From, |
| 695 | TemplateArgumentListInfo &Result) { |
| 696 | return ImportTemplateArgumentListInfo( |
| 697 | From.LAngleLoc, From.RAngleLoc, From.arguments(), Result); |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 698 | } |
| 699 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 700 | Expected<ASTNodeImporter::FunctionTemplateAndArgsTy> |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 701 | ASTNodeImporter::ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 702 | FunctionDecl *FromFD) { |
| 703 | assert(FromFD->getTemplatedKind() == |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 704 | FunctionDecl::TK_FunctionTemplateSpecialization); |
| 705 | |
| 706 | FunctionTemplateAndArgsTy Result; |
| 707 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 708 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 709 | if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate())) |
| 710 | return std::move(Err); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 711 | |
| 712 | // Import template arguments. |
| 713 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 714 | if (Error Err = ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), |
| 715 | std::get<1>(Result))) |
| 716 | return std::move(Err); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 717 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 718 | return Result; |
| 719 | } |
| 720 | |
| 721 | template <> |
| 722 | Expected<TemplateParameterList *> |
| 723 | ASTNodeImporter::import(TemplateParameterList *From) { |
| 724 | SmallVector<NamedDecl *, 4> To(From->size()); |
| 725 | if (Error Err = ImportContainerChecked(*From, To)) |
| 726 | return std::move(Err); |
| 727 | |
| 728 | ExpectedExpr ToRequiresClause = import(From->getRequiresClause()); |
| 729 | if (!ToRequiresClause) |
| 730 | return ToRequiresClause.takeError(); |
| 731 | |
| 732 | auto ToTemplateLocOrErr = import(From->getTemplateLoc()); |
| 733 | if (!ToTemplateLocOrErr) |
| 734 | return ToTemplateLocOrErr.takeError(); |
| 735 | auto ToLAngleLocOrErr = import(From->getLAngleLoc()); |
| 736 | if (!ToLAngleLocOrErr) |
| 737 | return ToLAngleLocOrErr.takeError(); |
| 738 | auto ToRAngleLocOrErr = import(From->getRAngleLoc()); |
| 739 | if (!ToRAngleLocOrErr) |
| 740 | return ToRAngleLocOrErr.takeError(); |
| 741 | |
| 742 | return TemplateParameterList::Create( |
| 743 | Importer.getToContext(), |
| 744 | *ToTemplateLocOrErr, |
| 745 | *ToLAngleLocOrErr, |
| 746 | To, |
| 747 | *ToRAngleLocOrErr, |
| 748 | *ToRequiresClause); |
| 749 | } |
| 750 | |
| 751 | template <> |
| 752 | Expected<TemplateArgument> |
| 753 | ASTNodeImporter::import(const TemplateArgument &From) { |
| 754 | switch (From.getKind()) { |
| 755 | case TemplateArgument::Null: |
| 756 | return TemplateArgument(); |
| 757 | |
| 758 | case TemplateArgument::Type: { |
| 759 | ExpectedType ToTypeOrErr = import(From.getAsType()); |
| 760 | if (!ToTypeOrErr) |
| 761 | return ToTypeOrErr.takeError(); |
| 762 | return TemplateArgument(*ToTypeOrErr); |
| 763 | } |
| 764 | |
| 765 | case TemplateArgument::Integral: { |
| 766 | ExpectedType ToTypeOrErr = import(From.getIntegralType()); |
| 767 | if (!ToTypeOrErr) |
| 768 | return ToTypeOrErr.takeError(); |
| 769 | return TemplateArgument(From, *ToTypeOrErr); |
| 770 | } |
| 771 | |
| 772 | case TemplateArgument::Declaration: { |
| 773 | Expected<ValueDecl *> ToOrErr = import(From.getAsDecl()); |
| 774 | if (!ToOrErr) |
| 775 | return ToOrErr.takeError(); |
| 776 | ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl()); |
| 777 | if (!ToTypeOrErr) |
| 778 | return ToTypeOrErr.takeError(); |
| 779 | return TemplateArgument(*ToOrErr, *ToTypeOrErr); |
| 780 | } |
| 781 | |
| 782 | case TemplateArgument::NullPtr: { |
| 783 | ExpectedType ToTypeOrErr = import(From.getNullPtrType()); |
| 784 | if (!ToTypeOrErr) |
| 785 | return ToTypeOrErr.takeError(); |
| 786 | return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true); |
| 787 | } |
| 788 | |
| 789 | case TemplateArgument::Template: { |
| 790 | Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate()); |
| 791 | if (!ToTemplateOrErr) |
| 792 | return ToTemplateOrErr.takeError(); |
| 793 | |
| 794 | return TemplateArgument(*ToTemplateOrErr); |
| 795 | } |
| 796 | |
| 797 | case TemplateArgument::TemplateExpansion: { |
| 798 | Expected<TemplateName> ToTemplateOrErr = |
| 799 | import(From.getAsTemplateOrTemplatePattern()); |
| 800 | if (!ToTemplateOrErr) |
| 801 | return ToTemplateOrErr.takeError(); |
| 802 | |
| 803 | return TemplateArgument( |
| 804 | *ToTemplateOrErr, From.getNumTemplateExpansions()); |
| 805 | } |
| 806 | |
| 807 | case TemplateArgument::Expression: |
| 808 | if (ExpectedExpr ToExpr = import(From.getAsExpr())) |
| 809 | return TemplateArgument(*ToExpr); |
| 810 | else |
| 811 | return ToExpr.takeError(); |
| 812 | |
| 813 | case TemplateArgument::Pack: { |
| 814 | SmallVector<TemplateArgument, 2> ToPack; |
| 815 | ToPack.reserve(From.pack_size()); |
| 816 | if (Error Err = ImportTemplateArguments( |
| 817 | From.pack_begin(), From.pack_size(), ToPack)) |
| 818 | return std::move(Err); |
| 819 | |
| 820 | return TemplateArgument( |
| 821 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | llvm_unreachable("Invalid template argument kind"); |
| 826 | } |
| 827 | |
| 828 | template <> |
| 829 | Expected<TemplateArgumentLoc> |
| 830 | ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) { |
| 831 | Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument()); |
| 832 | if (!ArgOrErr) |
| 833 | return ArgOrErr.takeError(); |
| 834 | TemplateArgument Arg = *ArgOrErr; |
| 835 | |
| 836 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); |
| 837 | |
| 838 | TemplateArgumentLocInfo ToInfo; |
| 839 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 840 | ExpectedExpr E = import(FromInfo.getAsExpr()); |
| 841 | if (!E) |
| 842 | return E.takeError(); |
| 843 | ToInfo = TemplateArgumentLocInfo(*E); |
| 844 | } else if (Arg.getKind() == TemplateArgument::Type) { |
| 845 | if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo())) |
| 846 | ToInfo = TemplateArgumentLocInfo(*TSIOrErr); |
| 847 | else |
| 848 | return TSIOrErr.takeError(); |
| 849 | } else { |
| 850 | auto ToTemplateQualifierLocOrErr = |
| 851 | import(FromInfo.getTemplateQualifierLoc()); |
| 852 | if (!ToTemplateQualifierLocOrErr) |
| 853 | return ToTemplateQualifierLocOrErr.takeError(); |
| 854 | auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc()); |
| 855 | if (!ToTemplateNameLocOrErr) |
| 856 | return ToTemplateNameLocOrErr.takeError(); |
| 857 | auto ToTemplateEllipsisLocOrErr = |
| 858 | import(FromInfo.getTemplateEllipsisLoc()); |
| 859 | if (!ToTemplateEllipsisLocOrErr) |
| 860 | return ToTemplateEllipsisLocOrErr.takeError(); |
| 861 | |
| 862 | ToInfo = TemplateArgumentLocInfo( |
| 863 | *ToTemplateQualifierLocOrErr, |
| 864 | *ToTemplateNameLocOrErr, |
| 865 | *ToTemplateEllipsisLocOrErr); |
| 866 | } |
| 867 | |
| 868 | return TemplateArgumentLoc(Arg, ToInfo); |
| 869 | } |
| 870 | |
| 871 | template <> |
| 872 | Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) { |
| 873 | if (DG.isNull()) |
| 874 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); |
| 875 | size_t NumDecls = DG.end() - DG.begin(); |
| 876 | SmallVector<Decl *, 1> ToDecls; |
| 877 | ToDecls.reserve(NumDecls); |
| 878 | for (Decl *FromD : DG) { |
| 879 | if (auto ToDOrErr = import(FromD)) |
| 880 | ToDecls.push_back(*ToDOrErr); |
| 881 | else |
| 882 | return ToDOrErr.takeError(); |
| 883 | } |
| 884 | return DeclGroupRef::Create(Importer.getToContext(), |
| 885 | ToDecls.begin(), |
| 886 | NumDecls); |
| 887 | } |
| 888 | |
| 889 | template <> |
| 890 | Expected<ASTNodeImporter::Designator> |
| 891 | ASTNodeImporter::import(const Designator &D) { |
| 892 | if (D.isFieldDesignator()) { |
| 893 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); |
| 894 | |
| 895 | ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc()); |
| 896 | if (!ToDotLocOrErr) |
| 897 | return ToDotLocOrErr.takeError(); |
| 898 | |
| 899 | ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc()); |
| 900 | if (!ToFieldLocOrErr) |
| 901 | return ToFieldLocOrErr.takeError(); |
| 902 | |
| 903 | return Designator(ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr); |
| 904 | } |
| 905 | |
| 906 | ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc()); |
| 907 | if (!ToLBracketLocOrErr) |
| 908 | return ToLBracketLocOrErr.takeError(); |
| 909 | |
| 910 | ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc()); |
| 911 | if (!ToRBracketLocOrErr) |
| 912 | return ToRBracketLocOrErr.takeError(); |
| 913 | |
| 914 | if (D.isArrayDesignator()) |
| 915 | return Designator(D.getFirstExprIndex(), |
| 916 | *ToLBracketLocOrErr, *ToRBracketLocOrErr); |
| 917 | |
| 918 | ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc()); |
| 919 | if (!ToEllipsisLocOrErr) |
| 920 | return ToEllipsisLocOrErr.takeError(); |
| 921 | |
| 922 | assert(D.isArrayRangeDesignator()); |
| 923 | return Designator( |
| 924 | D.getFirstExprIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr, |
| 925 | *ToRBracketLocOrErr); |
| 926 | } |
| 927 | |
| 928 | template <> |
| 929 | Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) { |
| 930 | VarDecl *Var = nullptr; |
| 931 | if (From.capturesVariable()) { |
| 932 | if (auto VarOrErr = import(From.getCapturedVar())) |
| 933 | Var = *VarOrErr; |
| 934 | else |
| 935 | return VarOrErr.takeError(); |
| 936 | } |
| 937 | |
| 938 | auto LocationOrErr = import(From.getLocation()); |
| 939 | if (!LocationOrErr) |
| 940 | return LocationOrErr.takeError(); |
| 941 | |
| 942 | SourceLocation EllipsisLoc; |
| 943 | if (From.isPackExpansion()) |
| 944 | if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc())) |
| 945 | return std::move(Err); |
| 946 | |
| 947 | return LambdaCapture( |
| 948 | *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var, |
| 949 | EllipsisLoc); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 950 | } |
| 951 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 952 | } // namespace clang |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 953 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 954 | //---------------------------------------------------------------------------- |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 955 | // Import Types |
| 956 | //---------------------------------------------------------------------------- |
| 957 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 958 | using namespace clang; |
| 959 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 960 | ExpectedType ASTNodeImporter::VisitType(const Type *T) { |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 961 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) |
| 962 | << T->getTypeClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 963 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 964 | } |
| 965 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 966 | ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ |
| 967 | ExpectedType UnderlyingTypeOrErr = import(T->getValueType()); |
| 968 | if (!UnderlyingTypeOrErr) |
| 969 | return UnderlyingTypeOrErr.takeError(); |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 970 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 971 | return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr); |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 972 | } |
| 973 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 974 | ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 975 | switch (T->getKind()) { |
Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 976 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 977 | case BuiltinType::Id: \ |
| 978 | return Importer.getToContext().SingletonId; |
Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 979 | #include "clang/Basic/OpenCLImageTypes.def" |
Andrew Savonichev | 3fee351 | 2018-11-08 11:25:41 +0000 | [diff] [blame] | 980 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ |
| 981 | case BuiltinType::Id: \ |
| 982 | return Importer.getToContext().Id##Ty; |
| 983 | #include "clang/Basic/OpenCLExtensionTypes.def" |
John McCall | e314e27 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 984 | #define SHARED_SINGLETON_TYPE(Expansion) |
| 985 | #define BUILTIN_TYPE(Id, SingletonId) \ |
| 986 | case BuiltinType::Id: return Importer.getToContext().SingletonId; |
| 987 | #include "clang/AST/BuiltinTypes.def" |
| 988 | |
| 989 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" |
| 990 | // context supports C++. |
| 991 | |
| 992 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" |
| 993 | // context supports ObjC. |
| 994 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 995 | case BuiltinType::Char_U: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 996 | // The context we're importing from has an unsigned 'char'. If we're |
| 997 | // importing into a context with a signed 'char', translate to |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 998 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 999 | if (Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1000 | return Importer.getToContext().UnsignedCharTy; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1001 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1002 | return Importer.getToContext().CharTy; |
| 1003 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1004 | case BuiltinType::Char_S: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1005 | // The context we're importing from has an unsigned 'char'. If we're |
| 1006 | // importing into a context with a signed 'char', translate to |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1007 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1008 | if (!Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1009 | return Importer.getToContext().SignedCharTy; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1010 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1011 | return Importer.getToContext().CharTy; |
| 1012 | |
Chris Lattner | ad3467e | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 1013 | case BuiltinType::WChar_S: |
| 1014 | case BuiltinType::WChar_U: |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1015 | // FIXME: If not in C++, shall we translate to the C equivalent of |
| 1016 | // wchar_t? |
| 1017 | return Importer.getToContext().WCharTy; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1018 | } |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 1019 | |
| 1020 | llvm_unreachable("Invalid BuiltinType Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1021 | } |
| 1022 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1023 | ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { |
| 1024 | ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType()); |
| 1025 | if (!ToOriginalTypeOrErr) |
| 1026 | return ToOriginalTypeOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1027 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1028 | return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1029 | } |
| 1030 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1031 | ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) { |
| 1032 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1033 | if (!ToElementTypeOrErr) |
| 1034 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1035 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1036 | return Importer.getToContext().getComplexType(*ToElementTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1039 | ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) { |
| 1040 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1041 | if (!ToPointeeTypeOrErr) |
| 1042 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1043 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1044 | return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1047 | ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1048 | // FIXME: Check for blocks support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1049 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1050 | if (!ToPointeeTypeOrErr) |
| 1051 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1052 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1053 | return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1054 | } |
| 1055 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1056 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1057 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1058 | // FIXME: Check for C++ support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1059 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); |
| 1060 | if (!ToPointeeTypeOrErr) |
| 1061 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1062 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1063 | return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1064 | } |
| 1065 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1066 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1067 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1068 | // FIXME: Check for C++0x support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1069 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); |
| 1070 | if (!ToPointeeTypeOrErr) |
| 1071 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1072 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1073 | return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1074 | } |
| 1075 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1076 | ExpectedType |
| 1077 | ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1078 | // FIXME: Check for C++ support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1079 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1080 | if (!ToPointeeTypeOrErr) |
| 1081 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1082 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1083 | ExpectedType ClassTypeOrErr = import(QualType(T->getClass(), 0)); |
| 1084 | if (!ClassTypeOrErr) |
| 1085 | return ClassTypeOrErr.takeError(); |
| 1086 | |
| 1087 | return Importer.getToContext().getMemberPointerType( |
| 1088 | *ToPointeeTypeOrErr, (*ClassTypeOrErr).getTypePtr()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1089 | } |
| 1090 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1091 | ExpectedType |
| 1092 | ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { |
| 1093 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1094 | if (!ToElementTypeOrErr) |
| 1095 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1096 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1097 | return Importer.getToContext().getConstantArrayType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1098 | T->getSize(), |
| 1099 | T->getSizeModifier(), |
| 1100 | T->getIndexTypeCVRQualifiers()); |
| 1101 | } |
| 1102 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1103 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1104 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1105 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1106 | if (!ToElementTypeOrErr) |
| 1107 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1108 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1109 | return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1110 | T->getSizeModifier(), |
| 1111 | T->getIndexTypeCVRQualifiers()); |
| 1112 | } |
| 1113 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1114 | ExpectedType |
| 1115 | ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { |
| 1116 | QualType ToElementType; |
| 1117 | Expr *ToSizeExpr; |
| 1118 | SourceRange ToBracketsRange; |
| 1119 | if (auto Imp = importSeq( |
| 1120 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) |
| 1121 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; |
| 1122 | else |
| 1123 | return Imp.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1124 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1125 | return Importer.getToContext().getVariableArrayType( |
| 1126 | ToElementType, ToSizeExpr, T->getSizeModifier(), |
| 1127 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1130 | ExpectedType ASTNodeImporter::VisitDependentSizedArrayType( |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1131 | const DependentSizedArrayType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1132 | QualType ToElementType; |
| 1133 | Expr *ToSizeExpr; |
| 1134 | SourceRange ToBracketsRange; |
| 1135 | if (auto Imp = importSeq( |
| 1136 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) |
| 1137 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; |
| 1138 | else |
| 1139 | return Imp.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1140 | // SizeExpr may be null if size is not specified directly. |
| 1141 | // For example, 'int a[]'. |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1142 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1143 | return Importer.getToContext().getDependentSizedArrayType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1144 | ToElementType, ToSizeExpr, T->getSizeModifier(), |
| 1145 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1146 | } |
| 1147 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1148 | ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) { |
| 1149 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1150 | if (!ToElementTypeOrErr) |
| 1151 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1152 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1153 | return Importer.getToContext().getVectorType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1154 | T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 1155 | T->getVectorKind()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1158 | ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { |
| 1159 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1160 | if (!ToElementTypeOrErr) |
| 1161 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1162 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1163 | return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1164 | T->getNumElements()); |
| 1165 | } |
| 1166 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1167 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1168 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1169 | // FIXME: What happens if we're importing a function without a prototype |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1170 | // into C++? Should we make it variadic? |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1171 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); |
| 1172 | if (!ToReturnTypeOrErr) |
| 1173 | return ToReturnTypeOrErr.takeError(); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1174 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1175 | return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr, |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1176 | T->getExtInfo()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1177 | } |
| 1178 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1179 | ExpectedType |
| 1180 | ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { |
| 1181 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); |
| 1182 | if (!ToReturnTypeOrErr) |
| 1183 | return ToReturnTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1184 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1185 | // Import argument types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1186 | SmallVector<QualType, 4> ArgTypes; |
Aaron Ballman | 40bd0aa | 2014-03-17 15:23:01 +0000 | [diff] [blame] | 1187 | for (const auto &A : T->param_types()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1188 | ExpectedType TyOrErr = import(A); |
| 1189 | if (!TyOrErr) |
| 1190 | return TyOrErr.takeError(); |
| 1191 | ArgTypes.push_back(*TyOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1192 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1193 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1194 | // Import exception types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1195 | SmallVector<QualType, 4> ExceptionTypes; |
Aaron Ballman | b088fbe | 2014-03-17 15:38:09 +0000 | [diff] [blame] | 1196 | for (const auto &E : T->exceptions()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1197 | ExpectedType TyOrErr = import(E); |
| 1198 | if (!TyOrErr) |
| 1199 | return TyOrErr.takeError(); |
| 1200 | ExceptionTypes.push_back(*TyOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1201 | } |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 1202 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1203 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); |
| 1204 | FunctionProtoType::ExtProtoInfo ToEPI; |
| 1205 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1206 | auto Imp = importSeq( |
| 1207 | FromEPI.ExceptionSpec.NoexceptExpr, |
| 1208 | FromEPI.ExceptionSpec.SourceDecl, |
| 1209 | FromEPI.ExceptionSpec.SourceTemplate); |
| 1210 | if (!Imp) |
| 1211 | return Imp.takeError(); |
| 1212 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1213 | ToEPI.ExtInfo = FromEPI.ExtInfo; |
| 1214 | ToEPI.Variadic = FromEPI.Variadic; |
| 1215 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; |
| 1216 | ToEPI.TypeQuals = FromEPI.TypeQuals; |
| 1217 | ToEPI.RefQualifier = FromEPI.RefQualifier; |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 1218 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; |
| 1219 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1220 | std::tie( |
| 1221 | ToEPI.ExceptionSpec.NoexceptExpr, |
| 1222 | ToEPI.ExceptionSpec.SourceDecl, |
| 1223 | ToEPI.ExceptionSpec.SourceTemplate) = *Imp; |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1224 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1225 | return Importer.getToContext().getFunctionType( |
| 1226 | *ToReturnTypeOrErr, ArgTypes, ToEPI); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1227 | } |
| 1228 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1229 | ExpectedType ASTNodeImporter::VisitUnresolvedUsingType( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1230 | const UnresolvedUsingType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1231 | UnresolvedUsingTypenameDecl *ToD; |
| 1232 | Decl *ToPrevD; |
| 1233 | if (auto Imp = importSeq(T->getDecl(), T->getDecl()->getPreviousDecl())) |
| 1234 | std::tie(ToD, ToPrevD) = *Imp; |
| 1235 | else |
| 1236 | return Imp.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1237 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1238 | return Importer.getToContext().getTypeDeclType( |
| 1239 | ToD, cast_or_null<TypeDecl>(ToPrevD)); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1240 | } |
| 1241 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1242 | ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) { |
| 1243 | ExpectedType ToInnerTypeOrErr = import(T->getInnerType()); |
| 1244 | if (!ToInnerTypeOrErr) |
| 1245 | return ToInnerTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1246 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1247 | return Importer.getToContext().getParenType(*ToInnerTypeOrErr); |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 1248 | } |
| 1249 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1250 | ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { |
| 1251 | Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1252 | if (!ToDeclOrErr) |
| 1253 | return ToDeclOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1254 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1255 | return Importer.getToContext().getTypeDeclType(*ToDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1256 | } |
| 1257 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1258 | ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { |
| 1259 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); |
| 1260 | if (!ToExprOrErr) |
| 1261 | return ToExprOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1262 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1263 | return Importer.getToContext().getTypeOfExprType(*ToExprOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1264 | } |
| 1265 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1266 | ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { |
| 1267 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1268 | if (!ToUnderlyingTypeOrErr) |
| 1269 | return ToUnderlyingTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1270 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1271 | return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1272 | } |
| 1273 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1274 | ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1275 | // FIXME: Make sure that the "to" context supports C++0x! |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1276 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); |
| 1277 | if (!ToExprOrErr) |
| 1278 | return ToExprOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1279 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1280 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1281 | if (!ToUnderlyingTypeOrErr) |
| 1282 | return ToUnderlyingTypeOrErr.takeError(); |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 1283 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1284 | return Importer.getToContext().getDecltypeType( |
| 1285 | *ToExprOrErr, *ToUnderlyingTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1286 | } |
| 1287 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1288 | ExpectedType |
| 1289 | ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 1290 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); |
| 1291 | if (!ToBaseTypeOrErr) |
| 1292 | return ToBaseTypeOrErr.takeError(); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1293 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1294 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1295 | if (!ToUnderlyingTypeOrErr) |
| 1296 | return ToUnderlyingTypeOrErr.takeError(); |
| 1297 | |
| 1298 | return Importer.getToContext().getUnaryTransformType( |
| 1299 | *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind()); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1300 | } |
| 1301 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1302 | ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 1303 | // FIXME: Make sure that the "to" context supports C++11! |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1304 | ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType()); |
| 1305 | if (!ToDeducedTypeOrErr) |
| 1306 | return ToDeducedTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1307 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1308 | return Importer.getToContext().getAutoType(*ToDeducedTypeOrErr, |
| 1309 | T->getKeyword(), |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 1310 | /*IsDependent*/false); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1311 | } |
| 1312 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1313 | ExpectedType ASTNodeImporter::VisitInjectedClassNameType( |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1314 | const InjectedClassNameType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1315 | Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1316 | if (!ToDeclOrErr) |
| 1317 | return ToDeclOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1318 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1319 | ExpectedType ToInjTypeOrErr = import(T->getInjectedSpecializationType()); |
| 1320 | if (!ToInjTypeOrErr) |
| 1321 | return ToInjTypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1322 | |
| 1323 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading |
| 1324 | // See comments in InjectedClassNameType definition for details |
| 1325 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); |
| 1326 | enum { |
| 1327 | TypeAlignmentInBits = 4, |
| 1328 | TypeAlignment = 1 << TypeAlignmentInBits |
| 1329 | }; |
| 1330 | |
| 1331 | return QualType(new (Importer.getToContext(), TypeAlignment) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1332 | InjectedClassNameType(*ToDeclOrErr, *ToInjTypeOrErr), 0); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1333 | } |
| 1334 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1335 | ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) { |
| 1336 | Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1337 | if (!ToDeclOrErr) |
| 1338 | return ToDeclOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1339 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1340 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1341 | } |
| 1342 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1343 | ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) { |
| 1344 | Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1345 | if (!ToDeclOrErr) |
| 1346 | return ToDeclOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1347 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1348 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1349 | } |
| 1350 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1351 | ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { |
| 1352 | ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType()); |
| 1353 | if (!ToModifiedTypeOrErr) |
| 1354 | return ToModifiedTypeOrErr.takeError(); |
| 1355 | ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType()); |
| 1356 | if (!ToEquivalentTypeOrErr) |
| 1357 | return ToEquivalentTypeOrErr.takeError(); |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1358 | |
| 1359 | return Importer.getToContext().getAttributedType(T->getAttrKind(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1360 | *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr); |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1361 | } |
| 1362 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1363 | ExpectedType ASTNodeImporter::VisitTemplateTypeParmType( |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1364 | const TemplateTypeParmType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1365 | Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1366 | if (!ToDeclOrErr) |
| 1367 | return ToDeclOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1368 | |
| 1369 | return Importer.getToContext().getTemplateTypeParmType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1370 | T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1371 | } |
| 1372 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1373 | ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType( |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1374 | const SubstTemplateTypeParmType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1375 | ExpectedType ReplacedOrErr = import(QualType(T->getReplacedParameter(), 0)); |
| 1376 | if (!ReplacedOrErr) |
| 1377 | return ReplacedOrErr.takeError(); |
| 1378 | const TemplateTypeParmType *Replaced = |
| 1379 | cast<TemplateTypeParmType>((*ReplacedOrErr).getTypePtr()); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1380 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1381 | ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType()); |
| 1382 | if (!ToReplacementTypeOrErr) |
| 1383 | return ToReplacementTypeOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1384 | |
| 1385 | return Importer.getToContext().getSubstTemplateTypeParmType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1386 | Replaced, (*ToReplacementTypeOrErr).getCanonicalType()); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1387 | } |
| 1388 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1389 | ExpectedType ASTNodeImporter::VisitTemplateSpecializationType( |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1390 | const TemplateSpecializationType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1391 | auto ToTemplateOrErr = import(T->getTemplateName()); |
| 1392 | if (!ToTemplateOrErr) |
| 1393 | return ToTemplateOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1394 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1395 | SmallVector<TemplateArgument, 2> ToTemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1396 | if (Error Err = ImportTemplateArguments( |
| 1397 | T->getArgs(), T->getNumArgs(), ToTemplateArgs)) |
| 1398 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1399 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1400 | QualType ToCanonType; |
| 1401 | if (!QualType(T, 0).isCanonical()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1402 | QualType FromCanonType |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1403 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1404 | if (ExpectedType TyOrErr = import(FromCanonType)) |
| 1405 | ToCanonType = *TyOrErr; |
| 1406 | else |
| 1407 | return TyOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1408 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1409 | return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr, |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 1410 | ToTemplateArgs, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1411 | ToCanonType); |
| 1412 | } |
| 1413 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1414 | ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1415 | // Note: the qualifier in an ElaboratedType is optional. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1416 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1417 | if (!ToQualifierOrErr) |
| 1418 | return ToQualifierOrErr.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 | ExpectedType ToNamedTypeOrErr = import(T->getNamedType()); |
| 1421 | if (!ToNamedTypeOrErr) |
| 1422 | return ToNamedTypeOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1423 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1424 | Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl()); |
| 1425 | if (!ToOwnedTagDeclOrErr) |
| 1426 | return ToOwnedTagDeclOrErr.takeError(); |
Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 1427 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1428 | return Importer.getToContext().getElaboratedType(T->getKeyword(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1429 | *ToQualifierOrErr, |
| 1430 | *ToNamedTypeOrErr, |
| 1431 | *ToOwnedTagDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1432 | } |
| 1433 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1434 | ExpectedType |
| 1435 | ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { |
| 1436 | ExpectedType ToPatternOrErr = import(T->getPattern()); |
| 1437 | if (!ToPatternOrErr) |
| 1438 | return ToPatternOrErr.takeError(); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1439 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1440 | return Importer.getToContext().getPackExpansionType(*ToPatternOrErr, |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1441 | T->getNumExpansions()); |
| 1442 | } |
| 1443 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1444 | ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType( |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1445 | const DependentTemplateSpecializationType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1446 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1447 | if (!ToQualifierOrErr) |
| 1448 | return ToQualifierOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1449 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1450 | IdentifierInfo *ToName = Importer.Import(T->getIdentifier()); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1451 | |
| 1452 | SmallVector<TemplateArgument, 2> ToPack; |
| 1453 | ToPack.reserve(T->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1454 | if (Error Err = ImportTemplateArguments( |
| 1455 | T->getArgs(), T->getNumArgs(), ToPack)) |
| 1456 | return std::move(Err); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1457 | |
| 1458 | return Importer.getToContext().getDependentTemplateSpecializationType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1459 | T->getKeyword(), *ToQualifierOrErr, ToName, ToPack); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1460 | } |
| 1461 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1462 | ExpectedType |
| 1463 | ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) { |
| 1464 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1465 | if (!ToQualifierOrErr) |
| 1466 | return ToQualifierOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1467 | |
| 1468 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1469 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1470 | QualType Canon; |
| 1471 | if (T != T->getCanonicalTypeInternal().getTypePtr()) { |
| 1472 | if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal())) |
| 1473 | Canon = (*TyOrErr).getCanonicalType(); |
| 1474 | else |
| 1475 | return TyOrErr.takeError(); |
| 1476 | } |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1477 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1478 | return Importer.getToContext().getDependentNameType(T->getKeyword(), |
| 1479 | *ToQualifierOrErr, |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1480 | Name, Canon); |
| 1481 | } |
| 1482 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1483 | ExpectedType |
| 1484 | ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
| 1485 | Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1486 | if (!ToDeclOrErr) |
| 1487 | return ToDeclOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1488 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1489 | return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1490 | } |
| 1491 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1492 | ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { |
| 1493 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); |
| 1494 | if (!ToBaseTypeOrErr) |
| 1495 | return ToBaseTypeOrErr.takeError(); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1496 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1497 | SmallVector<QualType, 4> TypeArgs; |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 1498 | for (auto TypeArg : T->getTypeArgsAsWritten()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1499 | if (ExpectedType TyOrErr = import(TypeArg)) |
| 1500 | TypeArgs.push_back(*TyOrErr); |
| 1501 | else |
| 1502 | return TyOrErr.takeError(); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1505 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 1506 | for (auto *P : T->quals()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1507 | if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P)) |
| 1508 | Protocols.push_back(*ProtocolOrErr); |
| 1509 | else |
| 1510 | return ProtocolOrErr.takeError(); |
| 1511 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1512 | } |
| 1513 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1514 | return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs, |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 1515 | Protocols, |
| 1516 | T->isKindOfTypeAsWritten()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1517 | } |
| 1518 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1519 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1520 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1521 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1522 | if (!ToPointeeTypeOrErr) |
| 1523 | return ToPointeeTypeOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1524 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1525 | return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1526 | } |
| 1527 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 1528 | //---------------------------------------------------------------------------- |
| 1529 | // Import Declarations |
| 1530 | //---------------------------------------------------------------------------- |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1531 | Error ASTNodeImporter::ImportDeclParts( |
| 1532 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, |
| 1533 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) { |
Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1534 | // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop. |
| 1535 | // example: int struct_in_proto(struct data_t{int a;int b;} *d); |
| 1536 | DeclContext *OrigDC = D->getDeclContext(); |
| 1537 | FunctionDecl *FunDecl; |
| 1538 | if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) && |
| 1539 | FunDecl->hasBody()) { |
Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1540 | auto getLeafPointeeType = [](const Type *T) { |
| 1541 | while (T->isPointerType() || T->isArrayType()) { |
| 1542 | T = T->getPointeeOrArrayElementType(); |
| 1543 | } |
| 1544 | return T; |
| 1545 | }; |
| 1546 | for (const ParmVarDecl *P : FunDecl->parameters()) { |
| 1547 | const Type *LeafT = |
| 1548 | getLeafPointeeType(P->getType().getCanonicalType().getTypePtr()); |
| 1549 | auto *RT = dyn_cast<RecordType>(LeafT); |
| 1550 | if (RT && RT->getDecl() == D) { |
| 1551 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 1552 | << D->getDeclKindName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1553 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1554 | } |
Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1555 | } |
| 1556 | } |
| 1557 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1558 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1559 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 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 name of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1563 | if (Error Err = importInto(Name, D->getDeclName())) |
| 1564 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1565 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1566 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1567 | if (Error Err = importInto(Loc, D->getLocation())) |
| 1568 | return Err; |
| 1569 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1570 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); |
Gabor Marton | be77a98 | 2018-12-12 11:22:55 +0000 | [diff] [blame] | 1571 | if (ToD) |
| 1572 | if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD)) |
| 1573 | return Err; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1574 | |
| 1575 | return Error::success(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1576 | } |
| 1577 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1578 | Error ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1579 | if (!FromD) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1580 | return Error::success(); |
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 (!ToD) |
| 1583 | if (Error Err = importInto(ToD, FromD)) |
| 1584 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1585 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1586 | if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) { |
| 1587 | if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) { |
| 1588 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && |
| 1589 | !ToRecord->getDefinition()) { |
| 1590 | if (Error Err = ImportDefinition(FromRecord, ToRecord)) |
| 1591 | return Err; |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1592 | } |
| 1593 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1594 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1595 | } |
| 1596 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1597 | if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) { |
| 1598 | if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1599 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1600 | if (Error Err = ImportDefinition(FromEnum, ToEnum)) |
| 1601 | return Err; |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1602 | } |
| 1603 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1604 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1605 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1606 | |
| 1607 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1608 | } |
| 1609 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1610 | Error |
| 1611 | ASTNodeImporter::ImportDeclarationNameLoc( |
| 1612 | const DeclarationNameInfo &From, DeclarationNameInfo& To) { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1613 | // NOTE: To.Name and To.Loc are already imported. |
| 1614 | // We only have to import To.LocInfo. |
| 1615 | switch (To.getName().getNameKind()) { |
| 1616 | case DeclarationName::Identifier: |
| 1617 | case DeclarationName::ObjCZeroArgSelector: |
| 1618 | case DeclarationName::ObjCOneArgSelector: |
| 1619 | case DeclarationName::ObjCMultiArgSelector: |
| 1620 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1621 | case DeclarationName::CXXDeductionGuideName: |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1622 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1623 | |
| 1624 | case DeclarationName::CXXOperatorName: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1625 | if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange())) |
| 1626 | To.setCXXOperatorNameRange(*ToRangeOrErr); |
| 1627 | else |
| 1628 | return ToRangeOrErr.takeError(); |
| 1629 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1630 | } |
| 1631 | case DeclarationName::CXXLiteralOperatorName: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1632 | if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc())) |
| 1633 | To.setCXXLiteralOperatorNameLoc(*LocOrErr); |
| 1634 | else |
| 1635 | return LocOrErr.takeError(); |
| 1636 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1637 | } |
| 1638 | case DeclarationName::CXXConstructorName: |
| 1639 | case DeclarationName::CXXDestructorName: |
| 1640 | case DeclarationName::CXXConversionFunctionName: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1641 | if (auto ToTInfoOrErr = import(From.getNamedTypeInfo())) |
| 1642 | To.setNamedTypeInfo(*ToTInfoOrErr); |
| 1643 | else |
| 1644 | return ToTInfoOrErr.takeError(); |
| 1645 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1646 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1647 | } |
Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 1648 | llvm_unreachable("Unknown name kind."); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1649 | } |
| 1650 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1651 | Error |
| 1652 | ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1653 | if (Importer.isMinimalImport() && !ForceImport) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1654 | auto ToDCOrErr = Importer.ImportContext(FromDC); |
| 1655 | return ToDCOrErr.takeError(); |
| 1656 | } |
Davide Italiano | 93a64ef | 2018-10-30 20:46:29 +0000 | [diff] [blame] | 1657 | llvm::SmallVector<Decl *, 8> ImportedDecls; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1658 | for (auto *From : FromDC->decls()) { |
| 1659 | ExpectedDecl ImportedOrErr = import(From); |
Davide Italiano | 93a64ef | 2018-10-30 20:46:29 +0000 | [diff] [blame] | 1660 | if (!ImportedOrErr) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1661 | // Ignore the error, continue with next Decl. |
| 1662 | // FIXME: Handle this case somehow better. |
Davide Italiano | 93a64ef | 2018-10-30 20:46:29 +0000 | [diff] [blame] | 1663 | consumeError(ImportedOrErr.takeError()); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1664 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1665 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1666 | return Error::success(); |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 1667 | } |
| 1668 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1669 | Error ASTNodeImporter::ImportDeclContext( |
| 1670 | Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) { |
| 1671 | auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext()); |
| 1672 | if (!ToDCOrErr) |
| 1673 | return ToDCOrErr.takeError(); |
| 1674 | ToDC = *ToDCOrErr; |
| 1675 | |
| 1676 | if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) { |
| 1677 | auto ToLexicalDCOrErr = Importer.ImportContext( |
| 1678 | FromD->getLexicalDeclContext()); |
| 1679 | if (!ToLexicalDCOrErr) |
| 1680 | return ToLexicalDCOrErr.takeError(); |
| 1681 | ToLexicalDC = *ToLexicalDCOrErr; |
| 1682 | } else |
| 1683 | ToLexicalDC = ToDC; |
| 1684 | |
| 1685 | return Error::success(); |
| 1686 | } |
| 1687 | |
| 1688 | Error ASTNodeImporter::ImportImplicitMethods( |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1689 | const CXXRecordDecl *From, CXXRecordDecl *To) { |
| 1690 | assert(From->isCompleteDefinition() && To->getDefinition() == To && |
| 1691 | "Import implicit methods to or from non-definition"); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1692 | |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1693 | for (CXXMethodDecl *FromM : From->methods()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1694 | if (FromM->isImplicit()) { |
| 1695 | Expected<CXXMethodDecl *> ToMOrErr = import(FromM); |
| 1696 | if (!ToMOrErr) |
| 1697 | return ToMOrErr.takeError(); |
| 1698 | } |
| 1699 | |
| 1700 | return Error::success(); |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1701 | } |
| 1702 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1703 | static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, |
| 1704 | ASTImporter &Importer) { |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1705 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1706 | Decl *ToTypedef = Importer.Import(FromTypedef); |
| 1707 | if (!ToTypedef) |
| 1708 | return make_error<ImportError>(); |
| 1709 | To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(ToTypedef)); |
| 1710 | // FIXME: This should be the final code. |
| 1711 | //if (Expected<Decl *> ToTypedefOrErr = Importer.Import(FromTypedef)) |
| 1712 | // To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr)); |
| 1713 | //else |
| 1714 | // return ToTypedefOrErr.takeError(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1715 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1716 | return Error::success(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1717 | } |
| 1718 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1719 | Error ASTNodeImporter::ImportDefinition( |
| 1720 | RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1721 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1722 | if (Kind == IDK_Everything) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1723 | return ImportDeclContext(From, /*ForceImport=*/true); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1724 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1725 | return Error::success(); |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1726 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1727 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1728 | To->startDefinition(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1729 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1730 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 1731 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1732 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1733 | // Add base classes. |
Gabor Marton | 17d3967 | 2018-11-26 15:54:08 +0000 | [diff] [blame] | 1734 | auto *ToCXX = dyn_cast<CXXRecordDecl>(To); |
| 1735 | auto *FromCXX = dyn_cast<CXXRecordDecl>(From); |
| 1736 | if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) { |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1737 | |
| 1738 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); |
| 1739 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); |
| 1740 | ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1741 | ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1742 | ToData.Aggregate = FromData.Aggregate; |
| 1743 | ToData.PlainOldData = FromData.PlainOldData; |
| 1744 | ToData.Empty = FromData.Empty; |
| 1745 | ToData.Polymorphic = FromData.Polymorphic; |
| 1746 | ToData.Abstract = FromData.Abstract; |
| 1747 | ToData.IsStandardLayout = FromData.IsStandardLayout; |
Richard Smith | b6070db | 2018-04-05 18:55:37 +0000 | [diff] [blame] | 1748 | ToData.IsCXX11StandardLayout = FromData.IsCXX11StandardLayout; |
| 1749 | ToData.HasBasesWithFields = FromData.HasBasesWithFields; |
| 1750 | ToData.HasBasesWithNonStaticDataMembers = |
| 1751 | FromData.HasBasesWithNonStaticDataMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1752 | ToData.HasPrivateFields = FromData.HasPrivateFields; |
| 1753 | ToData.HasProtectedFields = FromData.HasProtectedFields; |
| 1754 | ToData.HasPublicFields = FromData.HasPublicFields; |
| 1755 | ToData.HasMutableFields = FromData.HasMutableFields; |
Richard Smith | ab44d5b | 2013-12-10 08:25:00 +0000 | [diff] [blame] | 1756 | ToData.HasVariantMembers = FromData.HasVariantMembers; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1757 | ToData.HasOnlyCMembers = FromData.HasOnlyCMembers; |
Richard Smith | e2648ba | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 1758 | ToData.HasInClassInitializer = FromData.HasInClassInitializer; |
Richard Smith | 593f993 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 1759 | ToData.HasUninitializedReferenceMember |
| 1760 | = FromData.HasUninitializedReferenceMember; |
Nico Weber | 6a6376b | 2016-02-19 01:52:46 +0000 | [diff] [blame] | 1761 | ToData.HasUninitializedFields = FromData.HasUninitializedFields; |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 1762 | ToData.HasInheritedConstructor = FromData.HasInheritedConstructor; |
| 1763 | ToData.HasInheritedAssignment = FromData.HasInheritedAssignment; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1764 | ToData.NeedOverloadResolutionForCopyConstructor |
| 1765 | = FromData.NeedOverloadResolutionForCopyConstructor; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1766 | ToData.NeedOverloadResolutionForMoveConstructor |
| 1767 | = FromData.NeedOverloadResolutionForMoveConstructor; |
| 1768 | ToData.NeedOverloadResolutionForMoveAssignment |
| 1769 | = FromData.NeedOverloadResolutionForMoveAssignment; |
| 1770 | ToData.NeedOverloadResolutionForDestructor |
| 1771 | = FromData.NeedOverloadResolutionForDestructor; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1772 | ToData.DefaultedCopyConstructorIsDeleted |
| 1773 | = FromData.DefaultedCopyConstructorIsDeleted; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1774 | ToData.DefaultedMoveConstructorIsDeleted |
| 1775 | = FromData.DefaultedMoveConstructorIsDeleted; |
| 1776 | ToData.DefaultedMoveAssignmentIsDeleted |
| 1777 | = FromData.DefaultedMoveAssignmentIsDeleted; |
| 1778 | ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1779 | ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers; |
| 1780 | ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1781 | ToData.HasConstexprNonCopyMoveConstructor |
| 1782 | = FromData.HasConstexprNonCopyMoveConstructor; |
Nico Weber | 72c57f4 | 2016-02-24 20:58:14 +0000 | [diff] [blame] | 1783 | ToData.HasDefaultedDefaultConstructor |
| 1784 | = FromData.HasDefaultedDefaultConstructor; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1785 | ToData.DefaultedDefaultConstructorIsConstexpr |
| 1786 | = FromData.DefaultedDefaultConstructorIsConstexpr; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1787 | ToData.HasConstexprDefaultConstructor |
| 1788 | = FromData.HasConstexprDefaultConstructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1789 | ToData.HasNonLiteralTypeFieldsOrBases |
| 1790 | = FromData.HasNonLiteralTypeFieldsOrBases; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1791 | // ComputedVisibleConversions not imported. |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1792 | ToData.UserProvidedDefaultConstructor |
| 1793 | = FromData.UserProvidedDefaultConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1794 | ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers; |
Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 1795 | ToData.ImplicitCopyConstructorCanHaveConstParamForVBase |
| 1796 | = FromData.ImplicitCopyConstructorCanHaveConstParamForVBase; |
| 1797 | ToData.ImplicitCopyConstructorCanHaveConstParamForNonVBase |
| 1798 | = FromData.ImplicitCopyConstructorCanHaveConstParamForNonVBase; |
Richard Smith | 1c33fe8 | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 1799 | ToData.ImplicitCopyAssignmentHasConstParam |
| 1800 | = FromData.ImplicitCopyAssignmentHasConstParam; |
| 1801 | ToData.HasDeclaredCopyConstructorWithConstParam |
| 1802 | = FromData.HasDeclaredCopyConstructorWithConstParam; |
| 1803 | ToData.HasDeclaredCopyAssignmentWithConstParam |
| 1804 | = FromData.HasDeclaredCopyAssignmentWithConstParam; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1805 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1806 | SmallVector<CXXBaseSpecifier *, 4> Bases; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1807 | for (const auto &Base1 : FromCXX->bases()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1808 | ExpectedType TyOrErr = import(Base1.getType()); |
| 1809 | if (!TyOrErr) |
| 1810 | return TyOrErr.takeError(); |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1811 | |
| 1812 | SourceLocation EllipsisLoc; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1813 | if (Base1.isPackExpansion()) { |
| 1814 | if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc())) |
| 1815 | EllipsisLoc = *LocOrErr; |
| 1816 | else |
| 1817 | return LocOrErr.takeError(); |
| 1818 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1819 | |
| 1820 | // Ensure that we have a definition for the base. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1821 | if (Error Err = |
| 1822 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl())) |
| 1823 | return Err; |
| 1824 | |
| 1825 | auto RangeOrErr = import(Base1.getSourceRange()); |
| 1826 | if (!RangeOrErr) |
| 1827 | return RangeOrErr.takeError(); |
| 1828 | |
| 1829 | auto TSIOrErr = import(Base1.getTypeSourceInfo()); |
| 1830 | if (!TSIOrErr) |
| 1831 | return TSIOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1832 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1833 | Bases.push_back( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1834 | new (Importer.getToContext()) CXXBaseSpecifier( |
| 1835 | *RangeOrErr, |
| 1836 | Base1.isVirtual(), |
| 1837 | Base1.isBaseOfClass(), |
| 1838 | Base1.getAccessSpecifierAsWritten(), |
| 1839 | *TSIOrErr, |
| 1840 | EllipsisLoc)); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1841 | } |
| 1842 | if (!Bases.empty()) |
Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1843 | ToCXX->setBases(Bases.data(), Bases.size()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1844 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1845 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1846 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1847 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 1848 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1849 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1850 | To->completeDefinition(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1851 | return Error::success(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1852 | } |
| 1853 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1854 | Error ASTNodeImporter::ImportInitializer(VarDecl *From, VarDecl *To) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1855 | if (To->getAnyInitializer()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1856 | return Error::success(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1857 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1858 | Expr *FromInit = From->getInit(); |
| 1859 | if (!FromInit) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1860 | return Error::success(); |
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 | ExpectedExpr ToInitOrErr = import(FromInit); |
| 1863 | if (!ToInitOrErr) |
| 1864 | return ToInitOrErr.takeError(); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1865 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1866 | To->setInit(*ToInitOrErr); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1867 | if (From->isInitKnownICE()) { |
| 1868 | EvaluatedStmt *Eval = To->ensureEvaluatedStmt(); |
| 1869 | Eval->CheckedICE = true; |
| 1870 | Eval->IsICE = From->isInitICE(); |
| 1871 | } |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1872 | |
| 1873 | // FIXME: Other bits to merge? |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1874 | return Error::success(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1875 | } |
| 1876 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1877 | Error ASTNodeImporter::ImportDefinition( |
| 1878 | EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1879 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1880 | if (Kind == IDK_Everything) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1881 | return ImportDeclContext(From, /*ForceImport=*/true); |
| 1882 | return Error::success(); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1883 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1884 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1885 | To->startDefinition(); |
| 1886 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1887 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 1888 | return Err; |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1889 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1890 | ExpectedType ToTypeOrErr = |
| 1891 | import(Importer.getFromContext().getTypeDeclType(From)); |
| 1892 | if (!ToTypeOrErr) |
| 1893 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1894 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1895 | ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType()); |
| 1896 | if (!ToPromotionTypeOrErr) |
| 1897 | return ToPromotionTypeOrErr.takeError(); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1898 | |
| 1899 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1900 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 1901 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1902 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1903 | // FIXME: we might need to merge the number of positive or negative bits |
| 1904 | // if the enumerator lists don't match. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1905 | To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr, |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1906 | From->getNumPositiveBits(), |
| 1907 | From->getNumNegativeBits()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1908 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1909 | } |
| 1910 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1911 | // FIXME: Remove this, use `import` instead. |
| 1912 | Expected<TemplateParameterList *> ASTNodeImporter::ImportTemplateParameterList( |
| 1913 | TemplateParameterList *Params) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1914 | SmallVector<NamedDecl *, 4> ToParams(Params->size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1915 | if (Error Err = ImportContainerChecked(*Params, ToParams)) |
| 1916 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1917 | |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1918 | Expr *ToRequiresClause; |
| 1919 | if (Expr *const R = Params->getRequiresClause()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1920 | if (Error Err = importInto(ToRequiresClause, R)) |
| 1921 | return std::move(Err); |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1922 | } else { |
| 1923 | ToRequiresClause = nullptr; |
| 1924 | } |
| 1925 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1926 | auto ToTemplateLocOrErr = import(Params->getTemplateLoc()); |
| 1927 | if (!ToTemplateLocOrErr) |
| 1928 | return ToTemplateLocOrErr.takeError(); |
| 1929 | auto ToLAngleLocOrErr = import(Params->getLAngleLoc()); |
| 1930 | if (!ToLAngleLocOrErr) |
| 1931 | return ToLAngleLocOrErr.takeError(); |
| 1932 | auto ToRAngleLocOrErr = import(Params->getRAngleLoc()); |
| 1933 | if (!ToRAngleLocOrErr) |
| 1934 | return ToRAngleLocOrErr.takeError(); |
| 1935 | |
| 1936 | return TemplateParameterList::Create( |
| 1937 | Importer.getToContext(), |
| 1938 | *ToTemplateLocOrErr, |
| 1939 | *ToLAngleLocOrErr, |
| 1940 | ToParams, |
| 1941 | *ToRAngleLocOrErr, |
| 1942 | ToRequiresClause); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1943 | } |
| 1944 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1945 | Error ASTNodeImporter::ImportTemplateArguments( |
| 1946 | const TemplateArgument *FromArgs, unsigned NumFromArgs, |
| 1947 | SmallVectorImpl<TemplateArgument> &ToArgs) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1948 | for (unsigned I = 0; I != NumFromArgs; ++I) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1949 | if (auto ToOrErr = import(FromArgs[I])) |
| 1950 | ToArgs.push_back(*ToOrErr); |
| 1951 | else |
| 1952 | return ToOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1953 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1954 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1955 | return Error::success(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1956 | } |
| 1957 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1958 | // FIXME: Do not forget to remove this and use only 'import'. |
| 1959 | Expected<TemplateArgument> |
| 1960 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { |
| 1961 | return import(From); |
| 1962 | } |
| 1963 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1964 | template <typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1965 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1966 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { |
| 1967 | for (const auto &FromLoc : Container) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1968 | if (auto ToLocOrErr = import(FromLoc)) |
| 1969 | ToTAInfo.addArgument(*ToLocOrErr); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1970 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1971 | return ToLocOrErr.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1972 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1973 | return Error::success(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1974 | } |
| 1975 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1976 | static StructuralEquivalenceKind |
| 1977 | getStructuralEquivalenceKind(const ASTImporter &Importer) { |
| 1978 | return Importer.isMinimalImport() ? StructuralEquivalenceKind::Minimal |
| 1979 | : StructuralEquivalenceKind::Default; |
| 1980 | } |
| 1981 | |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1982 | bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) { |
| 1983 | StructuralEquivalenceContext Ctx( |
| 1984 | Importer.getFromContext(), Importer.getToContext(), |
| 1985 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1986 | false, Complain); |
| 1987 | return Ctx.IsEquivalent(From, To); |
| 1988 | } |
| 1989 | |
| 1990 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1991 | RecordDecl *ToRecord, bool Complain) { |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1992 | // Eliminate a potential failure point where we attempt to re-import |
| 1993 | // something we're trying to import while completing ToRecord. |
| 1994 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); |
| 1995 | if (ToOrigin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1996 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1997 | if (ToOriginRecord) |
| 1998 | ToRecord = ToOriginRecord; |
| 1999 | } |
| 2000 | |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 2001 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2002 | ToRecord->getASTContext(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2003 | Importer.getNonEquivalentDecls(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2004 | getStructuralEquivalenceKind(Importer), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2005 | false, Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2006 | return Ctx.IsEquivalent(FromRecord, ToRecord); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2007 | } |
| 2008 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2009 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 2010 | bool Complain) { |
| 2011 | StructuralEquivalenceContext Ctx( |
| 2012 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2013 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2014 | false, Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2015 | return Ctx.IsEquivalent(FromVar, ToVar); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2018 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2019 | StructuralEquivalenceContext Ctx( |
| 2020 | Importer.getFromContext(), Importer.getToContext(), |
| 2021 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2022 | return Ctx.IsEquivalent(FromEnum, ToEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2023 | } |
| 2024 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2025 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, |
| 2026 | FunctionTemplateDecl *To) { |
| 2027 | StructuralEquivalenceContext Ctx( |
| 2028 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2029 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2030 | false, false); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2031 | return Ctx.IsEquivalent(From, To); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2032 | } |
| 2033 | |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2034 | bool ASTNodeImporter::IsStructuralMatch(FunctionDecl *From, FunctionDecl *To) { |
| 2035 | StructuralEquivalenceContext Ctx( |
| 2036 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2037 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2038 | false, false); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2039 | return Ctx.IsEquivalent(From, To); |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2040 | } |
| 2041 | |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2042 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2043 | EnumConstantDecl *ToEC) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2044 | const llvm::APSInt &FromVal = FromEC->getInitVal(); |
| 2045 | const llvm::APSInt &ToVal = ToEC->getInitVal(); |
| 2046 | |
| 2047 | return FromVal.isSigned() == ToVal.isSigned() && |
| 2048 | FromVal.getBitWidth() == ToVal.getBitWidth() && |
| 2049 | FromVal == ToVal; |
| 2050 | } |
| 2051 | |
| 2052 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2053 | ClassTemplateDecl *To) { |
| 2054 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2055 | Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2056 | Importer.getNonEquivalentDecls(), |
| 2057 | getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2058 | return Ctx.IsEquivalent(From, To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2059 | } |
| 2060 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2061 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, |
| 2062 | VarTemplateDecl *To) { |
| 2063 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2064 | Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2065 | Importer.getNonEquivalentDecls(), |
| 2066 | getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2067 | return Ctx.IsEquivalent(From, To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2068 | } |
| 2069 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2070 | ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 2071 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2072 | << D->getDeclKindName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2073 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2074 | } |
| 2075 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2076 | ExpectedDecl ASTNodeImporter::VisitImportDecl(ImportDecl *D) { |
| 2077 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 2078 | << D->getDeclKindName(); |
| 2079 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| 2080 | } |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2081 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2082 | ExpectedDecl ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { |
| 2083 | // Import the context of this declaration. |
| 2084 | DeclContext *DC, *LexicalDC; |
| 2085 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 2086 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2087 | |
| 2088 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2089 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2090 | if (!LocOrErr) |
| 2091 | return LocOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2092 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2093 | EmptyDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2094 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2095 | return ToD; |
| 2096 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2097 | ToD->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2098 | LexicalDC->addDeclInternal(ToD); |
| 2099 | return ToD; |
| 2100 | } |
| 2101 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2102 | ExpectedDecl ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2103 | TranslationUnitDecl *ToD = |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2104 | Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2105 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2106 | Importer.MapImported(D, ToD); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2107 | |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2108 | return ToD; |
| 2109 | } |
| 2110 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2111 | ExpectedDecl ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
| 2112 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2113 | if (!LocOrErr) |
| 2114 | return LocOrErr.takeError(); |
| 2115 | auto ColonLocOrErr = import(D->getColonLoc()); |
| 2116 | if (!ColonLocOrErr) |
| 2117 | return ColonLocOrErr.takeError(); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2118 | |
| 2119 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2120 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2121 | if (!DCOrErr) |
| 2122 | return DCOrErr.takeError(); |
| 2123 | DeclContext *DC = *DCOrErr; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2124 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2125 | AccessSpecDecl *ToD; |
| 2126 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2127 | DC, *LocOrErr, *ColonLocOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2128 | return ToD; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2129 | |
| 2130 | // Lexical DeclContext and Semantic DeclContext |
| 2131 | // is always the same for the accessSpec. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2132 | ToD->setLexicalDeclContext(DC); |
| 2133 | DC->addDeclInternal(ToD); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2134 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2135 | return ToD; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2136 | } |
| 2137 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2138 | ExpectedDecl ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 2139 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2140 | if (!DCOrErr) |
| 2141 | return DCOrErr.takeError(); |
| 2142 | DeclContext *DC = *DCOrErr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2143 | DeclContext *LexicalDC = DC; |
| 2144 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2145 | SourceLocation ToLocation, ToRParenLoc; |
| 2146 | Expr *ToAssertExpr; |
| 2147 | StringLiteral *ToMessage; |
| 2148 | if (auto Imp = importSeq( |
| 2149 | D->getLocation(), D->getAssertExpr(), D->getMessage(), D->getRParenLoc())) |
| 2150 | std::tie(ToLocation, ToAssertExpr, ToMessage, ToRParenLoc) = *Imp; |
| 2151 | else |
| 2152 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2153 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2154 | StaticAssertDecl *ToD; |
| 2155 | if (GetImportedOrCreateDecl( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2156 | ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage, |
| 2157 | ToRParenLoc, D->isFailed())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2158 | return ToD; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2159 | |
| 2160 | ToD->setLexicalDeclContext(LexicalDC); |
| 2161 | LexicalDC->addDeclInternal(ToD); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2162 | return ToD; |
| 2163 | } |
| 2164 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2165 | ExpectedDecl ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2166 | // Import the major distinguishing characteristics of this namespace. |
| 2167 | DeclContext *DC, *LexicalDC; |
| 2168 | DeclarationName Name; |
| 2169 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2170 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2171 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2172 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2173 | if (ToD) |
| 2174 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2175 | |
| 2176 | NamespaceDecl *MergeWithNamespace = nullptr; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2177 | if (!Name) { |
| 2178 | // This is an anonymous namespace. Adopt an existing anonymous |
| 2179 | // namespace if we can. |
| 2180 | // FIXME: Not testable. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2181 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2182 | MergeWithNamespace = TU->getAnonymousNamespace(); |
| 2183 | else |
| 2184 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); |
| 2185 | } else { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2186 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2187 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2188 | for (auto *FoundDecl : FoundDecls) { |
| 2189 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2190 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2191 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2192 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2193 | MergeWithNamespace = FoundNS; |
| 2194 | ConflictingDecls.clear(); |
| 2195 | break; |
| 2196 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2197 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2198 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2199 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2200 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2201 | if (!ConflictingDecls.empty()) { |
John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 2202 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2203 | ConflictingDecls.data(), |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2204 | ConflictingDecls.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2205 | if (!Name) |
| 2206 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2207 | } |
| 2208 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2209 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2210 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2211 | if (!BeginLocOrErr) |
| 2212 | return BeginLocOrErr.takeError(); |
| 2213 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2214 | // Create the "to" namespace, if needed. |
| 2215 | NamespaceDecl *ToNamespace = MergeWithNamespace; |
| 2216 | if (!ToNamespace) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2217 | if (GetImportedOrCreateDecl( |
| 2218 | ToNamespace, D, Importer.getToContext(), DC, D->isInline(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2219 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2220 | /*PrevDecl=*/nullptr)) |
| 2221 | return ToNamespace; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2222 | ToNamespace->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2223 | LexicalDC->addDeclInternal(ToNamespace); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2224 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2225 | // If this is an anonymous namespace, register it as the anonymous |
| 2226 | // namespace within its context. |
| 2227 | if (!Name) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2228 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2229 | TU->setAnonymousNamespace(ToNamespace); |
| 2230 | else |
| 2231 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); |
| 2232 | } |
| 2233 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2234 | Importer.MapImported(D, ToNamespace); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2235 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2236 | if (Error Err = ImportDeclContext(D)) |
| 2237 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2238 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2239 | return ToNamespace; |
| 2240 | } |
| 2241 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2242 | ExpectedDecl ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2243 | // Import the major distinguishing characteristics of this namespace. |
| 2244 | DeclContext *DC, *LexicalDC; |
| 2245 | DeclarationName Name; |
| 2246 | SourceLocation Loc; |
| 2247 | NamedDecl *LookupD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2248 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) |
| 2249 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2250 | if (LookupD) |
| 2251 | return LookupD; |
| 2252 | |
| 2253 | // NOTE: No conflict resolution is done for namespace aliases now. |
| 2254 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2255 | SourceLocation ToNamespaceLoc, ToAliasLoc, ToTargetNameLoc; |
| 2256 | NestedNameSpecifierLoc ToQualifierLoc; |
| 2257 | NamespaceDecl *ToNamespace; |
| 2258 | if (auto Imp = importSeq( |
| 2259 | D->getNamespaceLoc(), D->getAliasLoc(), D->getQualifierLoc(), |
| 2260 | D->getTargetNameLoc(), D->getNamespace())) |
| 2261 | std::tie( |
| 2262 | ToNamespaceLoc, ToAliasLoc, ToQualifierLoc, ToTargetNameLoc, |
| 2263 | ToNamespace) = *Imp; |
| 2264 | else |
| 2265 | return Imp.takeError(); |
| 2266 | IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier()); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2267 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2268 | NamespaceAliasDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2269 | if (GetImportedOrCreateDecl( |
| 2270 | ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc, |
| 2271 | ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2272 | return ToD; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2273 | |
| 2274 | ToD->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2275 | LexicalDC->addDeclInternal(ToD); |
| 2276 | |
| 2277 | return ToD; |
| 2278 | } |
| 2279 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2280 | ExpectedDecl |
| 2281 | ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2282 | // Import the major distinguishing characteristics of this typedef. |
| 2283 | DeclContext *DC, *LexicalDC; |
| 2284 | DeclarationName Name; |
| 2285 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2286 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2287 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2288 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2289 | if (ToD) |
| 2290 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2291 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2292 | // If this typedef is not in block scope, determine whether we've |
| 2293 | // seen a typedef with the same name (that we can merge with) or any |
| 2294 | // other entity by that name (which name lookup could conflict with). |
| 2295 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2296 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2297 | unsigned IDNS = Decl::IDNS_Ordinary; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2298 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2299 | for (auto *FoundDecl : FoundDecls) { |
| 2300 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2301 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2302 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2303 | QualType FromUT = D->getUnderlyingType(); |
| 2304 | QualType FoundUT = FoundTypedef->getUnderlyingType(); |
| 2305 | if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) { |
| 2306 | // If the "From" context has a complete underlying type but we |
| 2307 | // already have a complete underlying type then return with that. |
| 2308 | if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2309 | return Importer.MapImported(D, FoundTypedef); |
Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2310 | } |
| 2311 | // FIXME Handle redecl chain. |
| 2312 | break; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2313 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2314 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2315 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2316 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2317 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2318 | if (!ConflictingDecls.empty()) { |
| 2319 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2320 | ConflictingDecls.data(), |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2321 | ConflictingDecls.size()); |
| 2322 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2323 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2324 | } |
| 2325 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2326 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2327 | QualType ToUnderlyingType; |
| 2328 | TypeSourceInfo *ToTypeSourceInfo; |
| 2329 | SourceLocation ToBeginLoc; |
| 2330 | if (auto Imp = importSeq( |
| 2331 | D->getUnderlyingType(), D->getTypeSourceInfo(), D->getBeginLoc())) |
| 2332 | std::tie(ToUnderlyingType, ToTypeSourceInfo, ToBeginLoc) = *Imp; |
| 2333 | else |
| 2334 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2335 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2336 | // Create the new typedef node. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2337 | // FIXME: ToUnderlyingType is not used. |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2338 | TypedefNameDecl *ToTypedef; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2339 | if (IsAlias) { |
| 2340 | if (GetImportedOrCreateDecl<TypeAliasDecl>( |
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; |
| 2344 | } else if (GetImportedOrCreateDecl<TypedefDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2345 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2346 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2347 | return ToTypedef; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2348 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2349 | ToTypedef->setAccess(D->getAccess()); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2350 | ToTypedef->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2351 | |
| 2352 | // Templated declarations should not appear in DeclContext. |
| 2353 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; |
| 2354 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) |
| 2355 | LexicalDC->addDeclInternal(ToTypedef); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2356 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2357 | return ToTypedef; |
| 2358 | } |
| 2359 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2360 | ExpectedDecl ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2361 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); |
| 2362 | } |
| 2363 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2364 | ExpectedDecl ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2365 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); |
| 2366 | } |
| 2367 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2368 | ExpectedDecl |
| 2369 | ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2370 | // Import the major distinguishing characteristics of this typedef. |
| 2371 | DeclContext *DC, *LexicalDC; |
| 2372 | DeclarationName Name; |
| 2373 | SourceLocation Loc; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2374 | NamedDecl *FoundD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2375 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) |
| 2376 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2377 | if (FoundD) |
| 2378 | return FoundD; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2379 | |
| 2380 | // If this typedef is not in block scope, determine whether we've |
| 2381 | // seen a typedef with the same name (that we can merge with) or any |
| 2382 | // other entity by that name (which name lookup could conflict with). |
| 2383 | if (!DC->isFunctionOrMethod()) { |
| 2384 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 2385 | unsigned IDNS = Decl::IDNS_Ordinary; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2386 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2387 | for (auto *FoundDecl : FoundDecls) { |
| 2388 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2389 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2390 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2391 | return Importer.MapImported(D, FoundAlias); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2392 | ConflictingDecls.push_back(FoundDecl); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2393 | } |
| 2394 | |
| 2395 | if (!ConflictingDecls.empty()) { |
| 2396 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2397 | ConflictingDecls.data(), |
| 2398 | ConflictingDecls.size()); |
| 2399 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2400 | return make_error<ImportError>(ImportError::NameConflict); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2401 | } |
| 2402 | } |
| 2403 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2404 | TemplateParameterList *ToTemplateParameters; |
| 2405 | TypeAliasDecl *ToTemplatedDecl; |
| 2406 | if (auto Imp = importSeq(D->getTemplateParameters(), D->getTemplatedDecl())) |
| 2407 | std::tie(ToTemplateParameters, ToTemplatedDecl) = *Imp; |
| 2408 | else |
| 2409 | return Imp.takeError(); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2410 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2411 | TypeAliasTemplateDecl *ToAlias; |
| 2412 | if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2413 | Name, ToTemplateParameters, ToTemplatedDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2414 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2415 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2416 | ToTemplatedDecl->setDescribedAliasTemplate(ToAlias); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2417 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2418 | ToAlias->setAccess(D->getAccess()); |
| 2419 | ToAlias->setLexicalDeclContext(LexicalDC); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2420 | LexicalDC->addDeclInternal(ToAlias); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2421 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2422 | } |
| 2423 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2424 | ExpectedDecl ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2425 | // Import the major distinguishing characteristics of this label. |
| 2426 | DeclContext *DC, *LexicalDC; |
| 2427 | DeclarationName Name; |
| 2428 | SourceLocation Loc; |
| 2429 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2430 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2431 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2432 | if (ToD) |
| 2433 | return ToD; |
| 2434 | |
| 2435 | assert(LexicalDC->isFunctionOrMethod()); |
| 2436 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2437 | LabelDecl *ToLabel; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2438 | if (D->isGnuLocal()) { |
| 2439 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2440 | if (!BeginLocOrErr) |
| 2441 | return BeginLocOrErr.takeError(); |
| 2442 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2443 | Name.getAsIdentifierInfo(), *BeginLocOrErr)) |
| 2444 | return ToLabel; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2445 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2446 | } else { |
| 2447 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2448 | Name.getAsIdentifierInfo())) |
| 2449 | return ToLabel; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2450 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2451 | } |
| 2452 | |
| 2453 | Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt()); |
| 2454 | if (!ToStmtOrErr) |
| 2455 | return ToStmtOrErr.takeError(); |
| 2456 | |
| 2457 | ToLabel->setStmt(*ToStmtOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2458 | ToLabel->setLexicalDeclContext(LexicalDC); |
| 2459 | LexicalDC->addDeclInternal(ToLabel); |
| 2460 | return ToLabel; |
| 2461 | } |
| 2462 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2463 | ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2464 | // Import the major distinguishing characteristics of this enum. |
| 2465 | DeclContext *DC, *LexicalDC; |
| 2466 | DeclarationName Name; |
| 2467 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2468 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2469 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2470 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2471 | if (ToD) |
| 2472 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2473 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2474 | // Figure out what enum name we're looking for. |
| 2475 | unsigned IDNS = Decl::IDNS_Tag; |
| 2476 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2477 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2478 | if (Error Err = importInto( |
| 2479 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2480 | return std::move(Err); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2481 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2482 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2483 | IDNS |= Decl::IDNS_Ordinary; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2484 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2485 | // We may already have an enum of the same name; try to find and match it. |
| 2486 | if (!DC->isFunctionOrMethod() && SearchName) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2487 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2488 | auto FoundDecls = |
| 2489 | Importer.findDeclsInToCtx(DC, SearchName); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2490 | for (auto *FoundDecl : FoundDecls) { |
| 2491 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2492 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2493 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2494 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2495 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2496 | FoundDecl = Tag->getDecl(); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2497 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2498 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2499 | if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) { |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2500 | if (IsStructuralMatch(D, FoundEnum)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2501 | return Importer.MapImported(D, FoundEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2502 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2503 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2504 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2505 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2506 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2507 | if (!ConflictingDecls.empty()) { |
| 2508 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2509 | ConflictingDecls.data(), |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2510 | ConflictingDecls.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2511 | if (!Name) |
| 2512 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2513 | } |
| 2514 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2515 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2516 | SourceLocation ToBeginLoc; |
| 2517 | NestedNameSpecifierLoc ToQualifierLoc; |
| 2518 | QualType ToIntegerType; |
| 2519 | if (auto Imp = importSeq( |
| 2520 | D->getBeginLoc(), D->getQualifierLoc(), D->getIntegerType())) |
| 2521 | std::tie(ToBeginLoc, ToQualifierLoc, ToIntegerType) = *Imp; |
| 2522 | else |
| 2523 | return Imp.takeError(); |
| 2524 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2525 | // Create the enum declaration. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2526 | EnumDecl *D2; |
| 2527 | if (GetImportedOrCreateDecl( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2528 | D2, D, Importer.getToContext(), DC, ToBeginLoc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2529 | Loc, Name.getAsIdentifierInfo(), nullptr, D->isScoped(), |
| 2530 | D->isScopedUsingClassTag(), D->isFixed())) |
| 2531 | return D2; |
| 2532 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2533 | D2->setQualifierInfo(ToQualifierLoc); |
| 2534 | D2->setIntegerType(ToIntegerType); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2535 | D2->setAccess(D->getAccess()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2536 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2537 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2538 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2539 | // Import the definition |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2540 | if (D->isCompleteDefinition()) |
| 2541 | if (Error Err = ImportDefinition(D, D2)) |
| 2542 | return std::move(Err); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2543 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2544 | return D2; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2545 | } |
| 2546 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2547 | ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2548 | bool IsFriendTemplate = false; |
| 2549 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2550 | IsFriendTemplate = |
| 2551 | DCXX->getDescribedClassTemplate() && |
| 2552 | DCXX->getDescribedClassTemplate()->getFriendObjectKind() != |
| 2553 | Decl::FOK_None; |
| 2554 | } |
| 2555 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2556 | // Import the major distinguishing characteristics of this record. |
| 2557 | DeclContext *DC, *LexicalDC; |
| 2558 | DeclarationName Name; |
| 2559 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2560 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2561 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2562 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2563 | if (ToD) |
| 2564 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2565 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2566 | // Figure out what structure name we're looking for. |
| 2567 | unsigned IDNS = Decl::IDNS_Tag; |
| 2568 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2569 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2570 | if (Error Err = importInto( |
| 2571 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2572 | return std::move(Err); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2573 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2574 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2575 | IDNS |= Decl::IDNS_Ordinary | Decl::IDNS_TagFriend; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2576 | |
| 2577 | // 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] | 2578 | RecordDecl *PrevDecl = nullptr; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2579 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2580 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2581 | auto FoundDecls = |
| 2582 | Importer.findDeclsInToCtx(DC, SearchName); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2583 | if (!FoundDecls.empty()) { |
Gabor Marton | 41e3892 | 2019-03-05 11:23:24 +0000 | [diff] [blame] | 2584 | // We're going to have to compare D against potentially conflicting Decls, |
| 2585 | // so complete it. |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2586 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) |
| 2587 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 2588 | } |
| 2589 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2590 | for (auto *FoundDecl : FoundDecls) { |
| 2591 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2592 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2593 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2594 | Decl *Found = FoundDecl; |
| 2595 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 2596 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2597 | Found = Tag->getDecl(); |
| 2598 | } |
Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2599 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2600 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2601 | // Do not emit false positive diagnostic in case of unnamed |
| 2602 | // struct/union and in case of anonymous structs. Would be false |
| 2603 | // because there may be several anonymous/unnamed structs in a class. |
| 2604 | // E.g. these are both valid: |
| 2605 | // struct A { // unnamed structs |
| 2606 | // struct { struct A *next; } entry0; |
| 2607 | // struct { struct A *next; } entry1; |
| 2608 | // }; |
| 2609 | // struct X { struct { int a; }; struct { int b; }; }; // anon structs |
| 2610 | if (!SearchName) |
Gabor Marton | 0bebf95 | 2018-07-05 09:51:13 +0000 | [diff] [blame] | 2611 | if (!IsStructuralMatch(D, FoundRecord, false)) |
| 2612 | continue; |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2613 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2614 | if (IsStructuralMatch(D, FoundRecord)) { |
| 2615 | RecordDecl *FoundDef = FoundRecord->getDefinition(); |
| 2616 | if (D->isThisDeclarationADefinition() && FoundDef) { |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2617 | // FIXME: Structural equivalence check should check for same |
| 2618 | // user-defined methods. |
| 2619 | Importer.MapImported(D, FoundDef); |
| 2620 | if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2621 | auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef); |
| 2622 | assert(FoundCXX && "Record type mismatch"); |
| 2623 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2624 | if (!Importer.isMinimalImport()) |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2625 | // FoundDef may not have every implicit method that D has |
| 2626 | // because implicit methods are created only if they are used. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2627 | if (Error Err = ImportImplicitMethods(DCXX, FoundCXX)) |
| 2628 | return std::move(Err); |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2629 | } |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2630 | } |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2631 | PrevDecl = FoundRecord->getMostRecentDecl(); |
| 2632 | break; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2633 | } |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2634 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2635 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2636 | ConflictingDecls.push_back(FoundDecl); |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2637 | } // for |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2638 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2639 | if (!ConflictingDecls.empty() && SearchName) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2640 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2641 | ConflictingDecls.data(), |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2642 | ConflictingDecls.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2643 | if (!Name) |
| 2644 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2645 | } |
| 2646 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2647 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2648 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2649 | if (!BeginLocOrErr) |
| 2650 | return BeginLocOrErr.takeError(); |
| 2651 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2652 | // Create the record declaration. |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2653 | RecordDecl *D2 = nullptr; |
| 2654 | CXXRecordDecl *D2CXX = nullptr; |
| 2655 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2656 | if (DCXX->isLambda()) { |
| 2657 | auto TInfoOrErr = import(DCXX->getLambdaTypeInfo()); |
| 2658 | if (!TInfoOrErr) |
| 2659 | return TInfoOrErr.takeError(); |
| 2660 | if (GetImportedOrCreateSpecialDecl( |
| 2661 | D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(), |
| 2662 | DC, *TInfoOrErr, Loc, DCXX->isDependentLambda(), |
| 2663 | DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault())) |
| 2664 | return D2CXX; |
| 2665 | ExpectedDecl CDeclOrErr = import(DCXX->getLambdaContextDecl()); |
| 2666 | if (!CDeclOrErr) |
| 2667 | return CDeclOrErr.takeError(); |
| 2668 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), *CDeclOrErr); |
| 2669 | } else if (DCXX->isInjectedClassName()) { |
| 2670 | // We have to be careful to do a similar dance to the one in |
| 2671 | // Sema::ActOnStartCXXMemberDeclarations |
| 2672 | const bool DelayTypeCreation = true; |
| 2673 | if (GetImportedOrCreateDecl( |
| 2674 | D2CXX, D, Importer.getToContext(), D->getTagKind(), DC, |
| 2675 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), |
| 2676 | cast_or_null<CXXRecordDecl>(PrevDecl), DelayTypeCreation)) |
| 2677 | return D2CXX; |
| 2678 | Importer.getToContext().getTypeDeclType( |
| 2679 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); |
| 2680 | } else { |
| 2681 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), |
| 2682 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
| 2683 | Name.getAsIdentifierInfo(), |
| 2684 | cast_or_null<CXXRecordDecl>(PrevDecl))) |
| 2685 | return D2CXX; |
| 2686 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2687 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2688 | D2 = D2CXX; |
| 2689 | D2->setAccess(D->getAccess()); |
| 2690 | D2->setLexicalDeclContext(LexicalDC); |
| 2691 | if (!DCXX->getDescribedClassTemplate() || DCXX->isImplicit()) |
| 2692 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2693 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2694 | if (LexicalDC != DC && D->isInIdentifierNamespace(Decl::IDNS_TagFriend)) |
| 2695 | DC->makeDeclVisibleInContext(D2); |
| 2696 | |
| 2697 | if (ClassTemplateDecl *FromDescribed = |
| 2698 | DCXX->getDescribedClassTemplate()) { |
| 2699 | ClassTemplateDecl *ToDescribed; |
| 2700 | if (Error Err = importInto(ToDescribed, FromDescribed)) |
| 2701 | return std::move(Err); |
| 2702 | D2CXX->setDescribedClassTemplate(ToDescribed); |
| 2703 | if (!DCXX->isInjectedClassName() && !IsFriendTemplate) { |
| 2704 | // In a record describing a template the type should be an |
| 2705 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the |
| 2706 | // previously set type to the correct value here (ToDescribed is not |
| 2707 | // available at record create). |
| 2708 | // FIXME: The previous type is cleared but not removed from |
| 2709 | // ASTContext's internal storage. |
| 2710 | CXXRecordDecl *Injected = nullptr; |
| 2711 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { |
| 2712 | auto *Record = dyn_cast<CXXRecordDecl>(Found); |
| 2713 | if (Record && Record->isInjectedClassName()) { |
| 2714 | Injected = Record; |
| 2715 | break; |
Gabor Marton | 5915777e | 2018-06-26 13:44:24 +0000 | [diff] [blame] | 2716 | } |
| 2717 | } |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2718 | // Create an injected type for the whole redecl chain. |
| 2719 | SmallVector<Decl *, 2> Redecls = |
| 2720 | getCanonicalForwardRedeclChain(D2CXX); |
| 2721 | for (auto *R : Redecls) { |
| 2722 | auto *RI = cast<CXXRecordDecl>(R); |
| 2723 | RI->setTypeForDecl(nullptr); |
| 2724 | // Below we create a new injected type and assign that to the |
| 2725 | // canonical decl, subsequent declarations in the chain will reuse |
| 2726 | // that type. |
| 2727 | Importer.getToContext().getInjectedClassNameType( |
| 2728 | RI, ToDescribed->getInjectedClassNameSpecialization()); |
| 2729 | } |
| 2730 | // Set the new type for the previous injected decl too. |
| 2731 | if (Injected) { |
| 2732 | Injected->setTypeForDecl(nullptr); |
| 2733 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); |
| 2734 | } |
| 2735 | } |
| 2736 | } else if (MemberSpecializationInfo *MemberInfo = |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2737 | DCXX->getMemberSpecializationInfo()) { |
| 2738 | TemplateSpecializationKind SK = |
| 2739 | MemberInfo->getTemplateSpecializationKind(); |
| 2740 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2741 | |
| 2742 | if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst)) |
| 2743 | D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK); |
| 2744 | else |
| 2745 | return ToInstOrErr.takeError(); |
| 2746 | |
| 2747 | if (ExpectedSLoc POIOrErr = |
| 2748 | import(MemberInfo->getPointOfInstantiation())) |
| 2749 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( |
| 2750 | *POIOrErr); |
| 2751 | else |
| 2752 | return POIOrErr.takeError(); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2753 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2754 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2755 | } else { |
| 2756 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), |
| 2757 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
| 2758 | Name.getAsIdentifierInfo(), PrevDecl)) |
| 2759 | return D2; |
| 2760 | D2->setLexicalDeclContext(LexicalDC); |
| 2761 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2762 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2763 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2764 | if (auto QualifierLocOrErr = import(D->getQualifierLoc())) |
| 2765 | D2->setQualifierInfo(*QualifierLocOrErr); |
| 2766 | else |
| 2767 | return QualifierLocOrErr.takeError(); |
| 2768 | |
| 2769 | if (D->isAnonymousStructOrUnion()) |
| 2770 | D2->setAnonymousStructOrUnion(true); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2771 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2772 | if (D->isCompleteDefinition()) |
| 2773 | if (Error Err = ImportDefinition(D, D2, IDK_Default)) |
| 2774 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2775 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2776 | return D2; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2777 | } |
| 2778 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2779 | ExpectedDecl ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2780 | // Import the major distinguishing characteristics of this enumerator. |
| 2781 | DeclContext *DC, *LexicalDC; |
| 2782 | DeclarationName Name; |
| 2783 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2784 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2785 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2786 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2787 | if (ToD) |
| 2788 | return ToD; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2789 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2790 | // Determine whether there are any other declarations with the same name and |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2791 | // in the same context. |
| 2792 | if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2793 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2794 | unsigned IDNS = Decl::IDNS_Ordinary; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2795 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2796 | for (auto *FoundDecl : FoundDecls) { |
| 2797 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2798 | continue; |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2799 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2800 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2801 | if (IsStructuralMatch(D, FoundEnumConstant)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2802 | return Importer.MapImported(D, FoundEnumConstant); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2803 | } |
| 2804 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2805 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2806 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2807 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2808 | if (!ConflictingDecls.empty()) { |
| 2809 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2810 | ConflictingDecls.data(), |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2811 | ConflictingDecls.size()); |
| 2812 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2813 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2814 | } |
| 2815 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2816 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2817 | ExpectedType TypeOrErr = import(D->getType()); |
| 2818 | if (!TypeOrErr) |
| 2819 | return TypeOrErr.takeError(); |
| 2820 | |
| 2821 | ExpectedExpr InitOrErr = import(D->getInitExpr()); |
| 2822 | if (!InitOrErr) |
| 2823 | return InitOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2824 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2825 | EnumConstantDecl *ToEnumerator; |
| 2826 | if (GetImportedOrCreateDecl( |
| 2827 | ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2828 | Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2829 | return ToEnumerator; |
| 2830 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2831 | ToEnumerator->setAccess(D->getAccess()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2832 | ToEnumerator->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2833 | LexicalDC->addDeclInternal(ToEnumerator); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2834 | return ToEnumerator; |
| 2835 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2836 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2837 | Error ASTNodeImporter::ImportTemplateInformation( |
| 2838 | FunctionDecl *FromFD, FunctionDecl *ToFD) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2839 | switch (FromFD->getTemplatedKind()) { |
| 2840 | case FunctionDecl::TK_NonTemplate: |
| 2841 | case FunctionDecl::TK_FunctionTemplate: |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2842 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2843 | |
| 2844 | case FunctionDecl::TK_MemberSpecialization: { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2845 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2846 | |
| 2847 | if (Expected<FunctionDecl *> InstFDOrErr = |
| 2848 | import(FromFD->getInstantiatedFromMemberFunction())) |
| 2849 | ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK); |
| 2850 | else |
| 2851 | return InstFDOrErr.takeError(); |
| 2852 | |
| 2853 | if (ExpectedSLoc POIOrErr = import( |
| 2854 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation())) |
| 2855 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr); |
| 2856 | else |
| 2857 | return POIOrErr.takeError(); |
| 2858 | |
| 2859 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2860 | } |
| 2861 | |
| 2862 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2863 | auto FunctionAndArgsOrErr = |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2864 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2865 | if (!FunctionAndArgsOrErr) |
| 2866 | return FunctionAndArgsOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2867 | |
| 2868 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2869 | Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr)); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2870 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2871 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2872 | TemplateArgumentListInfo ToTAInfo; |
| 2873 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2874 | if (FromTAArgsAsWritten) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2875 | if (Error Err = ImportTemplateArgumentListInfo( |
| 2876 | *FromTAArgsAsWritten, ToTAInfo)) |
| 2877 | return Err; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2878 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2879 | ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation()); |
| 2880 | if (!POIOrErr) |
| 2881 | return POIOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2882 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2883 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2884 | ToFD->setFunctionTemplateSpecialization( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2885 | std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr, |
| 2886 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr); |
| 2887 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2888 | } |
| 2889 | |
| 2890 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 2891 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); |
| 2892 | UnresolvedSet<8> TemplDecls; |
| 2893 | unsigned NumTemplates = FromInfo->getNumTemplates(); |
| 2894 | for (unsigned I = 0; I < NumTemplates; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2895 | if (Expected<FunctionTemplateDecl *> ToFTDOrErr = |
| 2896 | import(FromInfo->getTemplate(I))) |
| 2897 | TemplDecls.addDecl(*ToFTDOrErr); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2898 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2899 | return ToFTDOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2900 | } |
| 2901 | |
| 2902 | // Import TemplateArgumentListInfo. |
| 2903 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2904 | if (Error Err = ImportTemplateArgumentListInfo( |
| 2905 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), |
| 2906 | llvm::makeArrayRef( |
| 2907 | FromInfo->getTemplateArgs(), FromInfo->getNumTemplateArgs()), |
| 2908 | ToTAInfo)) |
| 2909 | return Err; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2910 | |
| 2911 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), |
| 2912 | TemplDecls, ToTAInfo); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2913 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2914 | } |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2915 | } |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2916 | llvm_unreachable("All cases should be covered!"); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2917 | } |
| 2918 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2919 | Expected<FunctionDecl *> |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2920 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2921 | auto FunctionAndArgsOrErr = |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2922 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2923 | if (!FunctionAndArgsOrErr) |
| 2924 | return FunctionAndArgsOrErr.takeError(); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2925 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2926 | FunctionTemplateDecl *Template; |
| 2927 | TemplateArgsTy ToTemplArgs; |
| 2928 | std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2929 | void *InsertPos = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2930 | auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2931 | return FoundSpec; |
| 2932 | } |
| 2933 | |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 2934 | Error ASTNodeImporter::ImportFunctionDeclBody(FunctionDecl *FromFD, |
| 2935 | FunctionDecl *ToFD) { |
| 2936 | if (Stmt *FromBody = FromFD->getBody()) { |
| 2937 | if (ExpectedStmt ToBodyOrErr = import(FromBody)) |
| 2938 | ToFD->setBody(*ToBodyOrErr); |
| 2939 | else |
| 2940 | return ToBodyOrErr.takeError(); |
| 2941 | } |
| 2942 | return Error::success(); |
| 2943 | } |
| 2944 | |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 2945 | template <typename T> |
| 2946 | bool ASTNodeImporter::hasSameVisibilityContext(T *Found, T *From) { |
| 2947 | if (From->hasExternalFormalLinkage()) |
| 2948 | return Found->hasExternalFormalLinkage(); |
| 2949 | if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl()) |
| 2950 | return false; |
| 2951 | if (From->isInAnonymousNamespace()) |
| 2952 | return Found->isInAnonymousNamespace(); |
| 2953 | else |
| 2954 | return !Found->isInAnonymousNamespace() && |
| 2955 | !Found->hasExternalFormalLinkage(); |
| 2956 | } |
| 2957 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2958 | ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2959 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2960 | SmallVector<Decl *, 2> Redecls = getCanonicalForwardRedeclChain(D); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2961 | auto RedeclIt = Redecls.begin(); |
| 2962 | // Import the first part of the decl chain. I.e. import all previous |
| 2963 | // declarations starting from the canonical decl. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2964 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 2965 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 2966 | if (!ToRedeclOrErr) |
| 2967 | return ToRedeclOrErr.takeError(); |
| 2968 | } |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2969 | assert(*RedeclIt == D); |
| 2970 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2971 | // Import the major distinguishing characteristics of this function. |
| 2972 | DeclContext *DC, *LexicalDC; |
| 2973 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2974 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2975 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2976 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2977 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2978 | if (ToD) |
| 2979 | return ToD; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2980 | |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 2981 | FunctionDecl *FoundByLookup = nullptr; |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 2982 | FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2983 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2984 | // 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] | 2985 | // existing specialization in the "to" context. The lookup below will not |
| 2986 | // find any specialization, but would find the primary template; thus, we |
| 2987 | // have to skip normal lookup in case of specializations. |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2988 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? |
| 2989 | if (D->getTemplatedKind() == |
| 2990 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2991 | auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D); |
| 2992 | if (!FoundFunctionOrErr) |
| 2993 | return FoundFunctionOrErr.takeError(); |
| 2994 | if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) { |
| 2995 | if (D->doesThisDeclarationHaveABody() && FoundFunction->hasBody()) |
| 2996 | return Importer.MapImported(D, FoundFunction); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2997 | FoundByLookup = FoundFunction; |
| 2998 | } |
| 2999 | } |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3000 | // Try to find a function in our own ("to") context with the same name, same |
| 3001 | // type, and in the same context as the function we're importing. |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3002 | else if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3003 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3004 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3005 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3006 | for (auto *FoundDecl : FoundDecls) { |
| 3007 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3008 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3009 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3010 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3011 | if (!hasSameVisibilityContext(FoundFunction, D)) |
| 3012 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3013 | |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3014 | if (IsStructuralMatch(D, FoundFunction)) { |
| 3015 | const FunctionDecl *Definition = nullptr; |
| 3016 | if (D->doesThisDeclarationHaveABody() && |
| 3017 | FoundFunction->hasBody(Definition)) |
| 3018 | return Importer.MapImported(D, |
| 3019 | const_cast<FunctionDecl *>(Definition)); |
| 3020 | FoundByLookup = FoundFunction; |
| 3021 | break; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3022 | } |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3023 | // FIXME: Check for overloading more carefully, e.g., by boosting |
| 3024 | // Sema::IsOverload out to the AST library. |
| 3025 | |
| 3026 | // Function overloading is okay in C++. |
| 3027 | if (Importer.getToContext().getLangOpts().CPlusPlus) |
| 3028 | continue; |
| 3029 | |
| 3030 | // Complain about inconsistent function types. |
| 3031 | Importer.ToDiag(Loc, diag::err_odr_function_type_inconsistent) |
| 3032 | << Name << D->getType() << FoundFunction->getType(); |
| 3033 | Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here) |
| 3034 | << FoundFunction->getType(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3035 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3036 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3037 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3038 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3039 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3040 | if (!ConflictingDecls.empty()) { |
| 3041 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3042 | ConflictingDecls.data(), |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3043 | ConflictingDecls.size()); |
| 3044 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3045 | return make_error<ImportError>(ImportError::NameConflict); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3046 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3047 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3048 | |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3049 | // We do not allow more than one in-class declaration of a function. This is |
| 3050 | // because AST clients like VTableBuilder asserts on this. VTableBuilder |
| 3051 | // assumes there is only one in-class declaration. Building a redecl |
| 3052 | // chain would result in more than one in-class declaration for |
| 3053 | // overrides (even if they are part of the same redecl chain inside the |
| 3054 | // derived class.) |
| 3055 | if (FoundByLookup) { |
Mikael Holmen | c1c97aa | 2019-01-29 06:53:31 +0000 | [diff] [blame] | 3056 | if (isa<CXXMethodDecl>(FoundByLookup)) { |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3057 | if (D->getLexicalDeclContext() == D->getDeclContext()) { |
| 3058 | if (!D->doesThisDeclarationHaveABody()) |
| 3059 | return Importer.MapImported(D, FoundByLookup); |
| 3060 | else { |
| 3061 | // Let's continue and build up the redecl chain in this case. |
| 3062 | // FIXME Merge the functions into one decl. |
| 3063 | } |
| 3064 | } |
| 3065 | } |
| 3066 | } |
| 3067 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3068 | DeclarationNameInfo NameInfo(Name, Loc); |
| 3069 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3070 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 3071 | return std::move(Err); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3072 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3073 | QualType FromTy = D->getType(); |
| 3074 | bool usedDifferentExceptionSpec = false; |
| 3075 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3076 | if (const auto *FromFPT = D->getType()->getAs<FunctionProtoType>()) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3077 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); |
| 3078 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the |
| 3079 | // FunctionDecl that we are importing the FunctionProtoType for. |
| 3080 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| 3081 | // with a simplified function type and update it afterwards. |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 3082 | if (FromEPI.ExceptionSpec.SourceDecl || |
| 3083 | FromEPI.ExceptionSpec.SourceTemplate || |
| 3084 | FromEPI.ExceptionSpec.NoexceptExpr) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3085 | FunctionProtoType::ExtProtoInfo DefaultEPI; |
| 3086 | FromTy = Importer.getFromContext().getFunctionType( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3087 | FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI); |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3088 | usedDifferentExceptionSpec = true; |
| 3089 | } |
| 3090 | } |
| 3091 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3092 | QualType T; |
| 3093 | TypeSourceInfo *TInfo; |
| 3094 | SourceLocation ToInnerLocStart, ToEndLoc; |
| 3095 | NestedNameSpecifierLoc ToQualifierLoc; |
| 3096 | if (auto Imp = importSeq( |
| 3097 | FromTy, D->getTypeSourceInfo(), D->getInnerLocStart(), |
| 3098 | D->getQualifierLoc(), D->getEndLoc())) |
| 3099 | std::tie(T, TInfo, ToInnerLocStart, ToQualifierLoc, ToEndLoc) = *Imp; |
| 3100 | else |
| 3101 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3102 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3103 | // Import the function parameters. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3104 | SmallVector<ParmVarDecl *, 8> Parameters; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3105 | for (auto P : D->parameters()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3106 | if (Expected<ParmVarDecl *> ToPOrErr = import(P)) |
| 3107 | Parameters.push_back(*ToPOrErr); |
| 3108 | else |
| 3109 | return ToPOrErr.takeError(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3110 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3111 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3112 | // Create the imported function. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3113 | FunctionDecl *ToFunction = nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3114 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3115 | if (GetImportedOrCreateDecl<CXXConstructorDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3116 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3117 | ToInnerLocStart, NameInfo, T, TInfo, |
| 3118 | FromConstructor->isExplicit(), |
| 3119 | D->isInlineSpecified(), D->isImplicit(), D->isConstexpr())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3120 | return ToFunction; |
Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3121 | } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) { |
| 3122 | |
| 3123 | auto Imp = |
| 3124 | importSeq(const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()), |
| 3125 | FromDtor->getOperatorDeleteThisArg()); |
| 3126 | |
| 3127 | if (!Imp) |
| 3128 | return Imp.takeError(); |
| 3129 | |
| 3130 | FunctionDecl *ToOperatorDelete; |
| 3131 | Expr *ToThisArg; |
| 3132 | std::tie(ToOperatorDelete, ToThisArg) = *Imp; |
| 3133 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3134 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3135 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3136 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| 3137 | D->isImplicit())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3138 | return ToFunction; |
Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3139 | |
| 3140 | CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction); |
| 3141 | |
| 3142 | ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3143 | } else if (CXXConversionDecl *FromConversion = |
| 3144 | dyn_cast<CXXConversionDecl>(D)) { |
| 3145 | if (GetImportedOrCreateDecl<CXXConversionDecl>( |
| 3146 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3147 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3148 | FromConversion->isExplicit(), D->isConstexpr(), SourceLocation())) |
| 3149 | return ToFunction; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3150 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3151 | if (GetImportedOrCreateDecl<CXXMethodDecl>( |
| 3152 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3153 | ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3154 | Method->isInlineSpecified(), D->isConstexpr(), SourceLocation())) |
| 3155 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3156 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3157 | if (GetImportedOrCreateDecl(ToFunction, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3158 | ToInnerLocStart, NameInfo, T, TInfo, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3159 | D->getStorageClass(), D->isInlineSpecified(), |
| 3160 | D->hasWrittenPrototype(), D->isConstexpr())) |
| 3161 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3162 | } |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3163 | |
Gabor Marton | f5e4f0a | 2018-11-20 14:19:39 +0000 | [diff] [blame] | 3164 | // Connect the redecl chain. |
| 3165 | if (FoundByLookup) { |
| 3166 | auto *Recent = const_cast<FunctionDecl *>( |
| 3167 | FoundByLookup->getMostRecentDecl()); |
| 3168 | ToFunction->setPreviousDecl(Recent); |
| 3169 | } |
| 3170 | |
| 3171 | // Import Ctor initializers. |
| 3172 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
| 3173 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
| 3174 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers); |
| 3175 | // Import first, then allocate memory and copy if there was no error. |
| 3176 | if (Error Err = ImportContainerChecked( |
| 3177 | FromConstructor->inits(), CtorInitializers)) |
| 3178 | return std::move(Err); |
| 3179 | auto **Memory = |
| 3180 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 3181 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
| 3182 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); |
| 3183 | ToCtor->setCtorInitializers(Memory); |
| 3184 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 3185 | } |
| 3186 | } |
| 3187 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3188 | ToFunction->setQualifierInfo(ToQualifierLoc); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3189 | ToFunction->setAccess(D->getAccess()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3190 | ToFunction->setLexicalDeclContext(LexicalDC); |
John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 3191 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 3192 | ToFunction->setTrivial(D->isTrivial()); |
| 3193 | ToFunction->setPure(D->isPure()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3194 | ToFunction->setRangeEnd(ToEndLoc); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3195 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3196 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3197 | for (auto *Param : Parameters) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3198 | Param->setOwningFunction(ToFunction); |
| 3199 | ToFunction->addDeclInternal(Param); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3200 | } |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 3201 | ToFunction->setParams(Parameters); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3202 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3203 | // We need to complete creation of FunctionProtoTypeLoc manually with setting |
| 3204 | // params it refers to. |
| 3205 | if (TInfo) { |
| 3206 | if (auto ProtoLoc = |
| 3207 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { |
| 3208 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) |
| 3209 | ProtoLoc.setParam(I, Parameters[I]); |
| 3210 | } |
| 3211 | } |
| 3212 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3213 | if (usedDifferentExceptionSpec) { |
| 3214 | // Update FunctionProtoType::ExtProtoInfo. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3215 | if (ExpectedType TyOrErr = import(D->getType())) |
| 3216 | ToFunction->setType(*TyOrErr); |
| 3217 | else |
| 3218 | return TyOrErr.takeError(); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 3219 | } |
| 3220 | |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3221 | // Import the describing template function, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3222 | if (FromFT) { |
| 3223 | auto ToFTOrErr = import(FromFT); |
| 3224 | if (!ToFTOrErr) |
| 3225 | return ToFTOrErr.takeError(); |
| 3226 | } |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3227 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3228 | if (D->doesThisDeclarationHaveABody()) { |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3229 | Error Err = ImportFunctionDeclBody(D, ToFunction); |
| 3230 | |
| 3231 | if (Err) |
| 3232 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3233 | } |
| 3234 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3235 | // FIXME: Other bits to merge? |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3236 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3237 | // If it is a template, import all related things. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3238 | if (Error Err = ImportTemplateInformation(D, ToFunction)) |
| 3239 | return std::move(Err); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3240 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3241 | bool IsFriend = D->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend); |
| 3242 | |
| 3243 | // TODO Can we generalize this approach to other AST nodes as well? |
| 3244 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 3245 | DC->addDeclInternal(ToFunction); |
| 3246 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3247 | LexicalDC->addDeclInternal(ToFunction); |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3248 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3249 | // Friend declaration's lexical context is the befriending class, but the |
| 3250 | // semantic context is the enclosing scope of the befriending class. |
| 3251 | // We want the friend functions to be found in the semantic context by lookup. |
| 3252 | // FIXME should we handle this generically in VisitFriendDecl? |
| 3253 | // In Other cases when LexicalDC != DC we don't want it to be added, |
| 3254 | // e.g out-of-class definitions like void B::f() {} . |
| 3255 | if (LexicalDC != DC && IsFriend) { |
| 3256 | DC->makeDeclVisibleInContext(ToFunction); |
| 3257 | } |
| 3258 | |
Gabor Marton | 7a0841e | 2018-10-29 10:18:28 +0000 | [diff] [blame] | 3259 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) |
| 3260 | ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod); |
| 3261 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3262 | // Import the rest of the chain. I.e. import all subsequent declarations. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3263 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3264 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 3265 | if (!ToRedeclOrErr) |
| 3266 | return ToRedeclOrErr.takeError(); |
| 3267 | } |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3268 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3269 | return ToFunction; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3270 | } |
| 3271 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3272 | ExpectedDecl ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3273 | return VisitFunctionDecl(D); |
| 3274 | } |
| 3275 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3276 | ExpectedDecl ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3277 | return VisitCXXMethodDecl(D); |
| 3278 | } |
| 3279 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3280 | ExpectedDecl ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3281 | return VisitCXXMethodDecl(D); |
| 3282 | } |
| 3283 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3284 | ExpectedDecl ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3285 | return VisitCXXMethodDecl(D); |
| 3286 | } |
| 3287 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3288 | ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3289 | // Import the major distinguishing characteristics of a variable. |
| 3290 | DeclContext *DC, *LexicalDC; |
| 3291 | DeclarationName Name; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3292 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3293 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3294 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3295 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3296 | if (ToD) |
| 3297 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3298 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3299 | // Determine whether we've already imported this field. |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3300 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3301 | for (auto *FoundDecl : FoundDecls) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3302 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3303 | // For anonymous fields, match up by index. |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3304 | if (!Name && |
| 3305 | ASTImporter::getFieldIndex(D) != |
| 3306 | ASTImporter::getFieldIndex(FoundField)) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3307 | continue; |
| 3308 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3309 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3310 | FoundField->getType())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3311 | Importer.MapImported(D, FoundField); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3312 | // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the |
| 3313 | // initializer of a FieldDecl might not had been instantiated in the |
| 3314 | // "To" context. However, the "From" context might instantiated that, |
| 3315 | // thus we have to merge that. |
| 3316 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
| 3317 | // We don't have yet the initializer set. |
| 3318 | if (FoundField->hasInClassInitializer() && |
| 3319 | !FoundField->getInClassInitializer()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3320 | if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) |
| 3321 | FoundField->setInClassInitializer(*ToInitializerOrErr); |
| 3322 | else { |
| 3323 | // We can't return error here, |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3324 | // since we already mapped D as imported. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3325 | // FIXME: warning message? |
| 3326 | consumeError(ToInitializerOrErr.takeError()); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3327 | return FoundField; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3328 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3329 | } |
| 3330 | } |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3331 | return FoundField; |
| 3332 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3333 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3334 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3335 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 3336 | << Name << D->getType() << FoundField->getType(); |
| 3337 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3338 | << FoundField->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3339 | |
| 3340 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3341 | } |
| 3342 | } |
| 3343 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3344 | QualType ToType; |
| 3345 | TypeSourceInfo *ToTInfo; |
| 3346 | Expr *ToBitWidth; |
| 3347 | SourceLocation ToInnerLocStart; |
| 3348 | Expr *ToInitializer; |
| 3349 | if (auto Imp = importSeq( |
| 3350 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), |
| 3351 | D->getInnerLocStart(), D->getInClassInitializer())) |
| 3352 | std::tie( |
| 3353 | ToType, ToTInfo, ToBitWidth, ToInnerLocStart, ToInitializer) = *Imp; |
| 3354 | else |
| 3355 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3356 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3357 | FieldDecl *ToField; |
| 3358 | if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3359 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3360 | ToType, ToTInfo, ToBitWidth, D->isMutable(), |
| 3361 | D->getInClassInitStyle())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3362 | return ToField; |
| 3363 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3364 | ToField->setAccess(D->getAccess()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3365 | ToField->setLexicalDeclContext(LexicalDC); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3366 | if (ToInitializer) |
| 3367 | ToField->setInClassInitializer(ToInitializer); |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3368 | ToField->setImplicit(D->isImplicit()); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3369 | LexicalDC->addDeclInternal(ToField); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3370 | return ToField; |
| 3371 | } |
| 3372 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3373 | ExpectedDecl ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3374 | // Import the major distinguishing characteristics of a variable. |
| 3375 | DeclContext *DC, *LexicalDC; |
| 3376 | DeclarationName Name; |
| 3377 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3378 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3379 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3380 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3381 | if (ToD) |
| 3382 | return ToD; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3383 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3384 | // Determine whether we've already imported this field. |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3385 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3386 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3387 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3388 | // For anonymous indirect fields, match up by index. |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3389 | if (!Name && |
| 3390 | ASTImporter::getFieldIndex(D) != |
| 3391 | ASTImporter::getFieldIndex(FoundField)) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3392 | continue; |
| 3393 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3394 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3395 | FoundField->getType(), |
David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 3396 | !Name.isEmpty())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3397 | Importer.MapImported(D, FoundField); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3398 | return FoundField; |
| 3399 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3400 | |
| 3401 | // If there are more anonymous fields to check, continue. |
| 3402 | if (!Name && I < N-1) |
| 3403 | continue; |
| 3404 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3405 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3406 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 3407 | << Name << D->getType() << FoundField->getType(); |
| 3408 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3409 | << FoundField->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3410 | |
| 3411 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3412 | } |
| 3413 | } |
| 3414 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3415 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3416 | auto TypeOrErr = import(D->getType()); |
| 3417 | if (!TypeOrErr) |
| 3418 | return TypeOrErr.takeError(); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3419 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3420 | auto **NamedChain = |
| 3421 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3422 | |
| 3423 | unsigned i = 0; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3424 | for (auto *PI : D->chain()) |
| 3425 | if (Expected<NamedDecl *> ToD = import(PI)) |
| 3426 | NamedChain[i++] = *ToD; |
| 3427 | else |
| 3428 | return ToD.takeError(); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3429 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3430 | llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()}; |
| 3431 | IndirectFieldDecl *ToIndirectField; |
| 3432 | if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3433 | Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3434 | // FIXME here we leak `NamedChain` which is allocated before |
| 3435 | return ToIndirectField; |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 3436 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3437 | for (const auto *Attr : D->attrs()) |
| 3438 | ToIndirectField->addAttr(Importer.Import(Attr)); |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 3439 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3440 | ToIndirectField->setAccess(D->getAccess()); |
| 3441 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3442 | LexicalDC->addDeclInternal(ToIndirectField); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3443 | return ToIndirectField; |
| 3444 | } |
| 3445 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3446 | ExpectedDecl ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3447 | // Import the major distinguishing characteristics of a declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3448 | DeclContext *DC, *LexicalDC; |
| 3449 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 3450 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3451 | |
| 3452 | // Determine whether we've already imported this decl. |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3453 | // FriendDecl is not a NamedDecl so we cannot use lookup. |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3454 | auto *RD = cast<CXXRecordDecl>(DC); |
| 3455 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3456 | |
| 3457 | while (ImportedFriend) { |
| 3458 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 3459 | if (IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(), |
| 3460 | /*Complain=*/false)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3461 | return Importer.MapImported(D, ImportedFriend); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3462 | |
| 3463 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| 3464 | if (Importer.IsStructurallyEquivalent( |
| 3465 | D->getFriendType()->getType(), |
| 3466 | ImportedFriend->getFriendType()->getType(), true)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3467 | return Importer.MapImported(D, ImportedFriend); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3468 | } |
| 3469 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 3470 | } |
| 3471 | |
| 3472 | // Not found. Create it. |
| 3473 | FriendDecl::FriendUnion ToFU; |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3474 | if (NamedDecl *FriendD = D->getFriendDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3475 | NamedDecl *ToFriendD; |
| 3476 | if (Error Err = importInto(ToFriendD, FriendD)) |
| 3477 | return std::move(Err); |
| 3478 | |
| 3479 | if (FriendD->getFriendObjectKind() != Decl::FOK_None && |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3480 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) |
| 3481 | ToFriendD->setObjectOfFriendDecl(false); |
| 3482 | |
| 3483 | ToFU = ToFriendD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3484 | } else { // The friend is a type, not a decl. |
| 3485 | if (auto TSIOrErr = import(D->getFriendType())) |
| 3486 | ToFU = *TSIOrErr; |
| 3487 | else |
| 3488 | return TSIOrErr.takeError(); |
| 3489 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3490 | |
| 3491 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3492 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3493 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3494 | if (auto ListOrErr = ImportTemplateParameterList(FromTPLists[I])) |
| 3495 | ToTPLists[I] = *ListOrErr; |
| 3496 | else |
| 3497 | return ListOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3498 | } |
| 3499 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3500 | auto LocationOrErr = import(D->getLocation()); |
| 3501 | if (!LocationOrErr) |
| 3502 | return LocationOrErr.takeError(); |
| 3503 | auto FriendLocOrErr = import(D->getFriendLoc()); |
| 3504 | if (!FriendLocOrErr) |
| 3505 | return FriendLocOrErr.takeError(); |
| 3506 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3507 | FriendDecl *FrD; |
| 3508 | if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3509 | *LocationOrErr, ToFU, |
| 3510 | *FriendLocOrErr, ToTPLists)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3511 | return FrD; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3512 | |
| 3513 | FrD->setAccess(D->getAccess()); |
| 3514 | FrD->setLexicalDeclContext(LexicalDC); |
| 3515 | LexicalDC->addDeclInternal(FrD); |
| 3516 | return FrD; |
| 3517 | } |
| 3518 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3519 | ExpectedDecl ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3520 | // Import the major distinguishing characteristics of an ivar. |
| 3521 | DeclContext *DC, *LexicalDC; |
| 3522 | DeclarationName Name; |
| 3523 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3524 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3525 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3526 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3527 | if (ToD) |
| 3528 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3529 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3530 | // Determine whether we've already imported this ivar |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3531 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3532 | for (auto *FoundDecl : FoundDecls) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3533 | if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3534 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3535 | FoundIvar->getType())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3536 | Importer.MapImported(D, FoundIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3537 | return FoundIvar; |
| 3538 | } |
| 3539 | |
| 3540 | Importer.ToDiag(Loc, diag::err_odr_ivar_type_inconsistent) |
| 3541 | << Name << D->getType() << FoundIvar->getType(); |
| 3542 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) |
| 3543 | << FoundIvar->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3544 | |
| 3545 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3546 | } |
| 3547 | } |
| 3548 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3549 | QualType ToType; |
| 3550 | TypeSourceInfo *ToTypeSourceInfo; |
| 3551 | Expr *ToBitWidth; |
| 3552 | SourceLocation ToInnerLocStart; |
| 3553 | if (auto Imp = importSeq( |
| 3554 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), D->getInnerLocStart())) |
| 3555 | std::tie(ToType, ToTypeSourceInfo, ToBitWidth, ToInnerLocStart) = *Imp; |
| 3556 | else |
| 3557 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3558 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3559 | ObjCIvarDecl *ToIvar; |
| 3560 | if (GetImportedOrCreateDecl( |
| 3561 | ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3562 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3563 | ToType, ToTypeSourceInfo, |
| 3564 | D->getAccessControl(),ToBitWidth, D->getSynthesize())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3565 | return ToIvar; |
| 3566 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3567 | ToIvar->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3568 | LexicalDC->addDeclInternal(ToIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3569 | return ToIvar; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3570 | } |
| 3571 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3572 | ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) { |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3573 | |
| 3574 | SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D); |
| 3575 | auto RedeclIt = Redecls.begin(); |
| 3576 | // Import the first part of the decl chain. I.e. import all previous |
| 3577 | // declarations starting from the canonical decl. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3578 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 3579 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3580 | if (!RedeclOrErr) |
| 3581 | return RedeclOrErr.takeError(); |
| 3582 | } |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3583 | assert(*RedeclIt == D); |
| 3584 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3585 | // Import the major distinguishing characteristics of a variable. |
| 3586 | DeclContext *DC, *LexicalDC; |
| 3587 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3588 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3589 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3590 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3591 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3592 | if (ToD) |
| 3593 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3594 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3595 | // Try to find a variable in our own ("to") context with the same name and |
| 3596 | // in the same context as the variable we're importing. |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3597 | VarDecl *FoundByLookup = nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3598 | if (D->isFileVarDecl()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3599 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3600 | unsigned IDNS = Decl::IDNS_Ordinary; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3601 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3602 | for (auto *FoundDecl : FoundDecls) { |
| 3603 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3604 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3605 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3606 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3607 | if (!hasSameVisibilityContext(FoundVar, D)) |
| 3608 | continue; |
| 3609 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| 3610 | FoundVar->getType())) { |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3611 | |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3612 | // The VarDecl in the "From" context has a definition, but in the |
| 3613 | // "To" context we already have a definition. |
| 3614 | VarDecl *FoundDef = FoundVar->getDefinition(); |
| 3615 | if (D->isThisDeclarationADefinition() && FoundDef) |
| 3616 | // FIXME Check for ODR error if the two definitions have |
| 3617 | // different initializers? |
| 3618 | return Importer.MapImported(D, FoundDef); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3619 | |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3620 | // The VarDecl in the "From" context has an initializer, but in the |
| 3621 | // "To" context we already have an initializer. |
| 3622 | const VarDecl *FoundDInit = nullptr; |
| 3623 | if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit)) |
| 3624 | // FIXME Diagnose ODR error if the two initializers are different? |
| 3625 | return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit)); |
| 3626 | |
| 3627 | FoundByLookup = FoundVar; |
| 3628 | break; |
| 3629 | } |
| 3630 | |
| 3631 | const ArrayType *FoundArray |
| 3632 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 3633 | const ArrayType *TArray |
| 3634 | = Importer.getToContext().getAsArrayType(D->getType()); |
| 3635 | if (FoundArray && TArray) { |
| 3636 | if (isa<IncompleteArrayType>(FoundArray) && |
| 3637 | isa<ConstantArrayType>(TArray)) { |
| 3638 | // Import the type. |
| 3639 | if (auto TyOrErr = import(D->getType())) |
| 3640 | FoundVar->setType(*TyOrErr); |
| 3641 | else |
| 3642 | return TyOrErr.takeError(); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3643 | |
| 3644 | FoundByLookup = FoundVar; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3645 | break; |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3646 | } else if (isa<IncompleteArrayType>(TArray) && |
| 3647 | isa<ConstantArrayType>(FoundArray)) { |
| 3648 | FoundByLookup = FoundVar; |
| 3649 | break; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3650 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3651 | } |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3652 | |
| 3653 | Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent) |
| 3654 | << Name << D->getType() << FoundVar->getType(); |
| 3655 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 3656 | << FoundVar->getType(); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3657 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3658 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3659 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3660 | } |
| 3661 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3662 | if (!ConflictingDecls.empty()) { |
| 3663 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3664 | ConflictingDecls.data(), |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3665 | ConflictingDecls.size()); |
| 3666 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3667 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3668 | } |
| 3669 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3670 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3671 | QualType ToType; |
| 3672 | TypeSourceInfo *ToTypeSourceInfo; |
| 3673 | SourceLocation ToInnerLocStart; |
| 3674 | NestedNameSpecifierLoc ToQualifierLoc; |
| 3675 | if (auto Imp = importSeq( |
| 3676 | D->getType(), D->getTypeSourceInfo(), D->getInnerLocStart(), |
| 3677 | D->getQualifierLoc())) |
| 3678 | std::tie(ToType, ToTypeSourceInfo, ToInnerLocStart, ToQualifierLoc) = *Imp; |
| 3679 | else |
| 3680 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3681 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3682 | // Create the imported variable. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3683 | VarDecl *ToVar; |
| 3684 | if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3685 | ToInnerLocStart, Loc, |
| 3686 | Name.getAsIdentifierInfo(), |
| 3687 | ToType, ToTypeSourceInfo, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3688 | D->getStorageClass())) |
| 3689 | return ToVar; |
| 3690 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3691 | ToVar->setQualifierInfo(ToQualifierLoc); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3692 | ToVar->setAccess(D->getAccess()); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3693 | ToVar->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3694 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3695 | if (FoundByLookup) { |
| 3696 | auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl()); |
| 3697 | ToVar->setPreviousDecl(Recent); |
| 3698 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3699 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3700 | if (Error Err = ImportInitializer(D, ToVar)) |
| 3701 | return std::move(Err); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3702 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3703 | if (D->isConstexpr()) |
| 3704 | ToVar->setConstexpr(true); |
| 3705 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3706 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 3707 | DC->addDeclInternal(ToVar); |
| 3708 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
| 3709 | LexicalDC->addDeclInternal(ToVar); |
| 3710 | |
| 3711 | // Import the rest of the chain. I.e. import all subsequent declarations. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3712 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3713 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3714 | if (!RedeclOrErr) |
| 3715 | return RedeclOrErr.takeError(); |
| 3716 | } |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3717 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3718 | return ToVar; |
| 3719 | } |
| 3720 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3721 | ExpectedDecl ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3722 | // Parameters are created in the translation unit's context, then moved |
| 3723 | // into the function declaration's context afterward. |
| 3724 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3725 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3726 | DeclarationName ToDeclName; |
| 3727 | SourceLocation ToLocation; |
| 3728 | QualType ToType; |
| 3729 | if (auto Imp = importSeq(D->getDeclName(), D->getLocation(), D->getType())) |
| 3730 | std::tie(ToDeclName, ToLocation, ToType) = *Imp; |
| 3731 | else |
| 3732 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3733 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3734 | // Create the imported parameter. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3735 | ImplicitParamDecl *ToParm = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3736 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
| 3737 | ToLocation, ToDeclName.getAsIdentifierInfo(), |
| 3738 | ToType, D->getParameterKind())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3739 | return ToParm; |
| 3740 | return ToParm; |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3741 | } |
| 3742 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3743 | ExpectedDecl ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3744 | // Parameters are created in the translation unit's context, then moved |
| 3745 | // into the function declaration's context afterward. |
| 3746 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3747 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3748 | DeclarationName ToDeclName; |
| 3749 | SourceLocation ToLocation, ToInnerLocStart; |
| 3750 | QualType ToType; |
| 3751 | TypeSourceInfo *ToTypeSourceInfo; |
| 3752 | if (auto Imp = importSeq( |
| 3753 | D->getDeclName(), D->getLocation(), D->getType(), D->getInnerLocStart(), |
| 3754 | D->getTypeSourceInfo())) |
| 3755 | std::tie( |
| 3756 | ToDeclName, ToLocation, ToType, ToInnerLocStart, |
| 3757 | ToTypeSourceInfo) = *Imp; |
| 3758 | else |
| 3759 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3760 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3761 | ParmVarDecl *ToParm; |
| 3762 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3763 | ToInnerLocStart, ToLocation, |
| 3764 | ToDeclName.getAsIdentifierInfo(), ToType, |
| 3765 | ToTypeSourceInfo, D->getStorageClass(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3766 | /*DefaultArg*/ nullptr)) |
| 3767 | return ToParm; |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3768 | |
| 3769 | // Set the default argument. |
John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 3770 | ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg()); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3771 | ToParm->setKNRPromoted(D->isKNRPromoted()); |
| 3772 | |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3773 | if (D->hasUninstantiatedDefaultArg()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3774 | if (auto ToDefArgOrErr = import(D->getUninstantiatedDefaultArg())) |
| 3775 | ToParm->setUninstantiatedDefaultArg(*ToDefArgOrErr); |
| 3776 | else |
| 3777 | return ToDefArgOrErr.takeError(); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3778 | } else if (D->hasUnparsedDefaultArg()) { |
| 3779 | ToParm->setUnparsedDefaultArg(); |
| 3780 | } else if (D->hasDefaultArg()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3781 | if (auto ToDefArgOrErr = import(D->getDefaultArg())) |
| 3782 | ToParm->setDefaultArg(*ToDefArgOrErr); |
| 3783 | else |
| 3784 | return ToDefArgOrErr.takeError(); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3785 | } |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3786 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3787 | if (D->isObjCMethodParameter()) { |
| 3788 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); |
| 3789 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); |
| 3790 | } else { |
| 3791 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), |
| 3792 | D->getFunctionScopeIndex()); |
| 3793 | } |
| 3794 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3795 | return ToParm; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3796 | } |
| 3797 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3798 | ExpectedDecl ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3799 | // Import the major distinguishing characteristics of a method. |
| 3800 | DeclContext *DC, *LexicalDC; |
| 3801 | DeclarationName Name; |
| 3802 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3803 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3804 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3805 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3806 | if (ToD) |
| 3807 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3808 | |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3809 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3810 | for (auto *FoundDecl : FoundDecls) { |
| 3811 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3812 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 3813 | continue; |
| 3814 | |
| 3815 | // Check return types. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3816 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 3817 | FoundMethod->getReturnType())) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3818 | Importer.ToDiag(Loc, diag::err_odr_objc_method_result_type_inconsistent) |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3819 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 3820 | << FoundMethod->getReturnType(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3821 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3822 | diag::note_odr_objc_method_here) |
| 3823 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3824 | |
| 3825 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3826 | } |
| 3827 | |
| 3828 | // Check the number of parameters. |
| 3829 | if (D->param_size() != FoundMethod->param_size()) { |
| 3830 | Importer.ToDiag(Loc, diag::err_odr_objc_method_num_params_inconsistent) |
| 3831 | << D->isInstanceMethod() << Name |
| 3832 | << D->param_size() << FoundMethod->param_size(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3833 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3834 | diag::note_odr_objc_method_here) |
| 3835 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3836 | |
| 3837 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3838 | } |
| 3839 | |
| 3840 | // Check parameter types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3841 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3842 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 3843 | P != PEnd; ++P, ++FoundP) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3844 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3845 | (*FoundP)->getType())) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3846 | Importer.FromDiag((*P)->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3847 | diag::err_odr_objc_method_param_type_inconsistent) |
| 3848 | << D->isInstanceMethod() << Name |
| 3849 | << (*P)->getType() << (*FoundP)->getType(); |
| 3850 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 3851 | << (*FoundP)->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3852 | |
| 3853 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3854 | } |
| 3855 | } |
| 3856 | |
| 3857 | // Check variadic/non-variadic. |
| 3858 | // Check the number of parameters. |
| 3859 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
| 3860 | Importer.ToDiag(Loc, diag::err_odr_objc_method_variadic_inconsistent) |
| 3861 | << D->isInstanceMethod() << Name; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3862 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3863 | diag::note_odr_objc_method_here) |
| 3864 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3865 | |
| 3866 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3867 | } |
| 3868 | |
| 3869 | // FIXME: Any other bits we need to merge? |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3870 | return Importer.MapImported(D, FoundMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3871 | } |
| 3872 | } |
| 3873 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3874 | SourceLocation ToEndLoc; |
| 3875 | QualType ToReturnType; |
| 3876 | TypeSourceInfo *ToReturnTypeSourceInfo; |
| 3877 | if (auto Imp = importSeq( |
| 3878 | D->getEndLoc(), D->getReturnType(), D->getReturnTypeSourceInfo())) |
| 3879 | std::tie(ToEndLoc, ToReturnType, ToReturnTypeSourceInfo) = *Imp; |
| 3880 | else |
| 3881 | return Imp.takeError(); |
Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 3882 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3883 | ObjCMethodDecl *ToMethod; |
| 3884 | if (GetImportedOrCreateDecl( |
| 3885 | ToMethod, D, Importer.getToContext(), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3886 | ToEndLoc, Name.getObjCSelector(), ToReturnType, |
| 3887 | ToReturnTypeSourceInfo, DC, D->isInstanceMethod(), D->isVariadic(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3888 | D->isPropertyAccessor(), D->isImplicit(), D->isDefined(), |
| 3889 | D->getImplementationControl(), D->hasRelatedResultType())) |
| 3890 | return ToMethod; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3891 | |
| 3892 | // FIXME: When we decide to merge method definitions, we'll need to |
| 3893 | // deal with implicit parameters. |
| 3894 | |
| 3895 | // Import the parameters |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3896 | SmallVector<ParmVarDecl *, 5> ToParams; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3897 | for (auto *FromP : D->parameters()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3898 | if (Expected<ParmVarDecl *> ToPOrErr = import(FromP)) |
| 3899 | ToParams.push_back(*ToPOrErr); |
| 3900 | else |
| 3901 | return ToPOrErr.takeError(); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3902 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3903 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3904 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3905 | for (auto *ToParam : ToParams) { |
| 3906 | ToParam->setOwningFunction(ToMethod); |
| 3907 | ToMethod->addDeclInternal(ToParam); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3908 | } |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3909 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3910 | SmallVector<SourceLocation, 12> FromSelLocs; |
| 3911 | D->getSelectorLocs(FromSelLocs); |
| 3912 | SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size()); |
| 3913 | if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs)) |
| 3914 | return std::move(Err); |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3915 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3916 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3917 | |
| 3918 | ToMethod->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3919 | LexicalDC->addDeclInternal(ToMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3920 | return ToMethod; |
| 3921 | } |
| 3922 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3923 | ExpectedDecl ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3924 | // Import the major distinguishing characteristics of a category. |
| 3925 | DeclContext *DC, *LexicalDC; |
| 3926 | DeclarationName Name; |
| 3927 | SourceLocation Loc; |
| 3928 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3929 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3930 | return std::move(Err); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3931 | if (ToD) |
| 3932 | return ToD; |
| 3933 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3934 | SourceLocation ToVarianceLoc, ToLocation, ToColonLoc; |
| 3935 | TypeSourceInfo *ToTypeSourceInfo; |
| 3936 | if (auto Imp = importSeq( |
| 3937 | D->getVarianceLoc(), D->getLocation(), D->getColonLoc(), |
| 3938 | D->getTypeSourceInfo())) |
| 3939 | std::tie(ToVarianceLoc, ToLocation, ToColonLoc, ToTypeSourceInfo) = *Imp; |
| 3940 | else |
| 3941 | return Imp.takeError(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3942 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3943 | ObjCTypeParamDecl *Result; |
| 3944 | if (GetImportedOrCreateDecl( |
| 3945 | Result, D, Importer.getToContext(), DC, D->getVariance(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3946 | ToVarianceLoc, D->getIndex(), |
| 3947 | ToLocation, Name.getAsIdentifierInfo(), |
| 3948 | ToColonLoc, ToTypeSourceInfo)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3949 | return Result; |
| 3950 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3951 | Result->setLexicalDeclContext(LexicalDC); |
| 3952 | return Result; |
| 3953 | } |
| 3954 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3955 | ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3956 | // Import the major distinguishing characteristics of a category. |
| 3957 | DeclContext *DC, *LexicalDC; |
| 3958 | DeclarationName Name; |
| 3959 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3960 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3961 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3962 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3963 | if (ToD) |
| 3964 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3965 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3966 | ObjCInterfaceDecl *ToInterface; |
| 3967 | if (Error Err = importInto(ToInterface, D->getClassInterface())) |
| 3968 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3969 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3970 | // Determine if we've already encountered this category. |
| 3971 | ObjCCategoryDecl *MergeWithCategory |
| 3972 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 3973 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 3974 | if (!ToCategory) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3975 | SourceLocation ToAtStartLoc, ToCategoryNameLoc; |
| 3976 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; |
| 3977 | if (auto Imp = importSeq( |
| 3978 | D->getAtStartLoc(), D->getCategoryNameLoc(), |
| 3979 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) |
| 3980 | std::tie( |
| 3981 | ToAtStartLoc, ToCategoryNameLoc, |
| 3982 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; |
| 3983 | else |
| 3984 | return Imp.takeError(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3985 | |
| 3986 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3987 | ToAtStartLoc, Loc, |
| 3988 | ToCategoryNameLoc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3989 | Name.getAsIdentifierInfo(), ToInterface, |
| 3990 | /*TypeParamList=*/nullptr, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3991 | ToIvarLBraceLoc, |
| 3992 | ToIvarRBraceLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3993 | return ToCategory; |
| 3994 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3995 | ToCategory->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3996 | LexicalDC->addDeclInternal(ToCategory); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3997 | // Import the type parameter list after MapImported, to avoid |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3998 | // loops when bringing in their DeclContext. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3999 | if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList())) |
| 4000 | ToCategory->setTypeParamList(*PListOrErr); |
| 4001 | else |
| 4002 | return PListOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4003 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4004 | // Import protocols |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4005 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4006 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4007 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 4008 | = D->protocol_loc_begin(); |
| 4009 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 4010 | FromProtoEnd = D->protocol_end(); |
| 4011 | FromProto != FromProtoEnd; |
| 4012 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4013 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4014 | Protocols.push_back(*ToProtoOrErr); |
| 4015 | else |
| 4016 | return ToProtoOrErr.takeError(); |
| 4017 | |
| 4018 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4019 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4020 | else |
| 4021 | return ToProtoLocOrErr.takeError(); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4022 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4023 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4024 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4025 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 4026 | ProtocolLocs.data(), Importer.getToContext()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4027 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4028 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4029 | Importer.MapImported(D, ToCategory); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4030 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4031 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4032 | // Import all of the members of this category. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4033 | if (Error Err = ImportDeclContext(D)) |
| 4034 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4035 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4036 | // If we have an implementation, import it as well. |
| 4037 | if (D->getImplementation()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4038 | if (Expected<ObjCCategoryImplDecl *> ToImplOrErr = |
| 4039 | import(D->getImplementation())) |
| 4040 | ToCategory->setImplementation(*ToImplOrErr); |
| 4041 | else |
| 4042 | return ToImplOrErr.takeError(); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4043 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4044 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4045 | return ToCategory; |
| 4046 | } |
| 4047 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4048 | Error ASTNodeImporter::ImportDefinition( |
| 4049 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4050 | if (To->getDefinition()) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4051 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4052 | if (Error Err = ImportDeclContext(From)) |
| 4053 | return Err; |
| 4054 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4055 | } |
| 4056 | |
| 4057 | // Start the protocol definition |
| 4058 | To->startDefinition(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4059 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4060 | // Import protocols |
| 4061 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4062 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4063 | ObjCProtocolDecl::protocol_loc_iterator FromProtoLoc = |
| 4064 | From->protocol_loc_begin(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4065 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4066 | FromProtoEnd = From->protocol_end(); |
| 4067 | FromProto != FromProtoEnd; |
| 4068 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4069 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4070 | Protocols.push_back(*ToProtoOrErr); |
| 4071 | else |
| 4072 | return ToProtoOrErr.takeError(); |
| 4073 | |
| 4074 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4075 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4076 | else |
| 4077 | return ToProtoLocOrErr.takeError(); |
| 4078 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4079 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4080 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4081 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4082 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4083 | ProtocolLocs.data(), Importer.getToContext()); |
| 4084 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4085 | if (shouldForceImportDeclContext(Kind)) { |
| 4086 | // Import all of the members of this protocol. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4087 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4088 | return Err; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4089 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4090 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4091 | } |
| 4092 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4093 | ExpectedDecl ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4094 | // 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] | 4095 | // from, but this particular declaration is not that definition, import the |
| 4096 | // definition and map to that. |
| 4097 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 4098 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4099 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4100 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4101 | else |
| 4102 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4103 | } |
| 4104 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4105 | // Import the major distinguishing characteristics of a protocol. |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4106 | DeclContext *DC, *LexicalDC; |
| 4107 | DeclarationName Name; |
| 4108 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4109 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4110 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4111 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4112 | if (ToD) |
| 4113 | return ToD; |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4114 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4115 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4116 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4117 | for (auto *FoundDecl : FoundDecls) { |
| 4118 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4119 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4120 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4121 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4122 | break; |
| 4123 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4124 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4125 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4126 | if (!ToProto) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4127 | auto ToAtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4128 | if (!ToAtBeginLocOrErr) |
| 4129 | return ToAtBeginLocOrErr.takeError(); |
| 4130 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4131 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, |
| 4132 | Name.getAsIdentifierInfo(), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4133 | *ToAtBeginLocOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4134 | /*PrevDecl=*/nullptr)) |
| 4135 | return ToProto; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4136 | ToProto->setLexicalDeclContext(LexicalDC); |
| 4137 | LexicalDC->addDeclInternal(ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4138 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4139 | |
| 4140 | Importer.MapImported(D, ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4141 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4142 | if (D->isThisDeclarationADefinition()) |
| 4143 | if (Error Err = ImportDefinition(D, ToProto)) |
| 4144 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4145 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4146 | return ToProto; |
| 4147 | } |
| 4148 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4149 | ExpectedDecl ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 4150 | DeclContext *DC, *LexicalDC; |
| 4151 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4152 | return std::move(Err); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4153 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4154 | ExpectedSLoc ExternLocOrErr = import(D->getExternLoc()); |
| 4155 | if (!ExternLocOrErr) |
| 4156 | return ExternLocOrErr.takeError(); |
| 4157 | |
| 4158 | ExpectedSLoc LangLocOrErr = import(D->getLocation()); |
| 4159 | if (!LangLocOrErr) |
| 4160 | return LangLocOrErr.takeError(); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4161 | |
| 4162 | bool HasBraces = D->hasBraces(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4163 | |
| 4164 | LinkageSpecDecl *ToLinkageSpec; |
| 4165 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4166 | *ExternLocOrErr, *LangLocOrErr, |
| 4167 | D->getLanguage(), HasBraces)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4168 | return ToLinkageSpec; |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4169 | |
| 4170 | if (HasBraces) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4171 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); |
| 4172 | if (!RBraceLocOrErr) |
| 4173 | return RBraceLocOrErr.takeError(); |
| 4174 | ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4175 | } |
| 4176 | |
| 4177 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 4178 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 4179 | |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4180 | return ToLinkageSpec; |
| 4181 | } |
| 4182 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4183 | ExpectedDecl ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4184 | DeclContext *DC, *LexicalDC; |
| 4185 | DeclarationName Name; |
| 4186 | SourceLocation Loc; |
| 4187 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4188 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4189 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4190 | if (ToD) |
| 4191 | return ToD; |
| 4192 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4193 | SourceLocation ToLoc, ToUsingLoc; |
| 4194 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4195 | if (auto Imp = importSeq( |
| 4196 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc())) |
| 4197 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc) = *Imp; |
| 4198 | else |
| 4199 | return Imp.takeError(); |
| 4200 | |
| 4201 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4202 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4203 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4204 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4205 | UsingDecl *ToUsing; |
| 4206 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4207 | ToUsingLoc, ToQualifierLoc, NameInfo, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4208 | D->hasTypename())) |
| 4209 | return ToUsing; |
| 4210 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4211 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4212 | LexicalDC->addDeclInternal(ToUsing); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4213 | |
| 4214 | if (NamedDecl *FromPattern = |
| 4215 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4216 | if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern)) |
| 4217 | Importer.getToContext().setInstantiatedFromUsingDecl( |
| 4218 | ToUsing, *ToPatternOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4219 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4220 | return ToPatternOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4221 | } |
| 4222 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4223 | for (UsingShadowDecl *FromShadow : D->shadows()) { |
| 4224 | if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow)) |
| 4225 | ToUsing->addShadowDecl(*ToShadowOrErr); |
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 | // FIXME: We return error here but the definition is already created |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4228 | // and available with lookups. How to fix this?.. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4229 | return ToShadowOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4230 | } |
| 4231 | return ToUsing; |
| 4232 | } |
| 4233 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4234 | ExpectedDecl ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4235 | DeclContext *DC, *LexicalDC; |
| 4236 | DeclarationName Name; |
| 4237 | SourceLocation Loc; |
| 4238 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4239 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4240 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4241 | if (ToD) |
| 4242 | return ToD; |
| 4243 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4244 | Expected<UsingDecl *> ToUsingOrErr = import(D->getUsingDecl()); |
| 4245 | if (!ToUsingOrErr) |
| 4246 | return ToUsingOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4247 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4248 | Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl()); |
| 4249 | if (!ToTargetOrErr) |
| 4250 | return ToTargetOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4251 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4252 | UsingShadowDecl *ToShadow; |
| 4253 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4254 | *ToUsingOrErr, *ToTargetOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4255 | return ToShadow; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4256 | |
| 4257 | ToShadow->setLexicalDeclContext(LexicalDC); |
| 4258 | ToShadow->setAccess(D->getAccess()); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4259 | |
| 4260 | if (UsingShadowDecl *FromPattern = |
| 4261 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4262 | if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern)) |
| 4263 | Importer.getToContext().setInstantiatedFromUsingShadowDecl( |
| 4264 | ToShadow, *ToPatternOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4265 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4266 | // FIXME: We return error here but the definition is already created |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4267 | // and available with lookups. How to fix this?.. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4268 | return ToPatternOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4269 | } |
| 4270 | |
| 4271 | LexicalDC->addDeclInternal(ToShadow); |
| 4272 | |
| 4273 | return ToShadow; |
| 4274 | } |
| 4275 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4276 | ExpectedDecl ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4277 | DeclContext *DC, *LexicalDC; |
| 4278 | DeclarationName Name; |
| 4279 | SourceLocation Loc; |
| 4280 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4281 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4282 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4283 | if (ToD) |
| 4284 | return ToD; |
| 4285 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4286 | auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor()); |
| 4287 | if (!ToComAncestorOrErr) |
| 4288 | return ToComAncestorOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4289 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4290 | NamespaceDecl *ToNominatedNamespace; |
| 4291 | SourceLocation ToUsingLoc, ToNamespaceKeyLocation, ToIdentLocation; |
| 4292 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4293 | if (auto Imp = importSeq( |
| 4294 | D->getNominatedNamespace(), D->getUsingLoc(), |
| 4295 | D->getNamespaceKeyLocation(), D->getQualifierLoc(), |
| 4296 | D->getIdentLocation())) |
| 4297 | std::tie( |
| 4298 | ToNominatedNamespace, ToUsingLoc, ToNamespaceKeyLocation, |
| 4299 | ToQualifierLoc, ToIdentLocation) = *Imp; |
| 4300 | else |
| 4301 | return Imp.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4302 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4303 | UsingDirectiveDecl *ToUsingDir; |
| 4304 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4305 | ToUsingLoc, |
| 4306 | ToNamespaceKeyLocation, |
| 4307 | ToQualifierLoc, |
| 4308 | ToIdentLocation, |
| 4309 | ToNominatedNamespace, *ToComAncestorOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4310 | return ToUsingDir; |
| 4311 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4312 | ToUsingDir->setLexicalDeclContext(LexicalDC); |
| 4313 | LexicalDC->addDeclInternal(ToUsingDir); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4314 | |
| 4315 | return ToUsingDir; |
| 4316 | } |
| 4317 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4318 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4319 | UnresolvedUsingValueDecl *D) { |
| 4320 | DeclContext *DC, *LexicalDC; |
| 4321 | DeclarationName Name; |
| 4322 | SourceLocation Loc; |
| 4323 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4324 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4325 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4326 | if (ToD) |
| 4327 | return ToD; |
| 4328 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4329 | SourceLocation ToLoc, ToUsingLoc, ToEllipsisLoc; |
| 4330 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4331 | if (auto Imp = importSeq( |
| 4332 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc(), |
| 4333 | D->getEllipsisLoc())) |
| 4334 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; |
| 4335 | else |
| 4336 | return Imp.takeError(); |
| 4337 | |
| 4338 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4339 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4340 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4341 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4342 | UnresolvedUsingValueDecl *ToUsingValue; |
| 4343 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4344 | ToUsingLoc, ToQualifierLoc, NameInfo, |
| 4345 | ToEllipsisLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4346 | return ToUsingValue; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4347 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4348 | ToUsingValue->setAccess(D->getAccess()); |
| 4349 | ToUsingValue->setLexicalDeclContext(LexicalDC); |
| 4350 | LexicalDC->addDeclInternal(ToUsingValue); |
| 4351 | |
| 4352 | return ToUsingValue; |
| 4353 | } |
| 4354 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4355 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4356 | UnresolvedUsingTypenameDecl *D) { |
| 4357 | DeclContext *DC, *LexicalDC; |
| 4358 | DeclarationName Name; |
| 4359 | SourceLocation Loc; |
| 4360 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4361 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4362 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4363 | if (ToD) |
| 4364 | return ToD; |
| 4365 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4366 | SourceLocation ToUsingLoc, ToTypenameLoc, ToEllipsisLoc; |
| 4367 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4368 | if (auto Imp = importSeq( |
| 4369 | D->getUsingLoc(), D->getTypenameLoc(), D->getQualifierLoc(), |
| 4370 | D->getEllipsisLoc())) |
| 4371 | std::tie(ToUsingLoc, ToTypenameLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; |
| 4372 | else |
| 4373 | return Imp.takeError(); |
| 4374 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4375 | UnresolvedUsingTypenameDecl *ToUsing; |
| 4376 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4377 | ToUsingLoc, ToTypenameLoc, |
| 4378 | ToQualifierLoc, Loc, Name, ToEllipsisLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4379 | return ToUsing; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4380 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4381 | ToUsing->setAccess(D->getAccess()); |
| 4382 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4383 | LexicalDC->addDeclInternal(ToUsing); |
| 4384 | |
| 4385 | return ToUsing; |
| 4386 | } |
| 4387 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4388 | |
| 4389 | Error ASTNodeImporter::ImportDefinition( |
| 4390 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4391 | if (To->getDefinition()) { |
| 4392 | // Check consistency of superclass. |
| 4393 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 4394 | if (FromSuper) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4395 | if (auto FromSuperOrErr = import(FromSuper)) |
| 4396 | FromSuper = *FromSuperOrErr; |
| 4397 | else |
| 4398 | return FromSuperOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4399 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4400 | |
| 4401 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4402 | if ((bool)FromSuper != (bool)ToSuper || |
| 4403 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4404 | Importer.ToDiag(To->getLocation(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4405 | diag::err_odr_objc_superclass_inconsistent) |
| 4406 | << To->getDeclName(); |
| 4407 | if (ToSuper) |
| 4408 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 4409 | << To->getSuperClass()->getDeclName(); |
| 4410 | else |
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::note_odr_objc_missing_superclass); |
| 4413 | if (From->getSuperClass()) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4414 | Importer.FromDiag(From->getSuperClassLoc(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4415 | diag::note_odr_objc_superclass) |
| 4416 | << From->getSuperClass()->getDeclName(); |
| 4417 | else |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4418 | Importer.FromDiag(From->getLocation(), |
| 4419 | diag::note_odr_objc_missing_superclass); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4420 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4421 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4422 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4423 | if (Error Err = ImportDeclContext(From)) |
| 4424 | return Err; |
| 4425 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4426 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4427 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4428 | // Start the definition. |
| 4429 | To->startDefinition(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4430 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4431 | // If this class has a superclass, import it. |
| 4432 | if (From->getSuperClass()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4433 | if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo())) |
| 4434 | To->setSuperClass(*SuperTInfoOrErr); |
| 4435 | else |
| 4436 | return SuperTInfoOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4437 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4438 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4439 | // Import protocols |
| 4440 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4441 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4442 | ObjCInterfaceDecl::protocol_loc_iterator FromProtoLoc = |
| 4443 | From->protocol_loc_begin(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4444 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4445 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4446 | FromProtoEnd = From->protocol_end(); |
| 4447 | FromProto != FromProtoEnd; |
| 4448 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4449 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4450 | Protocols.push_back(*ToProtoOrErr); |
| 4451 | else |
| 4452 | return ToProtoOrErr.takeError(); |
| 4453 | |
| 4454 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4455 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4456 | else |
| 4457 | return ToProtoLocOrErr.takeError(); |
| 4458 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4459 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4460 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4461 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4462 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4463 | ProtocolLocs.data(), Importer.getToContext()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4464 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4465 | // Import categories. When the categories themselves are imported, they'll |
| 4466 | // hook themselves into this interface. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4467 | for (auto *Cat : From->known_categories()) { |
| 4468 | auto ToCatOrErr = import(Cat); |
| 4469 | if (!ToCatOrErr) |
| 4470 | return ToCatOrErr.takeError(); |
| 4471 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4472 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4473 | // If we have an @implementation, import it as well. |
| 4474 | if (From->getImplementation()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4475 | if (Expected<ObjCImplementationDecl *> ToImplOrErr = |
| 4476 | import(From->getImplementation())) |
| 4477 | To->setImplementation(*ToImplOrErr); |
| 4478 | else |
| 4479 | return ToImplOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4480 | } |
| 4481 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4482 | if (shouldForceImportDeclContext(Kind)) { |
| 4483 | // Import all of the members of this class. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4484 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4485 | return Err; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4486 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4487 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4488 | } |
| 4489 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4490 | Expected<ObjCTypeParamList *> |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4491 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 4492 | if (!list) |
| 4493 | return nullptr; |
| 4494 | |
| 4495 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4496 | for (auto *fromTypeParam : *list) { |
| 4497 | if (auto toTypeParamOrErr = import(fromTypeParam)) |
| 4498 | toTypeParams.push_back(*toTypeParamOrErr); |
| 4499 | else |
| 4500 | return toTypeParamOrErr.takeError(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4501 | } |
| 4502 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4503 | auto LAngleLocOrErr = import(list->getLAngleLoc()); |
| 4504 | if (!LAngleLocOrErr) |
| 4505 | return LAngleLocOrErr.takeError(); |
| 4506 | |
| 4507 | auto RAngleLocOrErr = import(list->getRAngleLoc()); |
| 4508 | if (!RAngleLocOrErr) |
| 4509 | return RAngleLocOrErr.takeError(); |
| 4510 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4511 | return ObjCTypeParamList::create(Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4512 | *LAngleLocOrErr, |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4513 | toTypeParams, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4514 | *RAngleLocOrErr); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4515 | } |
| 4516 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4517 | ExpectedDecl ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4518 | // If this class has a definition in the translation unit we're coming from, |
| 4519 | // but this particular declaration is not that definition, import the |
| 4520 | // definition and map to that. |
| 4521 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 4522 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4523 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4524 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4525 | else |
| 4526 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4527 | } |
| 4528 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4529 | // Import the major distinguishing characteristics of an @interface. |
| 4530 | DeclContext *DC, *LexicalDC; |
| 4531 | DeclarationName Name; |
| 4532 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4533 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4534 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4535 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4536 | if (ToD) |
| 4537 | return ToD; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4538 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4539 | // Look for an existing interface with the same name. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4540 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4541 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4542 | for (auto *FoundDecl : FoundDecls) { |
| 4543 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4544 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4545 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4546 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4547 | break; |
| 4548 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4549 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4550 | // Create an interface declaration, if one does not already exist. |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4551 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4552 | if (!ToIface) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4553 | ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4554 | if (!AtBeginLocOrErr) |
| 4555 | return AtBeginLocOrErr.takeError(); |
| 4556 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4557 | if (GetImportedOrCreateDecl( |
| 4558 | ToIface, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4559 | *AtBeginLocOrErr, Name.getAsIdentifierInfo(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4560 | /*TypeParamList=*/nullptr, |
| 4561 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) |
| 4562 | return ToIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4563 | ToIface->setLexicalDeclContext(LexicalDC); |
| 4564 | LexicalDC->addDeclInternal(ToIface); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4565 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4566 | Importer.MapImported(D, ToIface); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4567 | // Import the type parameter list after MapImported, to avoid |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4568 | // loops when bringing in their DeclContext. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4569 | if (auto ToPListOrErr = |
| 4570 | ImportObjCTypeParamList(D->getTypeParamListAsWritten())) |
| 4571 | ToIface->setTypeParamList(*ToPListOrErr); |
| 4572 | else |
| 4573 | return ToPListOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4574 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4575 | if (D->isThisDeclarationADefinition()) |
| 4576 | if (Error Err = ImportDefinition(D, ToIface)) |
| 4577 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4578 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4579 | return ToIface; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4580 | } |
| 4581 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4582 | ExpectedDecl |
| 4583 | ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 4584 | ObjCCategoryDecl *Category; |
| 4585 | if (Error Err = importInto(Category, D->getCategoryDecl())) |
| 4586 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4587 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4588 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 4589 | if (!ToImpl) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4590 | DeclContext *DC, *LexicalDC; |
| 4591 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4592 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4593 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4594 | SourceLocation ToLocation, ToAtStartLoc, ToCategoryNameLoc; |
| 4595 | if (auto Imp = importSeq( |
| 4596 | D->getLocation(), D->getAtStartLoc(), D->getCategoryNameLoc())) |
| 4597 | std::tie(ToLocation, ToAtStartLoc, ToCategoryNameLoc) = *Imp; |
| 4598 | else |
| 4599 | return Imp.takeError(); |
| 4600 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4601 | if (GetImportedOrCreateDecl( |
| 4602 | ToImpl, D, Importer.getToContext(), DC, |
| 4603 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4604 | ToLocation, ToAtStartLoc, ToCategoryNameLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4605 | return ToImpl; |
| 4606 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4607 | ToImpl->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4608 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4609 | Category->setImplementation(ToImpl); |
| 4610 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4611 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4612 | Importer.MapImported(D, ToImpl); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4613 | if (Error Err = ImportDeclContext(D)) |
| 4614 | return std::move(Err); |
| 4615 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4616 | return ToImpl; |
| 4617 | } |
| 4618 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4619 | ExpectedDecl |
| 4620 | ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4621 | // Find the corresponding interface. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4622 | ObjCInterfaceDecl *Iface; |
| 4623 | if (Error Err = importInto(Iface, D->getClassInterface())) |
| 4624 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4625 | |
| 4626 | // Import the superclass, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4627 | ObjCInterfaceDecl *Super; |
| 4628 | if (Error Err = importInto(Super, D->getSuperClass())) |
| 4629 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4630 | |
| 4631 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 4632 | if (!Impl) { |
| 4633 | // We haven't imported an implementation yet. Create a new @implementation |
| 4634 | // now. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4635 | DeclContext *DC, *LexicalDC; |
| 4636 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4637 | return std::move(Err); |
| 4638 | |
| 4639 | SourceLocation ToLocation, ToAtStartLoc, ToSuperClassLoc; |
| 4640 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; |
| 4641 | if (auto Imp = importSeq( |
| 4642 | D->getLocation(), D->getAtStartLoc(), D->getSuperClassLoc(), |
| 4643 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) |
| 4644 | std::tie( |
| 4645 | ToLocation, ToAtStartLoc, ToSuperClassLoc, |
| 4646 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; |
| 4647 | else |
| 4648 | return Imp.takeError(); |
| 4649 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4650 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4651 | DC, Iface, Super, |
| 4652 | ToLocation, |
| 4653 | ToAtStartLoc, |
| 4654 | ToSuperClassLoc, |
| 4655 | ToIvarLBraceLoc, |
| 4656 | ToIvarRBraceLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4657 | return Impl; |
| 4658 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4659 | Impl->setLexicalDeclContext(LexicalDC); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4660 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4661 | // Associate the implementation with the class it implements. |
| 4662 | Iface->setImplementation(Impl); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4663 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4664 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4665 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4666 | |
| 4667 | // Verify that the existing @implementation has the same superclass. |
| 4668 | if ((Super && !Impl->getSuperClass()) || |
| 4669 | (!Super && Impl->getSuperClass()) || |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4670 | (Super && Impl->getSuperClass() && |
| 4671 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 4672 | Impl->getSuperClass()))) { |
| 4673 | Importer.ToDiag(Impl->getLocation(), |
| 4674 | diag::err_odr_objc_superclass_inconsistent) |
| 4675 | << Iface->getDeclName(); |
| 4676 | // FIXME: It would be nice to have the location of the superclass |
| 4677 | // below. |
| 4678 | if (Impl->getSuperClass()) |
| 4679 | Importer.ToDiag(Impl->getLocation(), |
| 4680 | diag::note_odr_objc_superclass) |
| 4681 | << Impl->getSuperClass()->getDeclName(); |
| 4682 | else |
| 4683 | Importer.ToDiag(Impl->getLocation(), |
| 4684 | diag::note_odr_objc_missing_superclass); |
| 4685 | if (D->getSuperClass()) |
| 4686 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4687 | diag::note_odr_objc_superclass) |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4688 | << D->getSuperClass()->getDeclName(); |
| 4689 | else |
| 4690 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4691 | diag::note_odr_objc_missing_superclass); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4692 | |
| 4693 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4694 | } |
| 4695 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4696 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4697 | // Import all of the members of this @implementation. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4698 | if (Error Err = ImportDeclContext(D)) |
| 4699 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4700 | |
| 4701 | return Impl; |
| 4702 | } |
| 4703 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4704 | ExpectedDecl ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4705 | // Import the major distinguishing characteristics of an @property. |
| 4706 | DeclContext *DC, *LexicalDC; |
| 4707 | DeclarationName Name; |
| 4708 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4709 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4710 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4711 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4712 | if (ToD) |
| 4713 | return ToD; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4714 | |
| 4715 | // Check whether we have already imported this property. |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4716 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4717 | for (auto *FoundDecl : FoundDecls) { |
| 4718 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4719 | // Check property types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4720 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4721 | FoundProp->getType())) { |
| 4722 | Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent) |
| 4723 | << Name << D->getType() << FoundProp->getType(); |
| 4724 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 4725 | << FoundProp->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4726 | |
| 4727 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4728 | } |
| 4729 | |
| 4730 | // FIXME: Check property attributes, getters, setters, etc.? |
| 4731 | |
| 4732 | // Consider these properties to be equivalent. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4733 | Importer.MapImported(D, FoundProp); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4734 | return FoundProp; |
| 4735 | } |
| 4736 | } |
| 4737 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4738 | QualType ToType; |
| 4739 | TypeSourceInfo *ToTypeSourceInfo; |
| 4740 | SourceLocation ToAtLoc, ToLParenLoc; |
| 4741 | if (auto Imp = importSeq( |
| 4742 | D->getType(), D->getTypeSourceInfo(), D->getAtLoc(), D->getLParenLoc())) |
| 4743 | std::tie(ToType, ToTypeSourceInfo, ToAtLoc, ToLParenLoc) = *Imp; |
| 4744 | else |
| 4745 | return Imp.takeError(); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4746 | |
| 4747 | // Create the new property. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4748 | ObjCPropertyDecl *ToProperty; |
| 4749 | if (GetImportedOrCreateDecl( |
| 4750 | ToProperty, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4751 | Name.getAsIdentifierInfo(), ToAtLoc, |
| 4752 | ToLParenLoc, ToType, |
| 4753 | ToTypeSourceInfo, D->getPropertyImplementation())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4754 | return ToProperty; |
| 4755 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4756 | Selector ToGetterName, ToSetterName; |
| 4757 | SourceLocation ToGetterNameLoc, ToSetterNameLoc; |
| 4758 | ObjCMethodDecl *ToGetterMethodDecl, *ToSetterMethodDecl; |
| 4759 | ObjCIvarDecl *ToPropertyIvarDecl; |
| 4760 | if (auto Imp = importSeq( |
| 4761 | D->getGetterName(), D->getSetterName(), |
| 4762 | D->getGetterNameLoc(), D->getSetterNameLoc(), |
| 4763 | D->getGetterMethodDecl(), D->getSetterMethodDecl(), |
| 4764 | D->getPropertyIvarDecl())) |
| 4765 | std::tie( |
| 4766 | ToGetterName, ToSetterName, |
| 4767 | ToGetterNameLoc, ToSetterNameLoc, |
| 4768 | ToGetterMethodDecl, ToSetterMethodDecl, |
| 4769 | ToPropertyIvarDecl) = *Imp; |
| 4770 | else |
| 4771 | return Imp.takeError(); |
| 4772 | |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4773 | ToProperty->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4774 | LexicalDC->addDeclInternal(ToProperty); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4775 | |
| 4776 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 4777 | ToProperty->setPropertyAttributesAsWritten( |
| 4778 | D->getPropertyAttributesAsWritten()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4779 | ToProperty->setGetterName(ToGetterName, ToGetterNameLoc); |
| 4780 | ToProperty->setSetterName(ToSetterName, ToSetterNameLoc); |
| 4781 | ToProperty->setGetterMethodDecl(ToGetterMethodDecl); |
| 4782 | ToProperty->setSetterMethodDecl(ToSetterMethodDecl); |
| 4783 | ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4784 | return ToProperty; |
| 4785 | } |
| 4786 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4787 | ExpectedDecl |
| 4788 | ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 4789 | ObjCPropertyDecl *Property; |
| 4790 | if (Error Err = importInto(Property, D->getPropertyDecl())) |
| 4791 | return std::move(Err); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4792 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4793 | DeclContext *DC, *LexicalDC; |
| 4794 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4795 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4796 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4797 | auto *InImpl = cast<ObjCImplDecl>(LexicalDC); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4798 | |
| 4799 | // Import the ivar (for an @synthesize). |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4800 | ObjCIvarDecl *Ivar = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4801 | if (Error Err = importInto(Ivar, D->getPropertyIvarDecl())) |
| 4802 | return std::move(Err); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4803 | |
| 4804 | ObjCPropertyImplDecl *ToImpl |
Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 4805 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 4806 | Property->getQueryKind()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4807 | if (!ToImpl) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4808 | SourceLocation ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc; |
| 4809 | if (auto Imp = importSeq( |
| 4810 | D->getBeginLoc(), D->getLocation(), D->getPropertyIvarDeclLoc())) |
| 4811 | std::tie(ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc) = *Imp; |
| 4812 | else |
| 4813 | return Imp.takeError(); |
| 4814 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4815 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4816 | ToBeginLoc, |
| 4817 | ToLocation, Property, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4818 | D->getPropertyImplementation(), Ivar, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4819 | ToPropertyIvarDeclLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4820 | return ToImpl; |
| 4821 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4822 | ToImpl->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4823 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4824 | } else { |
| 4825 | // Check that we have the same kind of property implementation (@synthesize |
| 4826 | // vs. @dynamic). |
| 4827 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4828 | Importer.ToDiag(ToImpl->getLocation(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4829 | diag::err_odr_objc_property_impl_kind_inconsistent) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4830 | << Property->getDeclName() |
| 4831 | << (ToImpl->getPropertyImplementation() |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4832 | == ObjCPropertyImplDecl::Dynamic); |
| 4833 | Importer.FromDiag(D->getLocation(), |
| 4834 | diag::note_odr_objc_property_impl_kind) |
| 4835 | << D->getPropertyDecl()->getDeclName() |
| 4836 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4837 | |
| 4838 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4839 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4840 | |
| 4841 | // For @synthesize, check that we have the same |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4842 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 4843 | Ivar != ToImpl->getPropertyIvarDecl()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4844 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4845 | diag::err_odr_objc_synthesize_ivar_inconsistent) |
| 4846 | << Property->getDeclName() |
| 4847 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 4848 | << Ivar->getDeclName(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4849 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4850 | diag::note_odr_objc_synthesize_ivar_here) |
| 4851 | << D->getPropertyIvarDecl()->getDeclName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4852 | |
| 4853 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4854 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4855 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4856 | // Merge the existing implementation with the new implementation. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4857 | Importer.MapImported(D, ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4858 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4859 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4860 | return ToImpl; |
| 4861 | } |
| 4862 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4863 | ExpectedDecl |
| 4864 | ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4865 | // For template arguments, we adopt the translation unit as our declaration |
| 4866 | // context. This context will be fixed when the actual template declaration |
| 4867 | // is created. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4868 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4869 | // FIXME: Import default argument. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4870 | |
| 4871 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 4872 | if (!BeginLocOrErr) |
| 4873 | return BeginLocOrErr.takeError(); |
| 4874 | |
| 4875 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 4876 | if (!LocationOrErr) |
| 4877 | return LocationOrErr.takeError(); |
| 4878 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4879 | TemplateTypeParmDecl *ToD = nullptr; |
| 4880 | (void)GetImportedOrCreateDecl( |
| 4881 | ToD, D, Importer.getToContext(), |
| 4882 | Importer.getToContext().getTranslationUnitDecl(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4883 | *BeginLocOrErr, *LocationOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4884 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), |
| 4885 | D->wasDeclaredWithTypename(), D->isParameterPack()); |
| 4886 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4887 | } |
| 4888 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4889 | ExpectedDecl |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4890 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4891 | DeclarationName ToDeclName; |
| 4892 | SourceLocation ToLocation, ToInnerLocStart; |
| 4893 | QualType ToType; |
| 4894 | TypeSourceInfo *ToTypeSourceInfo; |
| 4895 | if (auto Imp = importSeq( |
| 4896 | D->getDeclName(), D->getLocation(), D->getType(), D->getTypeSourceInfo(), |
| 4897 | D->getInnerLocStart())) |
| 4898 | std::tie( |
| 4899 | ToDeclName, ToLocation, ToType, ToTypeSourceInfo, |
| 4900 | ToInnerLocStart) = *Imp; |
| 4901 | else |
| 4902 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4903 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4904 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4905 | |
| 4906 | NonTypeTemplateParmDecl *ToD = nullptr; |
| 4907 | (void)GetImportedOrCreateDecl( |
| 4908 | ToD, D, Importer.getToContext(), |
| 4909 | Importer.getToContext().getTranslationUnitDecl(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4910 | ToInnerLocStart, ToLocation, D->getDepth(), |
| 4911 | D->getPosition(), ToDeclName.getAsIdentifierInfo(), ToType, |
| 4912 | D->isParameterPack(), ToTypeSourceInfo); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4913 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4914 | } |
| 4915 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4916 | ExpectedDecl |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4917 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 4918 | // Import the name of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4919 | auto NameOrErr = import(D->getDeclName()); |
| 4920 | if (!NameOrErr) |
| 4921 | return NameOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4922 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4923 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4924 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 4925 | if (!LocationOrErr) |
| 4926 | return LocationOrErr.takeError(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4927 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4928 | // Import template parameters. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4929 | auto TemplateParamsOrErr = ImportTemplateParameterList( |
| 4930 | D->getTemplateParameters()); |
| 4931 | if (!TemplateParamsOrErr) |
| 4932 | return TemplateParamsOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4933 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4934 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4935 | |
| 4936 | TemplateTemplateParmDecl *ToD = nullptr; |
| 4937 | (void)GetImportedOrCreateDecl( |
| 4938 | ToD, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4939 | Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr, |
| 4940 | D->getDepth(), D->getPosition(), D->isParameterPack(), |
| 4941 | (*NameOrErr).getAsIdentifierInfo(), |
| 4942 | *TemplateParamsOrErr); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4943 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4944 | } |
| 4945 | |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4946 | // Returns the definition for a (forward) declaration of a ClassTemplateDecl, if |
| 4947 | // it has any definition in the redecl chain. |
| 4948 | static ClassTemplateDecl *getDefinition(ClassTemplateDecl *D) { |
| 4949 | CXXRecordDecl *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); |
| 4950 | if (!ToTemplatedDef) |
| 4951 | return nullptr; |
| 4952 | ClassTemplateDecl *TemplateWithDef = |
| 4953 | ToTemplatedDef->getDescribedClassTemplate(); |
| 4954 | return TemplateWithDef; |
| 4955 | } |
| 4956 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4957 | ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4958 | bool IsFriend = D->getFriendObjectKind() != Decl::FOK_None; |
| 4959 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4960 | // Import the major distinguishing characteristics of this class template. |
| 4961 | DeclContext *DC, *LexicalDC; |
| 4962 | DeclarationName Name; |
| 4963 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4964 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4965 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4966 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4967 | if (ToD) |
| 4968 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4969 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4970 | ClassTemplateDecl *FoundByLookup = nullptr; |
| 4971 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4972 | // We may already have a template of the same name; try to find and match it. |
| 4973 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4974 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4975 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4976 | for (auto *FoundDecl : FoundDecls) { |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4977 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary | |
| 4978 | Decl::IDNS_TagFriend)) |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4979 | continue; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4980 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4981 | Decl *Found = FoundDecl; |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4982 | auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found); |
| 4983 | if (FoundTemplate) { |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4984 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4985 | if (IsStructuralMatch(D, FoundTemplate)) { |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4986 | ClassTemplateDecl *TemplateWithDef = getDefinition(FoundTemplate); |
| 4987 | if (D->isThisDeclarationADefinition() && TemplateWithDef) { |
| 4988 | return Importer.MapImported(D, TemplateWithDef); |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4989 | } |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4990 | FoundByLookup = FoundTemplate; |
| 4991 | break; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4992 | } |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4993 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4994 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4995 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4996 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4997 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4998 | if (!ConflictingDecls.empty()) { |
| 4999 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5000 | ConflictingDecls.data(), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5001 | ConflictingDecls.size()); |
| 5002 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5003 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5004 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5005 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5006 | } |
| 5007 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5008 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); |
| 5009 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5010 | // Create the declaration that is being templated. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5011 | CXXRecordDecl *ToTemplated; |
| 5012 | if (Error Err = importInto(ToTemplated, FromTemplated)) |
| 5013 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5014 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5015 | // Create the class template declaration itself. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5016 | auto TemplateParamsOrErr = ImportTemplateParameterList( |
| 5017 | D->getTemplateParameters()); |
| 5018 | if (!TemplateParamsOrErr) |
| 5019 | return TemplateParamsOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5020 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5021 | ClassTemplateDecl *D2; |
| 5022 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5023 | *TemplateParamsOrErr, ToTemplated)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5024 | return D2; |
| 5025 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5026 | ToTemplated->setDescribedClassTemplate(D2); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5027 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5028 | D2->setAccess(D->getAccess()); |
| 5029 | D2->setLexicalDeclContext(LexicalDC); |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5030 | |
| 5031 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 5032 | DC->addDeclInternal(D2); |
| 5033 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5034 | LexicalDC->addDeclInternal(D2); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5035 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5036 | if (FoundByLookup) { |
| 5037 | auto *Recent = |
| 5038 | const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl()); |
| 5039 | |
| 5040 | // It is possible that during the import of the class template definition |
| 5041 | // we start the import of a fwd friend decl of the very same class template |
| 5042 | // and we add the fwd friend decl to the lookup table. But the ToTemplated |
| 5043 | // had been created earlier and by that time the lookup could not find |
| 5044 | // anything existing, so it has no previous decl. Later, (still during the |
| 5045 | // import of the fwd friend decl) we start to import the definition again |
| 5046 | // and this time the lookup finds the previous fwd friend class template. |
| 5047 | // In this case we must set up the previous decl for the templated decl. |
| 5048 | if (!ToTemplated->getPreviousDecl()) { |
| 5049 | CXXRecordDecl *PrevTemplated = |
| 5050 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); |
| 5051 | if (ToTemplated != PrevTemplated) |
| 5052 | ToTemplated->setPreviousDecl(PrevTemplated); |
| 5053 | } |
| 5054 | |
| 5055 | D2->setPreviousDecl(Recent); |
| 5056 | } |
| 5057 | |
| 5058 | if (LexicalDC != DC && IsFriend) |
| 5059 | DC->makeDeclVisibleInContext(D2); |
| 5060 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5061 | if (FromTemplated->isCompleteDefinition() && |
| 5062 | !ToTemplated->isCompleteDefinition()) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5063 | // FIXME: Import definition! |
| 5064 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5065 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5066 | return D2; |
| 5067 | } |
| 5068 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5069 | ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5070 | ClassTemplateSpecializationDecl *D) { |
| 5071 | // If this record has a definition in the translation unit we're coming from, |
| 5072 | // but this particular declaration is not that definition, import the |
| 5073 | // definition and map to that. |
| 5074 | TagDecl *Definition = D->getDefinition(); |
| 5075 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5076 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 5077 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5078 | else |
| 5079 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5080 | } |
| 5081 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5082 | ClassTemplateDecl *ClassTemplate; |
| 5083 | if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate())) |
| 5084 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5085 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5086 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5087 | DeclContext *DC, *LexicalDC; |
| 5088 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5089 | return std::move(Err); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5090 | |
| 5091 | // Import template arguments. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5092 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5093 | if (Error Err = ImportTemplateArguments( |
| 5094 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5095 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5096 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5097 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5098 | void *InsertPos = nullptr; |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5099 | ClassTemplateSpecializationDecl *D2 = nullptr; |
| 5100 | ClassTemplatePartialSpecializationDecl *PartialSpec = |
| 5101 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D); |
| 5102 | if (PartialSpec) |
| 5103 | D2 = ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos); |
| 5104 | else |
| 5105 | D2 = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
| 5106 | ClassTemplateSpecializationDecl * const PrevDecl = D2; |
| 5107 | RecordDecl *FoundDef = D2 ? D2->getDefinition() : nullptr; |
| 5108 | if (FoundDef) { |
| 5109 | if (!D->isCompleteDefinition()) { |
| 5110 | // The "From" translation unit only had a forward declaration; call it |
| 5111 | // the same declaration. |
| 5112 | // TODO Handle the redecl chain properly! |
| 5113 | return Importer.MapImported(D, FoundDef); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5114 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5115 | |
| 5116 | if (IsStructuralMatch(D, FoundDef)) { |
| 5117 | |
| 5118 | Importer.MapImported(D, FoundDef); |
| 5119 | |
| 5120 | // Import those those default field initializers which have been |
| 5121 | // instantiated in the "From" context, but not in the "To" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5122 | for (auto *FromField : D->fields()) { |
| 5123 | auto ToOrErr = import(FromField); |
| 5124 | if (!ToOrErr) |
| 5125 | // FIXME: return the error? |
| 5126 | consumeError(ToOrErr.takeError()); |
| 5127 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5128 | |
| 5129 | // Import those methods which have been instantiated in the |
| 5130 | // "From" context, but not in the "To" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5131 | for (CXXMethodDecl *FromM : D->methods()) { |
| 5132 | auto ToOrErr = import(FromM); |
| 5133 | if (!ToOrErr) |
| 5134 | // FIXME: return the error? |
| 5135 | consumeError(ToOrErr.takeError()); |
| 5136 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5137 | |
| 5138 | // TODO Import instantiated default arguments. |
| 5139 | // TODO Import instantiated exception specifications. |
| 5140 | // |
| 5141 | // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint what |
| 5142 | // else could be fused during an AST merge. |
| 5143 | |
| 5144 | return FoundDef; |
| 5145 | } |
| 5146 | } else { // We either couldn't find any previous specialization in the "To" |
| 5147 | // context, or we found one but without definition. Let's create a |
| 5148 | // new specialization and register that at the class template. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5149 | |
| 5150 | // Import the location of this declaration. |
| 5151 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5152 | if (!BeginLocOrErr) |
| 5153 | return BeginLocOrErr.takeError(); |
| 5154 | ExpectedSLoc IdLocOrErr = import(D->getLocation()); |
| 5155 | if (!IdLocOrErr) |
| 5156 | return IdLocOrErr.takeError(); |
| 5157 | |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5158 | if (PartialSpec) { |
| 5159 | // Import TemplateArgumentListInfo. |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5160 | TemplateArgumentListInfo ToTAInfo; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5161 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5162 | if (Error Err = ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) |
| 5163 | return std::move(Err); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5164 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5165 | QualType CanonInjType; |
| 5166 | if (Error Err = importInto( |
| 5167 | CanonInjType, PartialSpec->getInjectedSpecializationType())) |
| 5168 | return std::move(Err); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5169 | CanonInjType = CanonInjType.getCanonicalType(); |
| 5170 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5171 | auto ToTPListOrErr = ImportTemplateParameterList( |
| 5172 | PartialSpec->getTemplateParameters()); |
| 5173 | if (!ToTPListOrErr) |
| 5174 | return ToTPListOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5175 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5176 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5177 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| 5178 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, ClassTemplate, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5179 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5180 | ToTAInfo, CanonInjType, |
| 5181 | cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl))) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5182 | return D2; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5183 | |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5184 | // Update InsertPos, because preceding import calls may have invalidated |
| 5185 | // it by adding new specializations. |
| 5186 | if (!ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos)) |
| 5187 | // Add this partial specialization to the class template. |
| 5188 | ClassTemplate->AddPartialSpecialization( |
| 5189 | cast<ClassTemplatePartialSpecializationDecl>(D2), InsertPos); |
| 5190 | |
| 5191 | } else { // Not a partial specialization. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5192 | if (GetImportedOrCreateDecl( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5193 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| 5194 | *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs, |
| 5195 | PrevDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5196 | return D2; |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5197 | |
| 5198 | // Update InsertPos, because preceding import calls may have invalidated |
| 5199 | // it by adding new specializations. |
| 5200 | if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos)) |
| 5201 | // Add this specialization to the class template. |
| 5202 | ClassTemplate->AddSpecialization(D2, InsertPos); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5203 | } |
| 5204 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5205 | D2->setSpecializationKind(D->getSpecializationKind()); |
| 5206 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5207 | // Import the qualifier, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5208 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5209 | D2->setQualifierInfo(*LocOrErr); |
| 5210 | else |
| 5211 | return LocOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5212 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5213 | if (auto *TSI = D->getTypeAsWritten()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5214 | if (auto TInfoOrErr = import(TSI)) |
| 5215 | D2->setTypeAsWritten(*TInfoOrErr); |
| 5216 | else |
| 5217 | return TInfoOrErr.takeError(); |
| 5218 | |
| 5219 | if (auto LocOrErr = import(D->getTemplateKeywordLoc())) |
| 5220 | D2->setTemplateKeywordLoc(*LocOrErr); |
| 5221 | else |
| 5222 | return LocOrErr.takeError(); |
| 5223 | |
| 5224 | if (auto LocOrErr = import(D->getExternLoc())) |
| 5225 | D2->setExternLoc(*LocOrErr); |
| 5226 | else |
| 5227 | return LocOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5228 | } |
| 5229 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5230 | if (D->getPointOfInstantiation().isValid()) { |
| 5231 | if (auto POIOrErr = import(D->getPointOfInstantiation())) |
| 5232 | D2->setPointOfInstantiation(*POIOrErr); |
| 5233 | else |
| 5234 | return POIOrErr.takeError(); |
| 5235 | } |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5236 | |
| 5237 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 5238 | |
Gabor Marton | b14056b | 2018-05-25 11:21:24 +0000 | [diff] [blame] | 5239 | // Set the context of this specialization/instantiation. |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5240 | D2->setLexicalDeclContext(LexicalDC); |
Gabor Marton | b14056b | 2018-05-25 11:21:24 +0000 | [diff] [blame] | 5241 | |
| 5242 | // Add to the DC only if it was an explicit specialization/instantiation. |
| 5243 | if (D2->isExplicitInstantiationOrSpecialization()) { |
| 5244 | LexicalDC->addDeclInternal(D2); |
| 5245 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5246 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5247 | if (D->isCompleteDefinition()) |
| 5248 | if (Error Err = ImportDefinition(D, D2)) |
| 5249 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5250 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5251 | return D2; |
| 5252 | } |
| 5253 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5254 | ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5255 | // If this variable has a definition in the translation unit we're coming |
| 5256 | // from, |
| 5257 | // but this particular declaration is not that definition, import the |
| 5258 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5259 | auto *Definition = |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5260 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); |
| 5261 | if (Definition && Definition != D->getTemplatedDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5262 | if (ExpectedDecl ImportedDefOrErr = import( |
| 5263 | Definition->getDescribedVarTemplate())) |
| 5264 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5265 | else |
| 5266 | return ImportedDefOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5267 | } |
| 5268 | |
| 5269 | // Import the major distinguishing characteristics of this variable template. |
| 5270 | DeclContext *DC, *LexicalDC; |
| 5271 | DeclarationName Name; |
| 5272 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5273 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5274 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5275 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5276 | if (ToD) |
| 5277 | return ToD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5278 | |
| 5279 | // We may already have a template of the same name; try to find and match it. |
| 5280 | assert(!DC->isFunctionOrMethod() && |
| 5281 | "Variable templates cannot be declared at function scope"); |
| 5282 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5283 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5284 | for (auto *FoundDecl : FoundDecls) { |
| 5285 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5286 | continue; |
| 5287 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5288 | Decl *Found = FoundDecl; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5289 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5290 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 5291 | // The variable templates structurally match; call it the same template. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5292 | Importer.MapImported(D->getTemplatedDecl(), |
| 5293 | FoundTemplate->getTemplatedDecl()); |
| 5294 | return Importer.MapImported(D, FoundTemplate); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5295 | } |
| 5296 | } |
| 5297 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5298 | ConflictingDecls.push_back(FoundDecl); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5299 | } |
| 5300 | |
| 5301 | if (!ConflictingDecls.empty()) { |
| 5302 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 5303 | ConflictingDecls.data(), |
| 5304 | ConflictingDecls.size()); |
| 5305 | } |
| 5306 | |
| 5307 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5308 | // FIXME: Is it possible to get other error than name conflict? |
| 5309 | // (Put this `if` into the previous `if`?) |
| 5310 | return make_error<ImportError>(ImportError::NameConflict); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5311 | |
| 5312 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 5313 | |
| 5314 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5315 | // FIXME: Value not used? |
| 5316 | ExpectedType TypeOrErr = import(DTemplated->getType()); |
| 5317 | if (!TypeOrErr) |
| 5318 | return TypeOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5319 | |
| 5320 | // Create the declaration that is being templated. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5321 | VarDecl *ToTemplated; |
| 5322 | if (Error Err = importInto(ToTemplated, DTemplated)) |
| 5323 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5324 | |
| 5325 | // Create the variable template declaration itself. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5326 | auto TemplateParamsOrErr = ImportTemplateParameterList( |
| 5327 | D->getTemplateParameters()); |
| 5328 | if (!TemplateParamsOrErr) |
| 5329 | return TemplateParamsOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5330 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5331 | VarTemplateDecl *ToVarTD; |
| 5332 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5333 | Name, *TemplateParamsOrErr, ToTemplated)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5334 | return ToVarTD; |
| 5335 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5336 | ToTemplated->setDescribedVarTemplate(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5337 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5338 | ToVarTD->setAccess(D->getAccess()); |
| 5339 | ToVarTD->setLexicalDeclContext(LexicalDC); |
| 5340 | LexicalDC->addDeclInternal(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5341 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5342 | if (DTemplated->isThisDeclarationADefinition() && |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5343 | !ToTemplated->isThisDeclarationADefinition()) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5344 | // FIXME: Import definition! |
| 5345 | } |
| 5346 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5347 | return ToVarTD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5348 | } |
| 5349 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5350 | ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5351 | VarTemplateSpecializationDecl *D) { |
| 5352 | // If this record has a definition in the translation unit we're coming from, |
| 5353 | // but this particular declaration is not that definition, import the |
| 5354 | // definition and map to that. |
| 5355 | VarDecl *Definition = D->getDefinition(); |
| 5356 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5357 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 5358 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5359 | else |
| 5360 | return ImportedDefOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5361 | } |
| 5362 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5363 | VarTemplateDecl *VarTemplate; |
| 5364 | if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate())) |
| 5365 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5366 | |
| 5367 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5368 | DeclContext *DC, *LexicalDC; |
| 5369 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5370 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5371 | |
| 5372 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5373 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5374 | if (!BeginLocOrErr) |
| 5375 | return BeginLocOrErr.takeError(); |
| 5376 | |
| 5377 | auto IdLocOrErr = import(D->getLocation()); |
| 5378 | if (!IdLocOrErr) |
| 5379 | return IdLocOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5380 | |
| 5381 | // Import template arguments. |
| 5382 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5383 | if (Error Err = ImportTemplateArguments( |
| 5384 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5385 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5386 | |
| 5387 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5388 | void *InsertPos = nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5389 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 5390 | TemplateArgs, InsertPos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5391 | if (D2) { |
| 5392 | // We already have a variable template specialization with these template |
| 5393 | // arguments. |
| 5394 | |
| 5395 | // FIXME: Check for specialization vs. instantiation errors. |
| 5396 | |
| 5397 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 5398 | if (!D->isThisDeclarationADefinition() || |
| 5399 | IsStructuralMatch(D, FoundDef)) { |
| 5400 | // The record types structurally match, or the "from" translation |
| 5401 | // unit only had a forward declaration anyway; call it the same |
| 5402 | // variable. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5403 | return Importer.MapImported(D, FoundDef); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5404 | } |
| 5405 | } |
| 5406 | } else { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5407 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5408 | QualType T; |
| 5409 | if (Error Err = importInto(T, D->getType())) |
| 5410 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5411 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5412 | auto TInfoOrErr = import(D->getTypeSourceInfo()); |
| 5413 | if (!TInfoOrErr) |
| 5414 | return TInfoOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5415 | |
| 5416 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5417 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5418 | D->getTemplateArgsInfo(), ToTAInfo)) |
| 5419 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5420 | |
| 5421 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5422 | // Create a new specialization. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5423 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { |
| 5424 | // Import TemplateArgumentListInfo |
| 5425 | TemplateArgumentListInfo ArgInfos; |
| 5426 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); |
| 5427 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5428 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5429 | *FromTAArgsAsWritten, ArgInfos)) |
| 5430 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5431 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5432 | auto ToTPListOrErr = ImportTemplateParameterList( |
| 5433 | FromPartial->getTemplateParameters()); |
| 5434 | if (!ToTPListOrErr) |
| 5435 | return ToTPListOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5436 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5437 | PartVarSpecDecl *ToPartial; |
| 5438 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5439 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, |
| 5440 | VarTemplate, T, *TInfoOrErr, |
| 5441 | D->getStorageClass(), TemplateArgs, ArgInfos)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5442 | return ToPartial; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5443 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5444 | if (Expected<PartVarSpecDecl *> ToInstOrErr = import( |
| 5445 | FromPartial->getInstantiatedFromMember())) |
| 5446 | ToPartial->setInstantiatedFromMember(*ToInstOrErr); |
| 5447 | else |
| 5448 | return ToInstOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5449 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5450 | if (FromPartial->isMemberSpecialization()) |
| 5451 | ToPartial->setMemberSpecialization(); |
| 5452 | |
| 5453 | D2 = ToPartial; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5454 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5455 | } else { // Full specialization |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5456 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, |
| 5457 | *BeginLocOrErr, *IdLocOrErr, VarTemplate, |
| 5458 | T, *TInfoOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5459 | D->getStorageClass(), TemplateArgs)) |
| 5460 | return D2; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5461 | } |
| 5462 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5463 | if (D->getPointOfInstantiation().isValid()) { |
| 5464 | if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation())) |
| 5465 | D2->setPointOfInstantiation(*POIOrErr); |
| 5466 | else |
| 5467 | return POIOrErr.takeError(); |
| 5468 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5469 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5470 | D2->setSpecializationKind(D->getSpecializationKind()); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5471 | D2->setTemplateArgsInfo(ToTAInfo); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5472 | |
| 5473 | // Add this specialization to the class template. |
| 5474 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 5475 | |
| 5476 | // Import the qualifier, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5477 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5478 | D2->setQualifierInfo(*LocOrErr); |
| 5479 | else |
| 5480 | return LocOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5481 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5482 | if (D->isConstexpr()) |
| 5483 | D2->setConstexpr(true); |
| 5484 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5485 | // Add the specialization to this context. |
| 5486 | D2->setLexicalDeclContext(LexicalDC); |
| 5487 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5488 | |
| 5489 | D2->setAccess(D->getAccess()); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5490 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5491 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5492 | if (Error Err = ImportInitializer(D, D2)) |
| 5493 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5494 | |
| 5495 | return D2; |
| 5496 | } |
| 5497 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5498 | ExpectedDecl |
| 5499 | ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5500 | DeclContext *DC, *LexicalDC; |
| 5501 | DeclarationName Name; |
| 5502 | SourceLocation Loc; |
| 5503 | NamedDecl *ToD; |
| 5504 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5505 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5506 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5507 | |
| 5508 | if (ToD) |
| 5509 | return ToD; |
| 5510 | |
| 5511 | // Try to find a function in our own ("to") context with the same name, same |
| 5512 | // type, and in the same context as the function we're importing. |
| 5513 | if (!LexicalDC->isFunctionOrMethod()) { |
Gabor Marton | e331e63 | 2019-02-18 13:09:27 +0000 | [diff] [blame] | 5514 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5515 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5516 | for (auto *FoundDecl : FoundDecls) { |
| 5517 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5518 | continue; |
| 5519 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5520 | if (auto *FoundFunction = |
| 5521 | dyn_cast<FunctionTemplateDecl>(FoundDecl)) { |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5522 | if (FoundFunction->hasExternalFormalLinkage() && |
| 5523 | D->hasExternalFormalLinkage()) { |
| 5524 | if (IsStructuralMatch(D, FoundFunction)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5525 | Importer.MapImported(D, FoundFunction); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5526 | // FIXME: Actually try to merge the body and other attributes. |
| 5527 | return FoundFunction; |
| 5528 | } |
| 5529 | } |
| 5530 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5531 | // TODO: handle conflicting names |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5532 | } |
| 5533 | } |
| 5534 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5535 | auto ParamsOrErr = ImportTemplateParameterList( |
| 5536 | D->getTemplateParameters()); |
| 5537 | if (!ParamsOrErr) |
| 5538 | return ParamsOrErr.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5539 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5540 | FunctionDecl *TemplatedFD; |
| 5541 | if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl())) |
| 5542 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5543 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5544 | FunctionTemplateDecl *ToFunc; |
| 5545 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5546 | *ParamsOrErr, TemplatedFD)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5547 | return ToFunc; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5548 | |
| 5549 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); |
| 5550 | ToFunc->setAccess(D->getAccess()); |
| 5551 | ToFunc->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5552 | |
| 5553 | LexicalDC->addDeclInternal(ToFunc); |
| 5554 | return ToFunc; |
| 5555 | } |
| 5556 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5557 | //---------------------------------------------------------------------------- |
| 5558 | // Import Statements |
| 5559 | //---------------------------------------------------------------------------- |
| 5560 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5561 | ExpectedStmt ASTNodeImporter::VisitStmt(Stmt *S) { |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5562 | Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node) |
| 5563 | << S->getStmtClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5564 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5565 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5566 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5567 | |
| 5568 | ExpectedStmt ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5569 | SmallVector<IdentifierInfo *, 4> Names; |
| 5570 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 5571 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5572 | // ToII is nullptr when no symbolic name is given for output operand |
| 5573 | // see ParseStmtAsm::ParseAsmOperandsOpt |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5574 | Names.push_back(ToII); |
| 5575 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5576 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5577 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 5578 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5579 | // ToII is nullptr when no symbolic name is given for input operand |
| 5580 | // see ParseStmtAsm::ParseAsmOperandsOpt |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5581 | Names.push_back(ToII); |
| 5582 | } |
| 5583 | |
| 5584 | SmallVector<StringLiteral *, 4> Clobbers; |
| 5585 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5586 | if (auto ClobberOrErr = import(S->getClobberStringLiteral(I))) |
| 5587 | Clobbers.push_back(*ClobberOrErr); |
| 5588 | else |
| 5589 | return ClobberOrErr.takeError(); |
| 5590 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5591 | } |
| 5592 | |
| 5593 | SmallVector<StringLiteral *, 4> Constraints; |
| 5594 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5595 | if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I))) |
| 5596 | Constraints.push_back(*OutputOrErr); |
| 5597 | else |
| 5598 | return OutputOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5599 | } |
| 5600 | |
| 5601 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5602 | if (auto InputOrErr = import(S->getInputConstraintLiteral(I))) |
| 5603 | Constraints.push_back(*InputOrErr); |
| 5604 | else |
| 5605 | return InputOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5606 | } |
| 5607 | |
| 5608 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5609 | if (Error Err = ImportContainerChecked(S->outputs(), Exprs)) |
| 5610 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5611 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5612 | if (Error Err = ImportArrayChecked( |
| 5613 | S->inputs(), Exprs.begin() + S->getNumOutputs())) |
| 5614 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5615 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5616 | ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc()); |
| 5617 | if (!AsmLocOrErr) |
| 5618 | return AsmLocOrErr.takeError(); |
| 5619 | auto AsmStrOrErr = import(S->getAsmString()); |
| 5620 | if (!AsmStrOrErr) |
| 5621 | return AsmStrOrErr.takeError(); |
| 5622 | ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc()); |
| 5623 | if (!RParenLocOrErr) |
| 5624 | return RParenLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5625 | |
| 5626 | return new (Importer.getToContext()) GCCAsmStmt( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5627 | Importer.getToContext(), |
| 5628 | *AsmLocOrErr, |
| 5629 | S->isSimple(), |
| 5630 | S->isVolatile(), |
| 5631 | S->getNumOutputs(), |
| 5632 | S->getNumInputs(), |
| 5633 | Names.data(), |
| 5634 | Constraints.data(), |
| 5635 | Exprs.data(), |
| 5636 | *AsmStrOrErr, |
| 5637 | S->getNumClobbers(), |
| 5638 | Clobbers.data(), |
| 5639 | *RParenLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5640 | } |
| 5641 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5642 | ExpectedStmt ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| 5643 | auto Imp = importSeq(S->getDeclGroup(), S->getBeginLoc(), S->getEndLoc()); |
| 5644 | if (!Imp) |
| 5645 | return Imp.takeError(); |
| 5646 | |
| 5647 | DeclGroupRef ToDG; |
| 5648 | SourceLocation ToBeginLoc, ToEndLoc; |
| 5649 | std::tie(ToDG, ToBeginLoc, ToEndLoc) = *Imp; |
| 5650 | |
| 5651 | return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5652 | } |
| 5653 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5654 | ExpectedStmt ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 5655 | ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc()); |
| 5656 | if (!ToSemiLocOrErr) |
| 5657 | return ToSemiLocOrErr.takeError(); |
| 5658 | return new (Importer.getToContext()) NullStmt( |
| 5659 | *ToSemiLocOrErr, S->hasLeadingEmptyMacro()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5660 | } |
| 5661 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5662 | ExpectedStmt ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5663 | SmallVector<Stmt *, 8> ToStmts(S->size()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5664 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5665 | if (Error Err = ImportContainerChecked(S->body(), ToStmts)) |
| 5666 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5667 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5668 | ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc()); |
| 5669 | if (!ToLBracLocOrErr) |
| 5670 | return ToLBracLocOrErr.takeError(); |
| 5671 | |
| 5672 | ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc()); |
| 5673 | if (!ToRBracLocOrErr) |
| 5674 | return ToRBracLocOrErr.takeError(); |
| 5675 | |
| 5676 | return CompoundStmt::Create( |
| 5677 | Importer.getToContext(), ToStmts, |
| 5678 | *ToLBracLocOrErr, *ToRBracLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5679 | } |
| 5680 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5681 | ExpectedStmt ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| 5682 | auto Imp = importSeq( |
| 5683 | S->getLHS(), S->getRHS(), S->getSubStmt(), S->getCaseLoc(), |
| 5684 | S->getEllipsisLoc(), S->getColonLoc()); |
| 5685 | if (!Imp) |
| 5686 | return Imp.takeError(); |
| 5687 | |
| 5688 | Expr *ToLHS, *ToRHS; |
| 5689 | Stmt *ToSubStmt; |
| 5690 | SourceLocation ToCaseLoc, ToEllipsisLoc, ToColonLoc; |
| 5691 | std::tie(ToLHS, ToRHS, ToSubStmt, ToCaseLoc, ToEllipsisLoc, ToColonLoc) = |
| 5692 | *Imp; |
| 5693 | |
Bruno Ricci | 5b3057175 | 2018-10-28 12:30:53 +0000 | [diff] [blame] | 5694 | auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS, |
| 5695 | ToCaseLoc, ToEllipsisLoc, ToColonLoc); |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5696 | ToStmt->setSubStmt(ToSubStmt); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5697 | |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5698 | return ToStmt; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5699 | } |
| 5700 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5701 | ExpectedStmt ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| 5702 | auto Imp = importSeq(S->getDefaultLoc(), S->getColonLoc(), S->getSubStmt()); |
| 5703 | if (!Imp) |
| 5704 | return Imp.takeError(); |
| 5705 | |
| 5706 | SourceLocation ToDefaultLoc, ToColonLoc; |
| 5707 | Stmt *ToSubStmt; |
| 5708 | std::tie(ToDefaultLoc, ToColonLoc, ToSubStmt) = *Imp; |
| 5709 | |
| 5710 | return new (Importer.getToContext()) DefaultStmt( |
| 5711 | ToDefaultLoc, ToColonLoc, ToSubStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5712 | } |
| 5713 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5714 | ExpectedStmt ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| 5715 | auto Imp = importSeq(S->getIdentLoc(), S->getDecl(), S->getSubStmt()); |
| 5716 | if (!Imp) |
| 5717 | return Imp.takeError(); |
| 5718 | |
| 5719 | SourceLocation ToIdentLoc; |
| 5720 | LabelDecl *ToLabelDecl; |
| 5721 | Stmt *ToSubStmt; |
| 5722 | std::tie(ToIdentLoc, ToLabelDecl, ToSubStmt) = *Imp; |
| 5723 | |
| 5724 | return new (Importer.getToContext()) LabelStmt( |
| 5725 | ToIdentLoc, ToLabelDecl, ToSubStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5726 | } |
| 5727 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5728 | ExpectedStmt ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { |
| 5729 | ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc()); |
| 5730 | if (!ToAttrLocOrErr) |
| 5731 | return ToAttrLocOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5732 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 5733 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5734 | if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs)) |
| 5735 | return std::move(Err); |
| 5736 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 5737 | if (!ToSubStmtOrErr) |
| 5738 | return ToSubStmtOrErr.takeError(); |
| 5739 | |
| 5740 | return AttributedStmt::Create( |
| 5741 | Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5742 | } |
| 5743 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5744 | ExpectedStmt ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| 5745 | auto Imp = importSeq( |
| 5746 | S->getIfLoc(), S->getInit(), S->getConditionVariable(), S->getCond(), |
| 5747 | S->getThen(), S->getElseLoc(), S->getElse()); |
| 5748 | if (!Imp) |
| 5749 | return Imp.takeError(); |
| 5750 | |
| 5751 | SourceLocation ToIfLoc, ToElseLoc; |
| 5752 | Stmt *ToInit, *ToThen, *ToElse; |
| 5753 | VarDecl *ToConditionVariable; |
| 5754 | Expr *ToCond; |
| 5755 | std::tie( |
| 5756 | ToIfLoc, ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, ToElse) = |
| 5757 | *Imp; |
| 5758 | |
Bruno Ricci | b1cc94b | 2018-10-27 21:12:20 +0000 | [diff] [blame] | 5759 | return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->isConstexpr(), |
| 5760 | ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, |
| 5761 | ToElse); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5762 | } |
| 5763 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5764 | ExpectedStmt ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
| 5765 | auto Imp = importSeq( |
| 5766 | S->getInit(), S->getConditionVariable(), S->getCond(), |
| 5767 | S->getBody(), S->getSwitchLoc()); |
| 5768 | if (!Imp) |
| 5769 | return Imp.takeError(); |
| 5770 | |
| 5771 | Stmt *ToInit, *ToBody; |
| 5772 | VarDecl *ToConditionVariable; |
| 5773 | Expr *ToCond; |
| 5774 | SourceLocation ToSwitchLoc; |
| 5775 | std::tie(ToInit, ToConditionVariable, ToCond, ToBody, ToSwitchLoc) = *Imp; |
| 5776 | |
Bruno Ricci | e2806f8 | 2018-10-29 16:12:37 +0000 | [diff] [blame] | 5777 | auto *ToStmt = SwitchStmt::Create(Importer.getToContext(), ToInit, |
| 5778 | ToConditionVariable, ToCond); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5779 | ToStmt->setBody(ToBody); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5780 | ToStmt->setSwitchLoc(ToSwitchLoc); |
| 5781 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5782 | // Now we have to re-chain the cases. |
| 5783 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 5784 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 5785 | SC = SC->getNextSwitchCase()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5786 | Expected<SwitchCase *> ToSCOrErr = import(SC); |
| 5787 | if (!ToSCOrErr) |
| 5788 | return ToSCOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5789 | if (LastChainedSwitchCase) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5790 | LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5791 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5792 | ToStmt->setSwitchCaseList(*ToSCOrErr); |
| 5793 | LastChainedSwitchCase = *ToSCOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5794 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5795 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5796 | return ToStmt; |
| 5797 | } |
| 5798 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5799 | ExpectedStmt ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| 5800 | auto Imp = importSeq( |
| 5801 | S->getConditionVariable(), S->getCond(), S->getBody(), S->getWhileLoc()); |
| 5802 | if (!Imp) |
| 5803 | return Imp.takeError(); |
| 5804 | |
| 5805 | VarDecl *ToConditionVariable; |
| 5806 | Expr *ToCond; |
| 5807 | Stmt *ToBody; |
| 5808 | SourceLocation ToWhileLoc; |
| 5809 | std::tie(ToConditionVariable, ToCond, ToBody, ToWhileLoc) = *Imp; |
| 5810 | |
Bruno Ricci | bacf751 | 2018-10-30 13:42:41 +0000 | [diff] [blame] | 5811 | return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond, |
| 5812 | ToBody, ToWhileLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5813 | } |
| 5814 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5815 | ExpectedStmt ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| 5816 | auto Imp = importSeq( |
| 5817 | S->getBody(), S->getCond(), S->getDoLoc(), S->getWhileLoc(), |
| 5818 | S->getRParenLoc()); |
| 5819 | if (!Imp) |
| 5820 | return Imp.takeError(); |
| 5821 | |
| 5822 | Stmt *ToBody; |
| 5823 | Expr *ToCond; |
| 5824 | SourceLocation ToDoLoc, ToWhileLoc, ToRParenLoc; |
| 5825 | std::tie(ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc) = *Imp; |
| 5826 | |
| 5827 | return new (Importer.getToContext()) DoStmt( |
| 5828 | ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5829 | } |
| 5830 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5831 | ExpectedStmt ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| 5832 | auto Imp = importSeq( |
| 5833 | S->getInit(), S->getCond(), S->getConditionVariable(), S->getInc(), |
| 5834 | S->getBody(), S->getForLoc(), S->getLParenLoc(), S->getRParenLoc()); |
| 5835 | if (!Imp) |
| 5836 | return Imp.takeError(); |
| 5837 | |
| 5838 | Stmt *ToInit; |
| 5839 | Expr *ToCond, *ToInc; |
| 5840 | VarDecl *ToConditionVariable; |
| 5841 | Stmt *ToBody; |
| 5842 | SourceLocation ToForLoc, ToLParenLoc, ToRParenLoc; |
| 5843 | std::tie( |
| 5844 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, |
| 5845 | ToLParenLoc, ToRParenLoc) = *Imp; |
| 5846 | |
| 5847 | return new (Importer.getToContext()) ForStmt( |
| 5848 | Importer.getToContext(), |
| 5849 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc, |
| 5850 | ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5851 | } |
| 5852 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5853 | ExpectedStmt ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| 5854 | auto Imp = importSeq(S->getLabel(), S->getGotoLoc(), S->getLabelLoc()); |
| 5855 | if (!Imp) |
| 5856 | return Imp.takeError(); |
| 5857 | |
| 5858 | LabelDecl *ToLabel; |
| 5859 | SourceLocation ToGotoLoc, ToLabelLoc; |
| 5860 | std::tie(ToLabel, ToGotoLoc, ToLabelLoc) = *Imp; |
| 5861 | |
| 5862 | return new (Importer.getToContext()) GotoStmt( |
| 5863 | ToLabel, ToGotoLoc, ToLabelLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5864 | } |
| 5865 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5866 | ExpectedStmt ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 5867 | auto Imp = importSeq(S->getGotoLoc(), S->getStarLoc(), S->getTarget()); |
| 5868 | if (!Imp) |
| 5869 | return Imp.takeError(); |
| 5870 | |
| 5871 | SourceLocation ToGotoLoc, ToStarLoc; |
| 5872 | Expr *ToTarget; |
| 5873 | std::tie(ToGotoLoc, ToStarLoc, ToTarget) = *Imp; |
| 5874 | |
| 5875 | return new (Importer.getToContext()) IndirectGotoStmt( |
| 5876 | ToGotoLoc, ToStarLoc, ToTarget); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5877 | } |
| 5878 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5879 | ExpectedStmt ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 5880 | ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc()); |
| 5881 | if (!ToContinueLocOrErr) |
| 5882 | return ToContinueLocOrErr.takeError(); |
| 5883 | return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5884 | } |
| 5885 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5886 | ExpectedStmt ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 5887 | auto ToBreakLocOrErr = import(S->getBreakLoc()); |
| 5888 | if (!ToBreakLocOrErr) |
| 5889 | return ToBreakLocOrErr.takeError(); |
| 5890 | return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5891 | } |
| 5892 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5893 | ExpectedStmt ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| 5894 | auto Imp = importSeq( |
| 5895 | S->getReturnLoc(), S->getRetValue(), S->getNRVOCandidate()); |
| 5896 | if (!Imp) |
| 5897 | return Imp.takeError(); |
| 5898 | |
| 5899 | SourceLocation ToReturnLoc; |
| 5900 | Expr *ToRetValue; |
| 5901 | const VarDecl *ToNRVOCandidate; |
| 5902 | std::tie(ToReturnLoc, ToRetValue, ToNRVOCandidate) = *Imp; |
| 5903 | |
Bruno Ricci | 023b1d1 | 2018-10-30 14:40:49 +0000 | [diff] [blame] | 5904 | return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue, |
| 5905 | ToNRVOCandidate); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5906 | } |
| 5907 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5908 | ExpectedStmt ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| 5909 | auto Imp = importSeq( |
| 5910 | S->getCatchLoc(), S->getExceptionDecl(), S->getHandlerBlock()); |
| 5911 | if (!Imp) |
| 5912 | return Imp.takeError(); |
| 5913 | |
| 5914 | SourceLocation ToCatchLoc; |
| 5915 | VarDecl *ToExceptionDecl; |
| 5916 | Stmt *ToHandlerBlock; |
| 5917 | std::tie(ToCatchLoc, ToExceptionDecl, ToHandlerBlock) = *Imp; |
| 5918 | |
| 5919 | return new (Importer.getToContext()) CXXCatchStmt ( |
| 5920 | ToCatchLoc, ToExceptionDecl, ToHandlerBlock); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5921 | } |
| 5922 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5923 | ExpectedStmt ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 5924 | ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc()); |
| 5925 | if (!ToTryLocOrErr) |
| 5926 | return ToTryLocOrErr.takeError(); |
| 5927 | |
| 5928 | ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock()); |
| 5929 | if (!ToTryBlockOrErr) |
| 5930 | return ToTryBlockOrErr.takeError(); |
| 5931 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5932 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 5933 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 5934 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5935 | if (auto ToHandlerOrErr = import(FromHandler)) |
| 5936 | ToHandlers[HI] = *ToHandlerOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5937 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5938 | return ToHandlerOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5939 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5940 | |
| 5941 | return CXXTryStmt::Create( |
| 5942 | Importer.getToContext(), *ToTryLocOrErr,*ToTryBlockOrErr, ToHandlers); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5943 | } |
| 5944 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5945 | ExpectedStmt ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
| 5946 | auto Imp1 = importSeq( |
| 5947 | S->getInit(), S->getRangeStmt(), S->getBeginStmt(), S->getEndStmt(), |
| 5948 | S->getCond(), S->getInc(), S->getLoopVarStmt(), S->getBody()); |
| 5949 | if (!Imp1) |
| 5950 | return Imp1.takeError(); |
| 5951 | auto Imp2 = importSeq( |
| 5952 | S->getForLoc(), S->getCoawaitLoc(), S->getColonLoc(), S->getRParenLoc()); |
| 5953 | if (!Imp2) |
| 5954 | return Imp2.takeError(); |
| 5955 | |
| 5956 | DeclStmt *ToRangeStmt, *ToBeginStmt, *ToEndStmt, *ToLoopVarStmt; |
| 5957 | Expr *ToCond, *ToInc; |
| 5958 | Stmt *ToInit, *ToBody; |
| 5959 | std::tie( |
| 5960 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 5961 | ToBody) = *Imp1; |
| 5962 | SourceLocation ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc; |
| 5963 | std::tie(ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc) = *Imp2; |
| 5964 | |
| 5965 | return new (Importer.getToContext()) CXXForRangeStmt( |
| 5966 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 5967 | ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5968 | } |
| 5969 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5970 | ExpectedStmt |
| 5971 | ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 5972 | auto Imp = importSeq( |
| 5973 | S->getElement(), S->getCollection(), S->getBody(), |
| 5974 | S->getForLoc(), S->getRParenLoc()); |
| 5975 | if (!Imp) |
| 5976 | return Imp.takeError(); |
| 5977 | |
| 5978 | Stmt *ToElement, *ToBody; |
| 5979 | Expr *ToCollection; |
| 5980 | SourceLocation ToForLoc, ToRParenLoc; |
| 5981 | std::tie(ToElement, ToCollection, ToBody, ToForLoc, ToRParenLoc) = *Imp; |
| 5982 | |
| 5983 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement, |
| 5984 | ToCollection, |
| 5985 | ToBody, |
| 5986 | ToForLoc, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5987 | ToRParenLoc); |
| 5988 | } |
| 5989 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5990 | ExpectedStmt ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 5991 | auto Imp = importSeq( |
| 5992 | S->getAtCatchLoc(), S->getRParenLoc(), S->getCatchParamDecl(), |
| 5993 | S->getCatchBody()); |
| 5994 | if (!Imp) |
| 5995 | return Imp.takeError(); |
| 5996 | |
| 5997 | SourceLocation ToAtCatchLoc, ToRParenLoc; |
| 5998 | VarDecl *ToCatchParamDecl; |
| 5999 | Stmt *ToCatchBody; |
| 6000 | std::tie(ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody) = *Imp; |
| 6001 | |
| 6002 | return new (Importer.getToContext()) ObjCAtCatchStmt ( |
| 6003 | ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6004 | } |
| 6005 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6006 | ExpectedStmt ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 6007 | ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc()); |
| 6008 | if (!ToAtFinallyLocOrErr) |
| 6009 | return ToAtFinallyLocOrErr.takeError(); |
| 6010 | ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody()); |
| 6011 | if (!ToAtFinallyStmtOrErr) |
| 6012 | return ToAtFinallyStmtOrErr.takeError(); |
| 6013 | return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr, |
| 6014 | *ToAtFinallyStmtOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6015 | } |
| 6016 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6017 | ExpectedStmt ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 6018 | auto Imp = importSeq( |
| 6019 | S->getAtTryLoc(), S->getTryBody(), S->getFinallyStmt()); |
| 6020 | if (!Imp) |
| 6021 | return Imp.takeError(); |
| 6022 | |
| 6023 | SourceLocation ToAtTryLoc; |
| 6024 | Stmt *ToTryBody, *ToFinallyStmt; |
| 6025 | std::tie(ToAtTryLoc, ToTryBody, ToFinallyStmt) = *Imp; |
| 6026 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6027 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 6028 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 6029 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6030 | if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt)) |
| 6031 | ToCatchStmts[CI] = *ToCatchStmtOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6032 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6033 | return ToCatchStmtOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6034 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6035 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6036 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6037 | ToAtTryLoc, ToTryBody, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6038 | ToCatchStmts.begin(), ToCatchStmts.size(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6039 | ToFinallyStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6040 | } |
| 6041 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6042 | ExpectedStmt ASTNodeImporter::VisitObjCAtSynchronizedStmt |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6043 | (ObjCAtSynchronizedStmt *S) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6044 | auto Imp = importSeq( |
| 6045 | S->getAtSynchronizedLoc(), S->getSynchExpr(), S->getSynchBody()); |
| 6046 | if (!Imp) |
| 6047 | return Imp.takeError(); |
| 6048 | |
| 6049 | SourceLocation ToAtSynchronizedLoc; |
| 6050 | Expr *ToSynchExpr; |
| 6051 | Stmt *ToSynchBody; |
| 6052 | std::tie(ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody) = *Imp; |
| 6053 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6054 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 6055 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 6056 | } |
| 6057 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6058 | ExpectedStmt ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 6059 | ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc()); |
| 6060 | if (!ToThrowLocOrErr) |
| 6061 | return ToThrowLocOrErr.takeError(); |
| 6062 | ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr()); |
| 6063 | if (!ToThrowExprOrErr) |
| 6064 | return ToThrowExprOrErr.takeError(); |
| 6065 | return new (Importer.getToContext()) ObjCAtThrowStmt( |
| 6066 | *ToThrowLocOrErr, *ToThrowExprOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6067 | } |
| 6068 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6069 | ExpectedStmt ASTNodeImporter::VisitObjCAutoreleasePoolStmt( |
| 6070 | ObjCAutoreleasePoolStmt *S) { |
| 6071 | ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc()); |
| 6072 | if (!ToAtLocOrErr) |
| 6073 | return ToAtLocOrErr.takeError(); |
| 6074 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 6075 | if (!ToSubStmtOrErr) |
| 6076 | return ToSubStmtOrErr.takeError(); |
| 6077 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr, |
| 6078 | *ToSubStmtOrErr); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6079 | } |
| 6080 | |
| 6081 | //---------------------------------------------------------------------------- |
| 6082 | // Import Expressions |
| 6083 | //---------------------------------------------------------------------------- |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6084 | ExpectedStmt ASTNodeImporter::VisitExpr(Expr *E) { |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6085 | Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node) |
| 6086 | << E->getStmtClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6087 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6088 | } |
| 6089 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6090 | ExpectedStmt ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| 6091 | auto Imp = importSeq( |
| 6092 | E->getBuiltinLoc(), E->getSubExpr(), E->getWrittenTypeInfo(), |
| 6093 | E->getRParenLoc(), E->getType()); |
| 6094 | if (!Imp) |
| 6095 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6096 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6097 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6098 | Expr *ToSubExpr; |
| 6099 | TypeSourceInfo *ToWrittenTypeInfo; |
| 6100 | QualType ToType; |
| 6101 | std::tie(ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType) = |
| 6102 | *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6103 | |
| 6104 | return new (Importer.getToContext()) VAArgExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6105 | ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType, |
| 6106 | E->isMicrosoftABI()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6107 | } |
| 6108 | |
Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 6109 | ExpectedStmt ASTNodeImporter::VisitChooseExpr(ChooseExpr *E) { |
| 6110 | auto Imp = importSeq(E->getCond(), E->getLHS(), E->getRHS(), |
| 6111 | E->getBuiltinLoc(), E->getRParenLoc(), E->getType()); |
| 6112 | if (!Imp) |
| 6113 | return Imp.takeError(); |
| 6114 | |
| 6115 | Expr *ToCond; |
| 6116 | Expr *ToLHS; |
| 6117 | Expr *ToRHS; |
| 6118 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6119 | QualType ToType; |
| 6120 | std::tie(ToCond, ToLHS, ToRHS, ToBuiltinLoc, ToRParenLoc, ToType) = *Imp; |
| 6121 | |
| 6122 | ExprValueKind VK = E->getValueKind(); |
| 6123 | ExprObjectKind OK = E->getObjectKind(); |
| 6124 | |
| 6125 | bool TypeDependent = ToCond->isTypeDependent(); |
| 6126 | bool ValueDependent = ToCond->isValueDependent(); |
| 6127 | |
| 6128 | // The value of CondIsTrue only matters if the value is not |
| 6129 | // condition-dependent. |
| 6130 | bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue(); |
| 6131 | |
| 6132 | return new (Importer.getToContext()) |
| 6133 | ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK, |
| 6134 | ToRParenLoc, CondIsTrue, TypeDependent, ValueDependent); |
| 6135 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6136 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6137 | ExpectedStmt ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 6138 | ExpectedType TypeOrErr = import(E->getType()); |
| 6139 | if (!TypeOrErr) |
| 6140 | return TypeOrErr.takeError(); |
| 6141 | |
| 6142 | ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc()); |
| 6143 | if (!BeginLocOrErr) |
| 6144 | return BeginLocOrErr.takeError(); |
| 6145 | |
| 6146 | return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6147 | } |
| 6148 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6149 | ExpectedStmt ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { |
| 6150 | auto Imp = importSeq( |
| 6151 | E->getBeginLoc(), E->getType(), E->getFunctionName()); |
| 6152 | if (!Imp) |
| 6153 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6154 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6155 | SourceLocation ToBeginLoc; |
| 6156 | QualType ToType; |
| 6157 | StringLiteral *ToFunctionName; |
| 6158 | std::tie(ToBeginLoc, ToType, ToFunctionName) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6159 | |
Bruno Ricci | 17ff026 | 2018-10-27 19:21:19 +0000 | [diff] [blame] | 6160 | return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType, |
| 6161 | E->getIdentKind(), ToFunctionName); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6162 | } |
| 6163 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6164 | ExpectedStmt ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
| 6165 | auto Imp = importSeq( |
| 6166 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDecl(), |
| 6167 | E->getLocation(), E->getType()); |
| 6168 | if (!Imp) |
| 6169 | return Imp.takeError(); |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6170 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6171 | NestedNameSpecifierLoc ToQualifierLoc; |
| 6172 | SourceLocation ToTemplateKeywordLoc, ToLocation; |
| 6173 | ValueDecl *ToDecl; |
| 6174 | QualType ToType; |
| 6175 | std::tie(ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, ToLocation, ToType) = |
| 6176 | *Imp; |
| 6177 | |
| 6178 | NamedDecl *ToFoundD = nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6179 | if (E->getDecl() != E->getFoundDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6180 | auto FoundDOrErr = import(E->getFoundDecl()); |
| 6181 | if (!FoundDOrErr) |
| 6182 | return FoundDOrErr.takeError(); |
| 6183 | ToFoundD = *FoundDOrErr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6184 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6185 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6186 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6187 | TemplateArgumentListInfo *ToResInfo = nullptr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6188 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6189 | if (Error Err = |
| 6190 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 6191 | return std::move(Err); |
| 6192 | ToResInfo = &ToTAInfo; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6193 | } |
| 6194 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6195 | auto *ToE = DeclRefExpr::Create( |
| 6196 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, |
| 6197 | E->refersToEnclosingVariableOrCapture(), ToLocation, ToType, |
| 6198 | E->getValueKind(), ToFoundD, ToResInfo); |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 6199 | if (E->hadMultipleCandidates()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6200 | ToE->setHadMultipleCandidates(true); |
| 6201 | return ToE; |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 6202 | } |
| 6203 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6204 | ExpectedStmt ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 6205 | ExpectedType TypeOrErr = import(E->getType()); |
| 6206 | if (!TypeOrErr) |
| 6207 | return TypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6208 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6209 | return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6210 | } |
| 6211 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6212 | ExpectedStmt ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { |
| 6213 | ExpectedExpr ToInitOrErr = import(E->getInit()); |
| 6214 | if (!ToInitOrErr) |
| 6215 | return ToInitOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6216 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6217 | ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc()); |
| 6218 | if (!ToEqualOrColonLocOrErr) |
| 6219 | return ToEqualOrColonLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6220 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6221 | SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6222 | // List elements from the second, the first is Init itself |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6223 | for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) { |
| 6224 | if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I))) |
| 6225 | ToIndexExprs[I - 1] = *ToArgOrErr; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6226 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6227 | return ToArgOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6228 | } |
| 6229 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6230 | SmallVector<Designator, 4> ToDesignators(E->size()); |
| 6231 | if (Error Err = ImportContainerChecked(E->designators(), ToDesignators)) |
| 6232 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6233 | |
| 6234 | return DesignatedInitExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6235 | Importer.getToContext(), ToDesignators, |
| 6236 | ToIndexExprs, *ToEqualOrColonLocOrErr, |
| 6237 | E->usesGNUSyntax(), *ToInitOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6238 | } |
| 6239 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6240 | ExpectedStmt |
| 6241 | ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 6242 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6243 | if (!ToTypeOrErr) |
| 6244 | return ToTypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6245 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6246 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6247 | if (!ToLocationOrErr) |
| 6248 | return ToLocationOrErr.takeError(); |
| 6249 | |
| 6250 | return new (Importer.getToContext()) CXXNullPtrLiteralExpr( |
| 6251 | *ToTypeOrErr, *ToLocationOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6252 | } |
| 6253 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6254 | ExpectedStmt ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 6255 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6256 | if (!ToTypeOrErr) |
| 6257 | return ToTypeOrErr.takeError(); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6258 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6259 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6260 | if (!ToLocationOrErr) |
| 6261 | return ToLocationOrErr.takeError(); |
| 6262 | |
| 6263 | return IntegerLiteral::Create( |
| 6264 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6265 | } |
| 6266 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6267 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6268 | ExpectedStmt ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 6269 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6270 | if (!ToTypeOrErr) |
| 6271 | return ToTypeOrErr.takeError(); |
| 6272 | |
| 6273 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6274 | if (!ToLocationOrErr) |
| 6275 | return ToLocationOrErr.takeError(); |
| 6276 | |
| 6277 | return FloatingLiteral::Create( |
| 6278 | Importer.getToContext(), E->getValue(), E->isExact(), |
| 6279 | *ToTypeOrErr, *ToLocationOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6280 | } |
| 6281 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6282 | ExpectedStmt ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) { |
| 6283 | auto ToTypeOrErr = import(E->getType()); |
| 6284 | if (!ToTypeOrErr) |
| 6285 | return ToTypeOrErr.takeError(); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6286 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6287 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6288 | if (!ToSubExprOrErr) |
| 6289 | return ToSubExprOrErr.takeError(); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6290 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6291 | return new (Importer.getToContext()) ImaginaryLiteral( |
| 6292 | *ToSubExprOrErr, *ToTypeOrErr); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6293 | } |
| 6294 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6295 | ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 6296 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6297 | if (!ToTypeOrErr) |
| 6298 | return ToTypeOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6299 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6300 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6301 | if (!ToLocationOrErr) |
| 6302 | return ToLocationOrErr.takeError(); |
| 6303 | |
| 6304 | return new (Importer.getToContext()) CharacterLiteral( |
| 6305 | E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr); |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 6306 | } |
| 6307 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6308 | ExpectedStmt ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 6309 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6310 | if (!ToTypeOrErr) |
| 6311 | return ToTypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6312 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6313 | SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated()); |
| 6314 | if (Error Err = ImportArrayChecked( |
| 6315 | E->tokloc_begin(), E->tokloc_end(), ToLocations.begin())) |
| 6316 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6317 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6318 | return StringLiteral::Create( |
| 6319 | Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(), |
| 6320 | *ToTypeOrErr, ToLocations.data(), ToLocations.size()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6321 | } |
| 6322 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6323 | ExpectedStmt ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 6324 | auto Imp = importSeq( |
| 6325 | E->getLParenLoc(), E->getTypeSourceInfo(), E->getType(), |
| 6326 | E->getInitializer()); |
| 6327 | if (!Imp) |
| 6328 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6329 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6330 | SourceLocation ToLParenLoc; |
| 6331 | TypeSourceInfo *ToTypeSourceInfo; |
| 6332 | QualType ToType; |
| 6333 | Expr *ToInitializer; |
| 6334 | std::tie(ToLParenLoc, ToTypeSourceInfo, ToType, ToInitializer) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6335 | |
| 6336 | return new (Importer.getToContext()) CompoundLiteralExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6337 | ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(), |
| 6338 | ToInitializer, E->isFileScope()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6339 | } |
| 6340 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6341 | ExpectedStmt ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { |
| 6342 | auto Imp = importSeq( |
| 6343 | E->getBuiltinLoc(), E->getType(), E->getRParenLoc()); |
| 6344 | if (!Imp) |
| 6345 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6346 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6347 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6348 | QualType ToType; |
| 6349 | std::tie(ToBuiltinLoc, ToType, ToRParenLoc) = *Imp; |
| 6350 | |
| 6351 | SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs()); |
| 6352 | if (Error Err = ImportArrayChecked( |
| 6353 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 6354 | ToExprs.begin())) |
| 6355 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6356 | |
| 6357 | return new (Importer.getToContext()) AtomicExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6358 | ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6359 | } |
| 6360 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6361 | ExpectedStmt ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 6362 | auto Imp = importSeq( |
| 6363 | E->getAmpAmpLoc(), E->getLabelLoc(), E->getLabel(), E->getType()); |
| 6364 | if (!Imp) |
| 6365 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6366 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6367 | SourceLocation ToAmpAmpLoc, ToLabelLoc; |
| 6368 | LabelDecl *ToLabel; |
| 6369 | QualType ToType; |
| 6370 | std::tie(ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6371 | |
| 6372 | return new (Importer.getToContext()) AddrLabelExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6373 | ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6374 | } |
| 6375 | |
Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6376 | ExpectedStmt ASTNodeImporter::VisitConstantExpr(ConstantExpr *E) { |
| 6377 | auto Imp = importSeq(E->getSubExpr()); |
| 6378 | if (!Imp) |
| 6379 | return Imp.takeError(); |
| 6380 | |
| 6381 | Expr *ToSubExpr; |
| 6382 | std::tie(ToSubExpr) = *Imp; |
| 6383 | |
Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 6384 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr); |
Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6385 | } |
| 6386 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6387 | ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| 6388 | auto Imp = importSeq(E->getLParen(), E->getRParen(), E->getSubExpr()); |
| 6389 | if (!Imp) |
| 6390 | return Imp.takeError(); |
| 6391 | |
| 6392 | SourceLocation ToLParen, ToRParen; |
| 6393 | Expr *ToSubExpr; |
| 6394 | std::tie(ToLParen, ToRParen, ToSubExpr) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6395 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6396 | return new (Importer.getToContext()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6397 | ParenExpr(ToLParen, ToRParen, ToSubExpr); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6398 | } |
| 6399 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6400 | ExpectedStmt ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 6401 | SmallVector<Expr *, 4> ToExprs(E->getNumExprs()); |
| 6402 | if (Error Err = ImportContainerChecked(E->exprs(), ToExprs)) |
| 6403 | return std::move(Err); |
| 6404 | |
| 6405 | ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc()); |
| 6406 | if (!ToLParenLocOrErr) |
| 6407 | return ToLParenLocOrErr.takeError(); |
| 6408 | |
| 6409 | ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc()); |
| 6410 | if (!ToRParenLocOrErr) |
| 6411 | return ToRParenLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6412 | |
Bruno Ricci | f49e1ca | 2018-11-20 16:20:40 +0000 | [diff] [blame] | 6413 | return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr, |
| 6414 | ToExprs, *ToRParenLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6415 | } |
| 6416 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6417 | ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| 6418 | auto Imp = importSeq( |
| 6419 | E->getSubStmt(), E->getType(), E->getLParenLoc(), E->getRParenLoc()); |
| 6420 | if (!Imp) |
| 6421 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6422 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6423 | CompoundStmt *ToSubStmt; |
| 6424 | QualType ToType; |
| 6425 | SourceLocation ToLParenLoc, ToRParenLoc; |
| 6426 | std::tie(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6427 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6428 | return new (Importer.getToContext()) StmtExpr( |
| 6429 | ToSubStmt, ToType, ToLParenLoc, ToRParenLoc); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6430 | } |
| 6431 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6432 | ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| 6433 | auto Imp = importSeq( |
| 6434 | E->getSubExpr(), E->getType(), E->getOperatorLoc()); |
| 6435 | if (!Imp) |
| 6436 | return Imp.takeError(); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6437 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6438 | Expr *ToSubExpr; |
| 6439 | QualType ToType; |
| 6440 | SourceLocation ToOperatorLoc; |
| 6441 | std::tie(ToSubExpr, ToType, ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6442 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6443 | return new (Importer.getToContext()) UnaryOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6444 | ToSubExpr, E->getOpcode(), ToType, E->getValueKind(), E->getObjectKind(), |
| 6445 | ToOperatorLoc, E->canOverflow()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6446 | } |
| 6447 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6448 | ExpectedStmt |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6449 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6450 | auto Imp = importSeq(E->getType(), E->getOperatorLoc(), E->getRParenLoc()); |
| 6451 | if (!Imp) |
| 6452 | return Imp.takeError(); |
| 6453 | |
| 6454 | QualType ToType; |
| 6455 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 6456 | std::tie(ToType, ToOperatorLoc, ToRParenLoc) = *Imp; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6457 | |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6458 | if (E->isArgumentType()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6459 | Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr = |
| 6460 | import(E->getArgumentTypeInfo()); |
| 6461 | if (!ToArgumentTypeInfoOrErr) |
| 6462 | return ToArgumentTypeInfoOrErr.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(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc, |
| 6466 | ToRParenLoc); |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6467 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6468 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6469 | ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr()); |
| 6470 | if (!ToArgumentExprOrErr) |
| 6471 | return ToArgumentExprOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6472 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6473 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6474 | E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc); |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6475 | } |
| 6476 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6477 | ExpectedStmt ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| 6478 | auto Imp = importSeq( |
| 6479 | E->getLHS(), E->getRHS(), E->getType(), E->getOperatorLoc()); |
| 6480 | if (!Imp) |
| 6481 | return Imp.takeError(); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6482 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6483 | Expr *ToLHS, *ToRHS; |
| 6484 | QualType ToType; |
| 6485 | SourceLocation ToOperatorLoc; |
| 6486 | std::tie(ToLHS, ToRHS, ToType, ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6487 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6488 | return new (Importer.getToContext()) BinaryOperator( |
| 6489 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6490 | E->getObjectKind(), ToOperatorLoc, E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6491 | } |
| 6492 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6493 | ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| 6494 | auto Imp = importSeq( |
| 6495 | E->getCond(), E->getQuestionLoc(), E->getLHS(), E->getColonLoc(), |
| 6496 | E->getRHS(), E->getType()); |
| 6497 | if (!Imp) |
| 6498 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6499 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6500 | Expr *ToCond, *ToLHS, *ToRHS; |
| 6501 | SourceLocation ToQuestionLoc, ToColonLoc; |
| 6502 | QualType ToType; |
| 6503 | std::tie(ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6504 | |
| 6505 | return new (Importer.getToContext()) ConditionalOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6506 | ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType, |
| 6507 | E->getValueKind(), E->getObjectKind()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6508 | } |
| 6509 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6510 | ExpectedStmt ASTNodeImporter::VisitBinaryConditionalOperator( |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6511 | BinaryConditionalOperator *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6512 | auto Imp = importSeq( |
| 6513 | E->getCommon(), E->getOpaqueValue(), E->getCond(), E->getTrueExpr(), |
| 6514 | E->getFalseExpr(), E->getQuestionLoc(), E->getColonLoc(), E->getType()); |
| 6515 | if (!Imp) |
| 6516 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6517 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6518 | Expr *ToCommon, *ToCond, *ToTrueExpr, *ToFalseExpr; |
| 6519 | OpaqueValueExpr *ToOpaqueValue; |
| 6520 | SourceLocation ToQuestionLoc, ToColonLoc; |
| 6521 | QualType ToType; |
| 6522 | std::tie( |
| 6523 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, ToQuestionLoc, |
| 6524 | ToColonLoc, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6525 | |
| 6526 | return new (Importer.getToContext()) BinaryConditionalOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6527 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, |
| 6528 | ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(), |
| 6529 | E->getObjectKind()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6530 | } |
| 6531 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6532 | ExpectedStmt ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 6533 | auto Imp = importSeq( |
| 6534 | E->getBeginLoc(), E->getQueriedTypeSourceInfo(), |
| 6535 | E->getDimensionExpression(), E->getEndLoc(), E->getType()); |
| 6536 | if (!Imp) |
| 6537 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6538 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6539 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6540 | TypeSourceInfo *ToQueriedTypeSourceInfo; |
| 6541 | Expr *ToDimensionExpression; |
| 6542 | QualType ToType; |
| 6543 | std::tie( |
| 6544 | ToBeginLoc, ToQueriedTypeSourceInfo, ToDimensionExpression, ToEndLoc, |
| 6545 | ToType) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6546 | |
| 6547 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6548 | ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(), |
| 6549 | ToDimensionExpression, ToEndLoc, ToType); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6550 | } |
| 6551 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6552 | ExpectedStmt ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 6553 | auto Imp = importSeq( |
| 6554 | E->getBeginLoc(), E->getQueriedExpression(), E->getEndLoc(), E->getType()); |
| 6555 | if (!Imp) |
| 6556 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6557 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6558 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6559 | Expr *ToQueriedExpression; |
| 6560 | QualType ToType; |
| 6561 | std::tie(ToBeginLoc, ToQueriedExpression, ToEndLoc, ToType) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6562 | |
| 6563 | return new (Importer.getToContext()) ExpressionTraitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6564 | ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(), |
| 6565 | ToEndLoc, ToType); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6566 | } |
| 6567 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6568 | ExpectedStmt ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| 6569 | auto Imp = importSeq( |
| 6570 | E->getLocation(), E->getType(), E->getSourceExpr()); |
| 6571 | if (!Imp) |
| 6572 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6573 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6574 | SourceLocation ToLocation; |
| 6575 | QualType ToType; |
| 6576 | Expr *ToSourceExpr; |
| 6577 | std::tie(ToLocation, ToType, ToSourceExpr) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6578 | |
| 6579 | return new (Importer.getToContext()) OpaqueValueExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6580 | ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6581 | } |
| 6582 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6583 | ExpectedStmt ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 6584 | auto Imp = importSeq( |
| 6585 | E->getLHS(), E->getRHS(), E->getType(), E->getRBracketLoc()); |
| 6586 | if (!Imp) |
| 6587 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6588 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6589 | Expr *ToLHS, *ToRHS; |
| 6590 | SourceLocation ToRBracketLoc; |
| 6591 | QualType ToType; |
| 6592 | std::tie(ToLHS, ToRHS, ToType, ToRBracketLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6593 | |
| 6594 | return new (Importer.getToContext()) ArraySubscriptExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6595 | ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(), |
| 6596 | ToRBracketLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6597 | } |
| 6598 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6599 | ExpectedStmt |
| 6600 | ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 6601 | auto Imp = importSeq( |
| 6602 | E->getLHS(), E->getRHS(), E->getType(), E->getComputationLHSType(), |
| 6603 | E->getComputationResultType(), E->getOperatorLoc()); |
| 6604 | if (!Imp) |
| 6605 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6606 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6607 | Expr *ToLHS, *ToRHS; |
| 6608 | QualType ToType, ToComputationLHSType, ToComputationResultType; |
| 6609 | SourceLocation ToOperatorLoc; |
| 6610 | std::tie(ToLHS, ToRHS, ToType, ToComputationLHSType, ToComputationResultType, |
| 6611 | ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6612 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6613 | return new (Importer.getToContext()) CompoundAssignOperator( |
| 6614 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6615 | E->getObjectKind(), ToComputationLHSType, ToComputationResultType, |
| 6616 | ToOperatorLoc, E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6617 | } |
| 6618 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6619 | Expected<CXXCastPath> |
| 6620 | ASTNodeImporter::ImportCastPath(CastExpr *CE) { |
| 6621 | CXXCastPath Path; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6622 | 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] | 6623 | if (auto SpecOrErr = import(*I)) |
| 6624 | Path.push_back(*SpecOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6625 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6626 | return SpecOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6627 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6628 | return Path; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6629 | } |
| 6630 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6631 | ExpectedStmt ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 6632 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6633 | if (!ToTypeOrErr) |
| 6634 | return ToTypeOrErr.takeError(); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6635 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6636 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6637 | if (!ToSubExprOrErr) |
| 6638 | return ToSubExprOrErr.takeError(); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6639 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6640 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6641 | if (!ToBasePathOrErr) |
| 6642 | return ToBasePathOrErr.takeError(); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6643 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6644 | return ImplicitCastExpr::Create( |
| 6645 | Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr, |
| 6646 | &(*ToBasePathOrErr), E->getValueKind()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6647 | } |
| 6648 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6649 | ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
| 6650 | auto Imp1 = importSeq( |
| 6651 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten()); |
| 6652 | if (!Imp1) |
| 6653 | return Imp1.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6654 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6655 | QualType ToType; |
| 6656 | Expr *ToSubExpr; |
| 6657 | TypeSourceInfo *ToTypeInfoAsWritten; |
| 6658 | std::tie(ToType, ToSubExpr, ToTypeInfoAsWritten) = *Imp1; |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6659 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6660 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6661 | if (!ToBasePathOrErr) |
| 6662 | return ToBasePathOrErr.takeError(); |
| 6663 | CXXCastPath *ToBasePath = &(*ToBasePathOrErr); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6664 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6665 | switch (E->getStmtClass()) { |
| 6666 | case Stmt::CStyleCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6667 | auto *CCE = cast<CStyleCastExpr>(E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6668 | ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc()); |
| 6669 | if (!ToLParenLocOrErr) |
| 6670 | return ToLParenLocOrErr.takeError(); |
| 6671 | ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc()); |
| 6672 | if (!ToRParenLocOrErr) |
| 6673 | return ToRParenLocOrErr.takeError(); |
| 6674 | return CStyleCastExpr::Create( |
| 6675 | Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(), |
| 6676 | ToSubExpr, ToBasePath, ToTypeInfoAsWritten, *ToLParenLocOrErr, |
| 6677 | *ToRParenLocOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6678 | } |
| 6679 | |
| 6680 | case Stmt::CXXFunctionalCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6681 | auto *FCE = cast<CXXFunctionalCastExpr>(E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6682 | ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc()); |
| 6683 | if (!ToLParenLocOrErr) |
| 6684 | return ToLParenLocOrErr.takeError(); |
| 6685 | ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc()); |
| 6686 | if (!ToRParenLocOrErr) |
| 6687 | return ToRParenLocOrErr.takeError(); |
| 6688 | return CXXFunctionalCastExpr::Create( |
| 6689 | Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten, |
| 6690 | E->getCastKind(), ToSubExpr, ToBasePath, *ToLParenLocOrErr, |
| 6691 | *ToRParenLocOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6692 | } |
| 6693 | |
| 6694 | case Stmt::ObjCBridgedCastExprClass: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6695 | auto *OCE = cast<ObjCBridgedCastExpr>(E); |
| 6696 | ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc()); |
| 6697 | if (!ToLParenLocOrErr) |
| 6698 | return ToLParenLocOrErr.takeError(); |
| 6699 | ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc()); |
| 6700 | if (!ToBridgeKeywordLocOrErr) |
| 6701 | return ToBridgeKeywordLocOrErr.takeError(); |
| 6702 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 6703 | *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), |
| 6704 | *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6705 | } |
| 6706 | default: |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6707 | llvm_unreachable("Cast expression of unsupported type!"); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6708 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6709 | } |
| 6710 | } |
| 6711 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6712 | ExpectedStmt ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *E) { |
| 6713 | SmallVector<OffsetOfNode, 4> ToNodes; |
| 6714 | for (int I = 0, N = E->getNumComponents(); I < N; ++I) { |
| 6715 | const OffsetOfNode &FromNode = E->getComponent(I); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6716 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6717 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6718 | if (FromNode.getKind() != OffsetOfNode::Base) { |
| 6719 | auto Imp = importSeq(FromNode.getBeginLoc(), FromNode.getEndLoc()); |
| 6720 | if (!Imp) |
| 6721 | return Imp.takeError(); |
| 6722 | std::tie(ToBeginLoc, ToEndLoc) = *Imp; |
| 6723 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6724 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6725 | switch (FromNode.getKind()) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6726 | case OffsetOfNode::Array: |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6727 | ToNodes.push_back( |
| 6728 | OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6729 | break; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6730 | case OffsetOfNode::Base: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6731 | auto ToBSOrErr = import(FromNode.getBase()); |
| 6732 | if (!ToBSOrErr) |
| 6733 | return ToBSOrErr.takeError(); |
| 6734 | ToNodes.push_back(OffsetOfNode(*ToBSOrErr)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6735 | break; |
| 6736 | } |
| 6737 | case OffsetOfNode::Field: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6738 | auto ToFieldOrErr = import(FromNode.getField()); |
| 6739 | if (!ToFieldOrErr) |
| 6740 | return ToFieldOrErr.takeError(); |
| 6741 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6742 | break; |
| 6743 | } |
| 6744 | case OffsetOfNode::Identifier: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6745 | IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName()); |
| 6746 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6747 | break; |
| 6748 | } |
| 6749 | } |
| 6750 | } |
| 6751 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6752 | SmallVector<Expr *, 4> ToExprs(E->getNumExpressions()); |
| 6753 | for (int I = 0, N = E->getNumExpressions(); I < N; ++I) { |
| 6754 | ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I)); |
| 6755 | if (!ToIndexExprOrErr) |
| 6756 | return ToIndexExprOrErr.takeError(); |
| 6757 | ToExprs[I] = *ToIndexExprOrErr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6758 | } |
| 6759 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6760 | auto Imp = importSeq( |
| 6761 | E->getType(), E->getTypeSourceInfo(), E->getOperatorLoc(), |
| 6762 | E->getRParenLoc()); |
| 6763 | if (!Imp) |
| 6764 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6765 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6766 | QualType ToType; |
| 6767 | TypeSourceInfo *ToTypeSourceInfo; |
| 6768 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 6769 | std::tie(ToType, ToTypeSourceInfo, ToOperatorLoc, ToRParenLoc) = *Imp; |
| 6770 | |
| 6771 | return OffsetOfExpr::Create( |
| 6772 | Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes, |
| 6773 | ToExprs, ToRParenLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6774 | } |
| 6775 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6776 | ExpectedStmt ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 6777 | auto Imp = importSeq( |
| 6778 | E->getType(), E->getOperand(), E->getBeginLoc(), E->getEndLoc()); |
| 6779 | if (!Imp) |
| 6780 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6781 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6782 | QualType ToType; |
| 6783 | Expr *ToOperand; |
| 6784 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6785 | std::tie(ToType, ToOperand, ToBeginLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6786 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6787 | CanThrowResult ToCanThrow; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6788 | if (E->isValueDependent()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6789 | ToCanThrow = CT_Dependent; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6790 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6791 | ToCanThrow = E->getValue() ? CT_Can : CT_Cannot; |
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 | return new (Importer.getToContext()) CXXNoexceptExpr( |
| 6794 | ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6795 | } |
| 6796 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6797 | ExpectedStmt ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| 6798 | auto Imp = importSeq(E->getSubExpr(), E->getType(), E->getThrowLoc()); |
| 6799 | if (!Imp) |
| 6800 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6801 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6802 | Expr *ToSubExpr; |
| 6803 | QualType ToType; |
| 6804 | SourceLocation ToThrowLoc; |
| 6805 | std::tie(ToSubExpr, ToType, ToThrowLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6806 | |
| 6807 | return new (Importer.getToContext()) CXXThrowExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6808 | ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6809 | } |
| 6810 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6811 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| 6812 | ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation()); |
| 6813 | if (!ToUsedLocOrErr) |
| 6814 | return ToUsedLocOrErr.takeError(); |
| 6815 | |
| 6816 | auto ToParamOrErr = import(E->getParam()); |
| 6817 | if (!ToParamOrErr) |
| 6818 | return ToParamOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6819 | |
| 6820 | return CXXDefaultArgExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6821 | Importer.getToContext(), *ToUsedLocOrErr, *ToParamOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6822 | } |
| 6823 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6824 | ExpectedStmt |
| 6825 | ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| 6826 | auto Imp = importSeq( |
| 6827 | E->getType(), E->getTypeSourceInfo(), E->getRParenLoc()); |
| 6828 | if (!Imp) |
| 6829 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6830 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6831 | QualType ToType; |
| 6832 | TypeSourceInfo *ToTypeSourceInfo; |
| 6833 | SourceLocation ToRParenLoc; |
| 6834 | std::tie(ToType, ToTypeSourceInfo, ToRParenLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6835 | |
| 6836 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6837 | ToType, ToTypeSourceInfo, ToRParenLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6838 | } |
| 6839 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6840 | ExpectedStmt |
| 6841 | ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 6842 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6843 | if (!ToSubExprOrErr) |
| 6844 | return ToSubExprOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6845 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6846 | auto ToDtorOrErr = import(E->getTemporary()->getDestructor()); |
| 6847 | if (!ToDtorOrErr) |
| 6848 | return ToDtorOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6849 | |
| 6850 | ASTContext &ToCtx = Importer.getToContext(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6851 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr); |
| 6852 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6853 | } |
| 6854 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6855 | ExpectedStmt |
| 6856 | ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { |
| 6857 | auto Imp = importSeq( |
| 6858 | E->getConstructor(), E->getType(), E->getTypeSourceInfo(), |
| 6859 | E->getParenOrBraceRange()); |
| 6860 | if (!Imp) |
| 6861 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6862 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6863 | CXXConstructorDecl *ToConstructor; |
| 6864 | QualType ToType; |
| 6865 | TypeSourceInfo *ToTypeSourceInfo; |
| 6866 | SourceRange ToParenOrBraceRange; |
| 6867 | std::tie(ToConstructor, ToType, ToTypeSourceInfo, ToParenOrBraceRange) = *Imp; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6868 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6869 | SmallVector<Expr *, 8> ToArgs(E->getNumArgs()); |
| 6870 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 6871 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6872 | |
Bruno Ricci | ddb8f6b | 2018-12-22 14:39:30 +0000 | [diff] [blame] | 6873 | return CXXTemporaryObjectExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6874 | Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs, |
| 6875 | ToParenOrBraceRange, E->hadMultipleCandidates(), |
| 6876 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 6877 | E->requiresZeroInitialization()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6878 | } |
| 6879 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6880 | ExpectedStmt |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6881 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6882 | auto Imp = importSeq( |
| 6883 | E->getType(), E->GetTemporaryExpr(), E->getExtendingDecl()); |
| 6884 | if (!Imp) |
| 6885 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6886 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6887 | QualType ToType; |
| 6888 | Expr *ToTemporaryExpr; |
| 6889 | const ValueDecl *ToExtendingDecl; |
| 6890 | std::tie(ToType, ToTemporaryExpr, ToExtendingDecl) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6891 | |
| 6892 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6893 | ToType, ToTemporaryExpr, E->isBoundToLvalueReference()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6894 | |
| 6895 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6896 | ToMTE->setExtendingDecl(ToExtendingDecl, E->getManglingNumber()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6897 | return ToMTE; |
| 6898 | } |
| 6899 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6900 | ExpectedStmt ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { |
| 6901 | auto Imp = importSeq( |
| 6902 | E->getType(), E->getPattern(), E->getEllipsisLoc()); |
| 6903 | if (!Imp) |
| 6904 | return Imp.takeError(); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6905 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6906 | QualType ToType; |
| 6907 | Expr *ToPattern; |
| 6908 | SourceLocation ToEllipsisLoc; |
| 6909 | std::tie(ToType, ToPattern, ToEllipsisLoc) = *Imp; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6910 | |
| 6911 | return new (Importer.getToContext()) PackExpansionExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6912 | ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions()); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6913 | } |
| 6914 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6915 | ExpectedStmt ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { |
| 6916 | auto Imp = importSeq( |
| 6917 | E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc()); |
| 6918 | if (!Imp) |
| 6919 | return Imp.takeError(); |
| 6920 | |
| 6921 | SourceLocation ToOperatorLoc, ToPackLoc, ToRParenLoc; |
| 6922 | NamedDecl *ToPack; |
| 6923 | std::tie(ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc) = *Imp; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6924 | |
| 6925 | Optional<unsigned> Length; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6926 | if (!E->isValueDependent()) |
| 6927 | Length = E->getPackLength(); |
| 6928 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6929 | SmallVector<TemplateArgument, 8> ToPartialArguments; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6930 | if (E->isPartiallySubstituted()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6931 | if (Error Err = ImportTemplateArguments( |
| 6932 | E->getPartialArguments().data(), |
| 6933 | E->getPartialArguments().size(), |
| 6934 | ToPartialArguments)) |
| 6935 | return std::move(Err); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6936 | } |
| 6937 | |
| 6938 | return SizeOfPackExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6939 | Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc, |
| 6940 | Length, ToPartialArguments); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6941 | } |
| 6942 | |
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 | ExpectedStmt ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) { |
| 6945 | auto Imp = importSeq( |
| 6946 | E->getOperatorNew(), E->getOperatorDelete(), E->getTypeIdParens(), |
| 6947 | E->getArraySize(), E->getInitializer(), E->getType(), |
| 6948 | E->getAllocatedTypeSourceInfo(), E->getSourceRange(), |
| 6949 | E->getDirectInitRange()); |
| 6950 | if (!Imp) |
| 6951 | return Imp.takeError(); |
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 | FunctionDecl *ToOperatorNew, *ToOperatorDelete; |
| 6954 | SourceRange ToTypeIdParens, ToSourceRange, ToDirectInitRange; |
| 6955 | Expr *ToArraySize, *ToInitializer; |
| 6956 | QualType ToType; |
| 6957 | TypeSourceInfo *ToAllocatedTypeSourceInfo; |
| 6958 | std::tie( |
| 6959 | ToOperatorNew, ToOperatorDelete, ToTypeIdParens, ToArraySize, ToInitializer, |
| 6960 | ToType, ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6961 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6962 | SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs()); |
| 6963 | if (Error Err = |
| 6964 | ImportContainerChecked(E->placement_arguments(), ToPlacementArgs)) |
| 6965 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6966 | |
Bruno Ricci | 9b6dfac | 2019-01-07 15:04:45 +0000 | [diff] [blame] | 6967 | return CXXNewExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6968 | Importer.getToContext(), E->isGlobalNew(), ToOperatorNew, |
| 6969 | ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(), |
| 6970 | ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(), |
| 6971 | ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange, |
| 6972 | ToDirectInitRange); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6973 | } |
| 6974 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6975 | ExpectedStmt ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 6976 | auto Imp = importSeq( |
| 6977 | E->getType(), E->getOperatorDelete(), E->getArgument(), E->getBeginLoc()); |
| 6978 | if (!Imp) |
| 6979 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6980 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6981 | QualType ToType; |
| 6982 | FunctionDecl *ToOperatorDelete; |
| 6983 | Expr *ToArgument; |
| 6984 | SourceLocation ToBeginLoc; |
| 6985 | std::tie(ToType, ToOperatorDelete, ToArgument, ToBeginLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6986 | |
| 6987 | return new (Importer.getToContext()) CXXDeleteExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6988 | ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(), |
| 6989 | E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument, |
| 6990 | ToBeginLoc); |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6991 | } |
| 6992 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6993 | ExpectedStmt ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| 6994 | auto Imp = importSeq( |
| 6995 | E->getType(), E->getLocation(), E->getConstructor(), |
| 6996 | E->getParenOrBraceRange()); |
| 6997 | if (!Imp) |
| 6998 | return Imp.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6999 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7000 | QualType ToType; |
| 7001 | SourceLocation ToLocation; |
| 7002 | CXXConstructorDecl *ToConstructor; |
| 7003 | SourceRange ToParenOrBraceRange; |
| 7004 | std::tie(ToType, ToLocation, ToConstructor, ToParenOrBraceRange) = *Imp; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7005 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7006 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7007 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7008 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7009 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7010 | return CXXConstructExpr::Create( |
| 7011 | Importer.getToContext(), ToType, ToLocation, ToConstructor, |
| 7012 | E->isElidable(), ToArgs, E->hadMultipleCandidates(), |
| 7013 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 7014 | E->requiresZeroInitialization(), E->getConstructionKind(), |
| 7015 | ToParenOrBraceRange); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7016 | } |
| 7017 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7018 | ExpectedStmt ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *E) { |
| 7019 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7020 | if (!ToSubExprOrErr) |
| 7021 | return ToSubExprOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7022 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7023 | SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects()); |
| 7024 | if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects)) |
| 7025 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7026 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7027 | return ExprWithCleanups::Create( |
| 7028 | Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(), |
| 7029 | ToObjects); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7030 | } |
| 7031 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7032 | ExpectedStmt ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 7033 | auto Imp = importSeq( |
| 7034 | E->getCallee(), E->getType(), E->getRParenLoc()); |
| 7035 | if (!Imp) |
| 7036 | return Imp.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7037 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7038 | Expr *ToCallee; |
| 7039 | QualType ToType; |
| 7040 | SourceLocation ToRParenLoc; |
| 7041 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7042 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7043 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7044 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7045 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7046 | |
Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7047 | return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, |
| 7048 | ToType, E->getValueKind(), ToRParenLoc); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7049 | } |
| 7050 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7051 | ExpectedStmt ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 7052 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7053 | if (!ToTypeOrErr) |
| 7054 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7055 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7056 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7057 | if (!ToLocationOrErr) |
| 7058 | return ToLocationOrErr.takeError(); |
| 7059 | |
| 7060 | return new (Importer.getToContext()) CXXThisExpr( |
| 7061 | *ToLocationOrErr, *ToTypeOrErr, E->isImplicit()); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7062 | } |
| 7063 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7064 | ExpectedStmt ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 7065 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7066 | if (!ToTypeOrErr) |
| 7067 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7068 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7069 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7070 | if (!ToLocationOrErr) |
| 7071 | return ToLocationOrErr.takeError(); |
| 7072 | |
| 7073 | return new (Importer.getToContext()) CXXBoolLiteralExpr( |
| 7074 | E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7075 | } |
| 7076 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7077 | ExpectedStmt ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| 7078 | auto Imp1 = importSeq( |
| 7079 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7080 | E->getTemplateKeywordLoc(), E->getMemberDecl(), E->getType()); |
| 7081 | if (!Imp1) |
| 7082 | return Imp1.takeError(); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7083 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7084 | Expr *ToBase; |
| 7085 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7086 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7087 | ValueDecl *ToMemberDecl; |
| 7088 | QualType ToType; |
| 7089 | std::tie( |
| 7090 | ToBase, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, |
| 7091 | ToType) = *Imp1; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7092 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7093 | auto Imp2 = importSeq( |
| 7094 | E->getFoundDecl().getDecl(), E->getMemberNameInfo().getName(), |
| 7095 | E->getMemberNameInfo().getLoc(), E->getLAngleLoc(), E->getRAngleLoc()); |
| 7096 | if (!Imp2) |
| 7097 | return Imp2.takeError(); |
| 7098 | NamedDecl *ToDecl; |
| 7099 | DeclarationName ToName; |
| 7100 | SourceLocation ToLoc, ToLAngleLoc, ToRAngleLoc; |
| 7101 | std::tie(ToDecl, ToName, ToLoc, ToLAngleLoc, ToRAngleLoc) = *Imp2; |
Peter Szecsi | ef97252 | 2018-05-02 11:52:54 +0000 | [diff] [blame] | 7102 | |
| 7103 | DeclAccessPair ToFoundDecl = |
| 7104 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7105 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7106 | DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7107 | |
| 7108 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7109 | // FIXME: handle template arguments |
| 7110 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7111 | } |
| 7112 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7113 | return MemberExpr::Create( |
| 7114 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, |
| 7115 | ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, ToFoundDecl, |
| 7116 | ToMemberNameInfo, nullptr, ToType, E->getValueKind(), E->getObjectKind()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7117 | } |
| 7118 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7119 | ExpectedStmt |
| 7120 | ASTNodeImporter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { |
| 7121 | auto Imp = importSeq( |
| 7122 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7123 | E->getScopeTypeInfo(), E->getColonColonLoc(), E->getTildeLoc()); |
| 7124 | if (!Imp) |
| 7125 | return Imp.takeError(); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7126 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7127 | Expr *ToBase; |
| 7128 | SourceLocation ToOperatorLoc, ToColonColonLoc, ToTildeLoc; |
| 7129 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7130 | TypeSourceInfo *ToScopeTypeInfo; |
| 7131 | std::tie( |
| 7132 | ToBase, ToOperatorLoc, ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, |
| 7133 | ToTildeLoc) = *Imp; |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7134 | |
| 7135 | PseudoDestructorTypeStorage Storage; |
| 7136 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { |
| 7137 | IdentifierInfo *ToII = Importer.Import(FromII); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7138 | ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc()); |
| 7139 | if (!ToDestroyedTypeLocOrErr) |
| 7140 | return ToDestroyedTypeLocOrErr.takeError(); |
| 7141 | Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7142 | } else { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7143 | if (auto ToTIOrErr = import(E->getDestroyedTypeInfo())) |
| 7144 | Storage = PseudoDestructorTypeStorage(*ToTIOrErr); |
| 7145 | else |
| 7146 | return ToTIOrErr.takeError(); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7147 | } |
| 7148 | |
| 7149 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7150 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, |
| 7151 | ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7152 | } |
| 7153 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7154 | ExpectedStmt ASTNodeImporter::VisitCXXDependentScopeMemberExpr( |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7155 | CXXDependentScopeMemberExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7156 | auto Imp = importSeq( |
| 7157 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7158 | E->getTemplateKeywordLoc(), E->getFirstQualifierFoundInScope()); |
| 7159 | if (!Imp) |
| 7160 | return Imp.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7161 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7162 | QualType ToType; |
| 7163 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7164 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7165 | NamedDecl *ToFirstQualifierFoundInScope; |
| 7166 | std::tie( |
| 7167 | ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7168 | ToFirstQualifierFoundInScope) = *Imp; |
| 7169 | |
| 7170 | Expr *ToBase = nullptr; |
| 7171 | if (!E->isImplicitAccess()) { |
| 7172 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7173 | ToBase = *ToBaseOrErr; |
| 7174 | else |
| 7175 | return ToBaseOrErr.takeError(); |
| 7176 | } |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7177 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7178 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7179 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7180 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7181 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7182 | ToTAInfo)) |
| 7183 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7184 | ResInfo = &ToTAInfo; |
| 7185 | } |
| 7186 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7187 | auto ToMemberNameInfoOrErr = importSeq(E->getMember(), E->getMemberLoc()); |
| 7188 | if (!ToMemberNameInfoOrErr) |
| 7189 | return ToMemberNameInfoOrErr.takeError(); |
| 7190 | DeclarationNameInfo ToMemberNameInfo( |
| 7191 | std::get<0>(*ToMemberNameInfoOrErr), std::get<1>(*ToMemberNameInfoOrErr)); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7192 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7193 | if (Error Err = ImportDeclarationNameLoc( |
| 7194 | E->getMemberNameInfo(), ToMemberNameInfo)) |
| 7195 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7196 | |
| 7197 | return CXXDependentScopeMemberExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7198 | Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc, |
| 7199 | ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope, |
| 7200 | ToMemberNameInfo, ResInfo); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7201 | } |
| 7202 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7203 | ExpectedStmt |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7204 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7205 | auto Imp = importSeq( |
| 7206 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDeclName(), |
| 7207 | E->getExprLoc(), E->getLAngleLoc(), E->getRAngleLoc()); |
| 7208 | if (!Imp) |
| 7209 | return Imp.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7210 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7211 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7212 | SourceLocation ToTemplateKeywordLoc, ToExprLoc, ToLAngleLoc, ToRAngleLoc; |
| 7213 | DeclarationName ToDeclName; |
| 7214 | std::tie( |
| 7215 | ToQualifierLoc, ToTemplateKeywordLoc, ToDeclName, ToExprLoc, |
| 7216 | ToLAngleLoc, ToRAngleLoc) = *Imp; |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7217 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7218 | DeclarationNameInfo ToNameInfo(ToDeclName, ToExprLoc); |
| 7219 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7220 | return std::move(Err); |
| 7221 | |
| 7222 | TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7223 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7224 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7225 | if (Error Err = |
| 7226 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 7227 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7228 | ResInfo = &ToTAInfo; |
| 7229 | } |
| 7230 | |
| 7231 | return DependentScopeDeclRefExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7232 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, |
| 7233 | ToNameInfo, ResInfo); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7234 | } |
| 7235 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7236 | ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr( |
| 7237 | CXXUnresolvedConstructExpr *E) { |
| 7238 | auto Imp = importSeq( |
| 7239 | E->getLParenLoc(), E->getRParenLoc(), E->getTypeSourceInfo()); |
| 7240 | if (!Imp) |
| 7241 | return Imp.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7242 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7243 | SourceLocation ToLParenLoc, ToRParenLoc; |
| 7244 | TypeSourceInfo *ToTypeSourceInfo; |
| 7245 | std::tie(ToLParenLoc, ToRParenLoc, ToTypeSourceInfo) = *Imp; |
| 7246 | |
| 7247 | SmallVector<Expr *, 8> ToArgs(E->arg_size()); |
| 7248 | if (Error Err = |
| 7249 | ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin())) |
| 7250 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7251 | |
| 7252 | return CXXUnresolvedConstructExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7253 | Importer.getToContext(), ToTypeSourceInfo, ToLParenLoc, |
| 7254 | llvm::makeArrayRef(ToArgs), ToRParenLoc); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7255 | } |
| 7256 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7257 | ExpectedStmt |
| 7258 | ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { |
| 7259 | Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass()); |
| 7260 | if (!ToNamingClassOrErr) |
| 7261 | return ToNamingClassOrErr.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7262 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7263 | auto ToQualifierLocOrErr = import(E->getQualifierLoc()); |
| 7264 | if (!ToQualifierLocOrErr) |
| 7265 | return ToQualifierLocOrErr.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7266 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7267 | auto ToNameInfoOrErr = importSeq(E->getName(), E->getNameLoc()); |
| 7268 | if (!ToNameInfoOrErr) |
| 7269 | return ToNameInfoOrErr.takeError(); |
| 7270 | DeclarationNameInfo ToNameInfo( |
| 7271 | std::get<0>(*ToNameInfoOrErr), std::get<1>(*ToNameInfoOrErr)); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7272 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7273 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7274 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7275 | |
| 7276 | UnresolvedSet<8> ToDecls; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7277 | for (auto *D : E->decls()) |
| 7278 | if (auto ToDOrErr = import(D)) |
| 7279 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7280 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7281 | return ToDOrErr.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7282 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7283 | if (E->hasExplicitTemplateArgs() && E->getTemplateKeywordLoc().isValid()) { |
| 7284 | TemplateArgumentListInfo ToTAInfo; |
| 7285 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7286 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7287 | ToTAInfo)) |
| 7288 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7289 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7290 | ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc()); |
| 7291 | if (!ToTemplateKeywordLocOrErr) |
| 7292 | return ToTemplateKeywordLocOrErr.takeError(); |
| 7293 | |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7294 | return UnresolvedLookupExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7295 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7296 | *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo, |
| 7297 | ToDecls.begin(), ToDecls.end()); |
| 7298 | } |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7299 | |
| 7300 | return UnresolvedLookupExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7301 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7302 | ToNameInfo, E->requiresADL(), E->isOverloaded(), ToDecls.begin(), |
| 7303 | ToDecls.end()); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7304 | } |
| 7305 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7306 | ExpectedStmt |
| 7307 | ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { |
| 7308 | auto Imp1 = importSeq( |
| 7309 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7310 | E->getTemplateKeywordLoc()); |
| 7311 | if (!Imp1) |
| 7312 | return Imp1.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7313 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7314 | QualType ToType; |
| 7315 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7316 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7317 | std::tie(ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc) = *Imp1; |
| 7318 | |
| 7319 | auto Imp2 = importSeq(E->getName(), E->getNameLoc()); |
| 7320 | if (!Imp2) |
| 7321 | return Imp2.takeError(); |
| 7322 | DeclarationNameInfo ToNameInfo(std::get<0>(*Imp2), std::get<1>(*Imp2)); |
| 7323 | // Import additional name location/type info. |
| 7324 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7325 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7326 | |
| 7327 | UnresolvedSet<8> ToDecls; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7328 | for (Decl *D : E->decls()) |
| 7329 | if (auto ToDOrErr = import(D)) |
| 7330 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7331 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7332 | return ToDOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7333 | |
| 7334 | TemplateArgumentListInfo ToTAInfo; |
| 7335 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7336 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7337 | if (Error Err = |
| 7338 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 7339 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7340 | ResInfo = &ToTAInfo; |
| 7341 | } |
| 7342 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7343 | Expr *ToBase = nullptr; |
| 7344 | if (!E->isImplicitAccess()) { |
| 7345 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7346 | ToBase = *ToBaseOrErr; |
| 7347 | else |
| 7348 | return ToBaseOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7349 | } |
| 7350 | |
| 7351 | return UnresolvedMemberExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7352 | Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType, |
| 7353 | E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7354 | ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end()); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7355 | } |
| 7356 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7357 | ExpectedStmt ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| 7358 | auto Imp = importSeq(E->getCallee(), E->getType(), E->getRParenLoc()); |
| 7359 | if (!Imp) |
| 7360 | return Imp.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7361 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7362 | Expr *ToCallee; |
| 7363 | QualType ToType; |
| 7364 | SourceLocation ToRParenLoc; |
| 7365 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7366 | |
| 7367 | unsigned NumArgs = E->getNumArgs(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7368 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); |
| 7369 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7370 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7371 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7372 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { |
Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7373 | return CXXOperatorCallExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7374 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType, |
Eric Fiselier | 5cdc2cd | 2018-12-12 21:50:55 +0000 | [diff] [blame] | 7375 | OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(), |
| 7376 | OCE->getADLCallKind()); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7377 | } |
| 7378 | |
Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7379 | return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType, |
| 7380 | E->getValueKind(), ToRParenLoc, /*MinNumArgs=*/0, |
| 7381 | E->getADLCallKind()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7382 | } |
| 7383 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7384 | ExpectedStmt ASTNodeImporter::VisitLambdaExpr(LambdaExpr *E) { |
| 7385 | CXXRecordDecl *FromClass = E->getLambdaClass(); |
| 7386 | auto ToClassOrErr = import(FromClass); |
| 7387 | if (!ToClassOrErr) |
| 7388 | return ToClassOrErr.takeError(); |
| 7389 | CXXRecordDecl *ToClass = *ToClassOrErr; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7390 | |
| 7391 | // NOTE: lambda classes are created with BeingDefined flag set up. |
| 7392 | // It means that ImportDefinition doesn't work for them and we should fill it |
| 7393 | // manually. |
Gabor Marton | 302f300 | 2019-02-15 12:04:05 +0000 | [diff] [blame] | 7394 | if (ToClass->isBeingDefined()) |
| 7395 | if (Error Err = ImportDeclContext(FromClass, /*ForceImport = */ true)) |
| 7396 | return std::move(Err); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7397 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7398 | auto ToCallOpOrErr = import(E->getCallOperator()); |
| 7399 | if (!ToCallOpOrErr) |
| 7400 | return ToCallOpOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7401 | |
| 7402 | ToClass->completeDefinition(); |
| 7403 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7404 | SmallVector<LambdaCapture, 8> ToCaptures; |
| 7405 | ToCaptures.reserve(E->capture_size()); |
| 7406 | for (const auto &FromCapture : E->captures()) { |
| 7407 | if (auto ToCaptureOrErr = import(FromCapture)) |
| 7408 | ToCaptures.push_back(*ToCaptureOrErr); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7409 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7410 | return ToCaptureOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7411 | } |
| 7412 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7413 | SmallVector<Expr *, 8> ToCaptureInits(E->capture_size()); |
| 7414 | if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits)) |
| 7415 | return std::move(Err); |
| 7416 | |
| 7417 | auto Imp = importSeq( |
| 7418 | E->getIntroducerRange(), E->getCaptureDefaultLoc(), E->getEndLoc()); |
| 7419 | if (!Imp) |
| 7420 | return Imp.takeError(); |
| 7421 | |
| 7422 | SourceRange ToIntroducerRange; |
| 7423 | SourceLocation ToCaptureDefaultLoc, ToEndLoc; |
| 7424 | std::tie(ToIntroducerRange, ToCaptureDefaultLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7425 | |
Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 7426 | return LambdaExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7427 | Importer.getToContext(), ToClass, ToIntroducerRange, |
| 7428 | E->getCaptureDefault(), ToCaptureDefaultLoc, ToCaptures, |
| 7429 | E->hasExplicitParameters(), E->hasExplicitResultType(), ToCaptureInits, |
| 7430 | ToEndLoc, E->containsUnexpandedParameterPack()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7431 | } |
| 7432 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7433 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7434 | ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) { |
| 7435 | auto Imp = importSeq(E->getLBraceLoc(), E->getRBraceLoc(), E->getType()); |
| 7436 | if (!Imp) |
| 7437 | return Imp.takeError(); |
| 7438 | |
| 7439 | SourceLocation ToLBraceLoc, ToRBraceLoc; |
| 7440 | QualType ToType; |
| 7441 | std::tie(ToLBraceLoc, ToRBraceLoc, ToType) = *Imp; |
| 7442 | |
| 7443 | SmallVector<Expr *, 4> ToExprs(E->getNumInits()); |
| 7444 | if (Error Err = ImportContainerChecked(E->inits(), ToExprs)) |
| 7445 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7446 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7447 | ASTContext &ToCtx = Importer.getToContext(); |
| 7448 | InitListExpr *To = new (ToCtx) InitListExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7449 | ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc); |
| 7450 | To->setType(ToType); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7451 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7452 | if (E->hasArrayFiller()) { |
| 7453 | if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller())) |
| 7454 | To->setArrayFiller(*ToFillerOrErr); |
| 7455 | else |
| 7456 | return ToFillerOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7457 | } |
| 7458 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7459 | if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) { |
| 7460 | if (auto ToFDOrErr = import(FromFD)) |
| 7461 | To->setInitializedFieldInUnion(*ToFDOrErr); |
| 7462 | else |
| 7463 | return ToFDOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7464 | } |
| 7465 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7466 | if (InitListExpr *SyntForm = E->getSyntacticForm()) { |
| 7467 | if (auto ToSyntFormOrErr = import(SyntForm)) |
| 7468 | To->setSyntacticForm(*ToSyntFormOrErr); |
| 7469 | else |
| 7470 | return ToSyntFormOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7471 | } |
| 7472 | |
Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7473 | // Copy InitListExprBitfields, which are not handled in the ctor of |
| 7474 | // InitListExpr. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7475 | To->sawArrayRangeDesignator(E->hadArrayRangeDesignator()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7476 | |
| 7477 | return To; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7478 | } |
| 7479 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7480 | ExpectedStmt ASTNodeImporter::VisitCXXStdInitializerListExpr( |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7481 | CXXStdInitializerListExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7482 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7483 | if (!ToTypeOrErr) |
| 7484 | return ToTypeOrErr.takeError(); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7485 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7486 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7487 | if (!ToSubExprOrErr) |
| 7488 | return ToSubExprOrErr.takeError(); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7489 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7490 | return new (Importer.getToContext()) CXXStdInitializerListExpr( |
| 7491 | *ToTypeOrErr, *ToSubExprOrErr); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7492 | } |
| 7493 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7494 | ExpectedStmt ASTNodeImporter::VisitCXXInheritedCtorInitExpr( |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7495 | CXXInheritedCtorInitExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7496 | auto Imp = importSeq(E->getLocation(), E->getType(), E->getConstructor()); |
| 7497 | if (!Imp) |
| 7498 | return Imp.takeError(); |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7499 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7500 | SourceLocation ToLocation; |
| 7501 | QualType ToType; |
| 7502 | CXXConstructorDecl *ToConstructor; |
| 7503 | std::tie(ToLocation, ToType, ToConstructor) = *Imp; |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7504 | |
| 7505 | return new (Importer.getToContext()) CXXInheritedCtorInitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7506 | ToLocation, ToType, ToConstructor, E->constructsVBase(), |
| 7507 | E->inheritedFromVBase()); |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7508 | } |
| 7509 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7510 | ExpectedStmt ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 7511 | auto Imp = importSeq(E->getType(), E->getCommonExpr(), E->getSubExpr()); |
| 7512 | if (!Imp) |
| 7513 | return Imp.takeError(); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7514 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7515 | QualType ToType; |
| 7516 | Expr *ToCommonExpr, *ToSubExpr; |
| 7517 | std::tie(ToType, ToCommonExpr, ToSubExpr) = *Imp; |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7518 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7519 | return new (Importer.getToContext()) ArrayInitLoopExpr( |
| 7520 | ToType, ToCommonExpr, ToSubExpr); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7521 | } |
| 7522 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7523 | ExpectedStmt ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 7524 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7525 | if (!ToTypeOrErr) |
| 7526 | return ToTypeOrErr.takeError(); |
| 7527 | return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7528 | } |
| 7529 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7530 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 7531 | ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc()); |
| 7532 | if (!ToBeginLocOrErr) |
| 7533 | return ToBeginLocOrErr.takeError(); |
| 7534 | |
| 7535 | auto ToFieldOrErr = import(E->getField()); |
| 7536 | if (!ToFieldOrErr) |
| 7537 | return ToFieldOrErr.takeError(); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7538 | |
| 7539 | return CXXDefaultInitExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7540 | Importer.getToContext(), *ToBeginLocOrErr, *ToFieldOrErr); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7541 | } |
| 7542 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7543 | ExpectedStmt ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 7544 | auto Imp = importSeq( |
| 7545 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten(), |
| 7546 | E->getOperatorLoc(), E->getRParenLoc(), E->getAngleBrackets()); |
| 7547 | if (!Imp) |
| 7548 | return Imp.takeError(); |
| 7549 | |
| 7550 | QualType ToType; |
| 7551 | Expr *ToSubExpr; |
| 7552 | TypeSourceInfo *ToTypeInfoAsWritten; |
| 7553 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 7554 | SourceRange ToAngleBrackets; |
| 7555 | std::tie( |
| 7556 | ToType, ToSubExpr, ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, |
| 7557 | ToAngleBrackets) = *Imp; |
| 7558 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7559 | ExprValueKind VK = E->getValueKind(); |
| 7560 | CastKind CK = E->getCastKind(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7561 | auto ToBasePathOrErr = ImportCastPath(E); |
| 7562 | if (!ToBasePathOrErr) |
| 7563 | return ToBasePathOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7564 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7565 | if (isa<CXXStaticCastExpr>(E)) { |
| 7566 | return CXXStaticCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7567 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7568 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7569 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 7570 | return CXXDynamicCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7571 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7572 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7573 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 7574 | return CXXReinterpretCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7575 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7576 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Raphael Isemann | c705bb8 | 2018-08-20 16:20:01 +0000 | [diff] [blame] | 7577 | } else if (isa<CXXConstCastExpr>(E)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7578 | return CXXConstCastExpr::Create( |
| 7579 | Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten, |
| 7580 | ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7581 | } else { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7582 | llvm_unreachable("Unknown cast type"); |
| 7583 | return make_error<ImportError>(); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7584 | } |
| 7585 | } |
| 7586 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7587 | ExpectedStmt ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7588 | SubstNonTypeTemplateParmExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7589 | auto Imp = importSeq( |
| 7590 | E->getType(), E->getExprLoc(), E->getParameter(), E->getReplacement()); |
| 7591 | if (!Imp) |
| 7592 | return Imp.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7593 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7594 | QualType ToType; |
| 7595 | SourceLocation ToExprLoc; |
| 7596 | NonTypeTemplateParmDecl *ToParameter; |
| 7597 | Expr *ToReplacement; |
| 7598 | std::tie(ToType, ToExprLoc, ToParameter, ToReplacement) = *Imp; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7599 | |
| 7600 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7601 | ToType, E->getValueKind(), ToExprLoc, ToParameter, ToReplacement); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7602 | } |
| 7603 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7604 | ExpectedStmt ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { |
| 7605 | auto Imp = importSeq( |
| 7606 | E->getType(), E->getBeginLoc(), E->getEndLoc()); |
| 7607 | if (!Imp) |
| 7608 | return Imp.takeError(); |
| 7609 | |
| 7610 | QualType ToType; |
| 7611 | SourceLocation ToBeginLoc, ToEndLoc; |
| 7612 | std::tie(ToType, ToBeginLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7613 | |
| 7614 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7615 | if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs)) |
| 7616 | return std::move(Err); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7617 | |
| 7618 | // According to Sema::BuildTypeTrait(), if E is value-dependent, |
| 7619 | // Value is always false. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7620 | bool ToValue = (E->isValueDependent() ? false : E->getValue()); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7621 | |
| 7622 | return TypeTraitExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7623 | Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs, |
| 7624 | ToEndLoc, ToValue); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7625 | } |
| 7626 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7627 | ExpectedStmt ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { |
| 7628 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7629 | if (!ToTypeOrErr) |
| 7630 | return ToTypeOrErr.takeError(); |
| 7631 | |
| 7632 | auto ToSourceRangeOrErr = import(E->getSourceRange()); |
| 7633 | if (!ToSourceRangeOrErr) |
| 7634 | return ToSourceRangeOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7635 | |
| 7636 | if (E->isTypeOperand()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7637 | if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo())) |
| 7638 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7639 | *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr); |
| 7640 | else |
| 7641 | return ToTSIOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7642 | } |
| 7643 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7644 | ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand()); |
| 7645 | if (!ToExprOperandOrErr) |
| 7646 | return ToExprOperandOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7647 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7648 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7649 | *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7650 | } |
| 7651 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7652 | void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod, |
| 7653 | CXXMethodDecl *FromMethod) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7654 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) { |
| 7655 | if (auto ImportedOrErr = import(FromOverriddenMethod)) |
| 7656 | ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>( |
| 7657 | (*ImportedOrErr)->getCanonicalDecl())); |
| 7658 | else |
| 7659 | consumeError(ImportedOrErr.takeError()); |
| 7660 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7661 | } |
| 7662 | |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7663 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7664 | ASTContext &FromContext, FileManager &FromFileManager, |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7665 | bool MinimalImport, |
| 7666 | ASTImporterLookupTable *LookupTable) |
| 7667 | : LookupTable(LookupTable), ToContext(ToContext), FromContext(FromContext), |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7668 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
| 7669 | Minimal(MinimalImport) { |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7670 | |
| 7671 | ImportedDecls[FromContext.getTranslationUnitDecl()] = |
| 7672 | ToContext.getTranslationUnitDecl(); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7673 | } |
| 7674 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7675 | ASTImporter::~ASTImporter() = default; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7676 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7677 | Expected<QualType> ASTImporter::Import_New(QualType FromT) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7678 | QualType ToT = Import(FromT); |
| 7679 | if (ToT.isNull() && !FromT.isNull()) |
| 7680 | return make_error<ImportError>(); |
| 7681 | return ToT; |
| 7682 | } |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7683 | |
| 7684 | Optional<unsigned> ASTImporter::getFieldIndex(Decl *F) { |
| 7685 | assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) && |
| 7686 | "Try to get field index for non-field."); |
| 7687 | |
| 7688 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); |
| 7689 | if (!Owner) |
| 7690 | return None; |
| 7691 | |
| 7692 | unsigned Index = 0; |
| 7693 | for (const auto *D : Owner->decls()) { |
| 7694 | if (D == F) |
| 7695 | return Index; |
| 7696 | |
| 7697 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) |
| 7698 | ++Index; |
| 7699 | } |
| 7700 | |
| 7701 | llvm_unreachable("Field was not found in its parent context."); |
| 7702 | |
| 7703 | return None; |
| 7704 | } |
| 7705 | |
| 7706 | ASTImporter::FoundDeclsTy |
| 7707 | ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) { |
| 7708 | // We search in the redecl context because of transparent contexts. |
| 7709 | // E.g. a simple C language enum is a transparent context: |
| 7710 | // enum E { A, B }; |
| 7711 | // Now if we had a global variable in the TU |
| 7712 | // int A; |
| 7713 | // then the enum constant 'A' and the variable 'A' violates ODR. |
| 7714 | // We can diagnose this only if we search in the redecl context. |
| 7715 | DeclContext *ReDC = DC->getRedeclContext(); |
| 7716 | if (LookupTable) { |
| 7717 | ASTImporterLookupTable::LookupResult LookupResult = |
| 7718 | LookupTable->lookup(ReDC, Name); |
| 7719 | return FoundDeclsTy(LookupResult.begin(), LookupResult.end()); |
| 7720 | } else { |
| 7721 | // FIXME Can we remove this kind of lookup? |
| 7722 | // Or lldb really needs this C/C++ lookup? |
| 7723 | FoundDeclsTy Result; |
| 7724 | ReDC->localUncachedLookup(Name, Result); |
| 7725 | return Result; |
| 7726 | } |
| 7727 | } |
| 7728 | |
| 7729 | void ASTImporter::AddToLookupTable(Decl *ToD) { |
| 7730 | if (LookupTable) |
| 7731 | if (auto *ToND = dyn_cast<NamedDecl>(ToD)) |
| 7732 | LookupTable->add(ToND); |
| 7733 | } |
| 7734 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7735 | QualType ASTImporter::Import(QualType FromT) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7736 | if (FromT.isNull()) |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7737 | return {}; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7738 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7739 | const Type *FromTy = FromT.getTypePtr(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7740 | |
| 7741 | // Check whether we've already imported this type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7742 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7743 | = ImportedTypes.find(FromTy); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7744 | if (Pos != ImportedTypes.end()) |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7745 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7746 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7747 | // Import the type |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7748 | ASTNodeImporter Importer(*this); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7749 | ExpectedType ToTOrErr = Importer.Visit(FromTy); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7750 | if (!ToTOrErr) { |
| 7751 | llvm::consumeError(ToTOrErr.takeError()); |
| 7752 | return {}; |
| 7753 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7754 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7755 | // Record the imported type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7756 | ImportedTypes[FromTy] = (*ToTOrErr).getTypePtr(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7757 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7758 | return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7759 | } |
| 7760 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7761 | Expected<TypeSourceInfo *> ASTImporter::Import_New(TypeSourceInfo *FromTSI) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7762 | TypeSourceInfo *ToTSI = Import(FromTSI); |
| 7763 | if (!ToTSI && FromTSI) |
| 7764 | return llvm::make_error<ImportError>(); |
| 7765 | return ToTSI; |
| 7766 | } |
| 7767 | TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) { |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7768 | if (!FromTSI) |
| 7769 | return FromTSI; |
| 7770 | |
| 7771 | // FIXME: For now we just create a "trivial" type source info based |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 7772 | // 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] | 7773 | QualType T = Import(FromTSI->getType()); |
| 7774 | if (T.isNull()) |
| 7775 | return nullptr; |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7776 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7777 | return ToContext.getTrivialTypeSourceInfo( |
| 7778 | T, Import(FromTSI->getTypeLoc().getBeginLoc())); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7779 | } |
| 7780 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7781 | Expected<Attr *> ASTImporter::Import_New(const Attr *FromAttr) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7782 | return Import(FromAttr); |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 7783 | } |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7784 | Attr *ASTImporter::Import(const Attr *FromAttr) { |
| 7785 | Attr *ToAttr = FromAttr->clone(ToContext); |
| 7786 | // NOTE: Import of SourceRange may fail. |
| 7787 | ToAttr->setRange(Import(FromAttr->getRange())); |
| 7788 | return ToAttr; |
Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 7789 | } |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 7790 | |
Gabor Marton | be77a98 | 2018-12-12 11:22:55 +0000 | [diff] [blame] | 7791 | Decl *ASTImporter::GetAlreadyImportedOrNull(const Decl *FromD) const { |
| 7792 | auto Pos = ImportedDecls.find(FromD); |
| 7793 | if (Pos != ImportedDecls.end()) |
| 7794 | return Pos->second; |
| 7795 | else |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7796 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7797 | } |
| 7798 | |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 7799 | TranslationUnitDecl *ASTImporter::GetFromTU(Decl *ToD) { |
| 7800 | auto FromDPos = ImportedFromDecls.find(ToD); |
| 7801 | if (FromDPos == ImportedFromDecls.end()) |
| 7802 | return nullptr; |
| 7803 | return FromDPos->second->getTranslationUnitDecl(); |
| 7804 | } |
| 7805 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7806 | Expected<Decl *> ASTImporter::Import_New(Decl *FromD) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7807 | Decl *ToD = Import(FromD); |
| 7808 | if (!ToD && FromD) |
| 7809 | return llvm::make_error<ImportError>(); |
| 7810 | return ToD; |
| 7811 | } |
| 7812 | Decl *ASTImporter::Import(Decl *FromD) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7813 | if (!FromD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7814 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7815 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7816 | ASTNodeImporter Importer(*this); |
| 7817 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7818 | // Check whether we've already imported this declaration. |
| 7819 | Decl *ToD = GetAlreadyImportedOrNull(FromD); |
| 7820 | if (ToD) { |
| 7821 | // If FromD has some updated flags after last import, apply it |
| 7822 | updateFlags(FromD, ToD); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7823 | return ToD; |
| 7824 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7825 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7826 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7827 | ExpectedDecl ToDOrErr = Importer.Visit(FromD); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7828 | if (!ToDOrErr) { |
| 7829 | llvm::consumeError(ToDOrErr.takeError()); |
| 7830 | return nullptr; |
| 7831 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7832 | ToD = *ToDOrErr; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7833 | |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7834 | // Once the decl is connected to the existing declarations, i.e. when the |
| 7835 | // redecl chain is properly set then we populate the lookup again. |
| 7836 | // This way the primary context will be able to find all decls. |
| 7837 | AddToLookupTable(ToD); |
| 7838 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7839 | // Notify subclasses. |
| 7840 | Imported(FromD, ToD); |
| 7841 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 7842 | updateFlags(FromD, ToD); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7843 | return ToD; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7844 | } |
| 7845 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7846 | Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7847 | if (!FromDC) |
| 7848 | return FromDC; |
| 7849 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7850 | auto *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC))); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7851 | if (!ToDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7852 | return nullptr; |
| 7853 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7854 | // 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] | 7855 | // need it to have a definition. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7856 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
| 7857 | auto *FromRecord = cast<RecordDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7858 | if (ToRecord->isCompleteDefinition()) { |
| 7859 | // Do nothing. |
| 7860 | } else if (FromRecord->isCompleteDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7861 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7862 | FromRecord, ToRecord, ASTNodeImporter::IDK_Basic)) |
| 7863 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7864 | } else { |
| 7865 | CompleteDecl(ToRecord); |
| 7866 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7867 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 7868 | auto *FromEnum = cast<EnumDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7869 | if (ToEnum->isCompleteDefinition()) { |
| 7870 | // Do nothing. |
| 7871 | } else if (FromEnum->isCompleteDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7872 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7873 | FromEnum, ToEnum, ASTNodeImporter::IDK_Basic)) |
| 7874 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7875 | } else { |
| 7876 | CompleteDecl(ToEnum); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7877 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7878 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 7879 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7880 | if (ToClass->getDefinition()) { |
| 7881 | // Do nothing. |
| 7882 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7883 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7884 | FromDef, ToClass, ASTNodeImporter::IDK_Basic)) |
| 7885 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7886 | } else { |
| 7887 | CompleteDecl(ToClass); |
| 7888 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7889 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 7890 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7891 | if (ToProto->getDefinition()) { |
| 7892 | // Do nothing. |
| 7893 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7894 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7895 | FromDef, ToProto, ASTNodeImporter::IDK_Basic)) |
| 7896 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7897 | } else { |
| 7898 | CompleteDecl(ToProto); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7899 | } |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7900 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7901 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7902 | return ToDC; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7903 | } |
| 7904 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7905 | Expected<Expr *> ASTImporter::Import_New(Expr *FromE) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7906 | Expr *ToE = Import(FromE); |
| 7907 | if (!ToE && FromE) |
| 7908 | return llvm::make_error<ImportError>(); |
| 7909 | return ToE; |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7910 | } |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7911 | Expr *ASTImporter::Import(Expr *FromE) { |
| 7912 | if (!FromE) |
| 7913 | return nullptr; |
| 7914 | |
| 7915 | return cast_or_null<Expr>(Import(cast<Stmt>(FromE))); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7916 | } |
| 7917 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7918 | Expected<Stmt *> ASTImporter::Import_New(Stmt *FromS) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7919 | Stmt *ToS = Import(FromS); |
| 7920 | if (!ToS && FromS) |
| 7921 | return llvm::make_error<ImportError>(); |
| 7922 | return ToS; |
| 7923 | } |
| 7924 | Stmt *ASTImporter::Import(Stmt *FromS) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7925 | if (!FromS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7926 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7927 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7928 | // Check whether we've already imported this declaration. |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7929 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 7930 | if (Pos != ImportedStmts.end()) |
| 7931 | return Pos->second; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7932 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7933 | // Import the statement. |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7934 | ASTNodeImporter Importer(*this); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7935 | ExpectedStmt ToSOrErr = Importer.Visit(FromS); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7936 | if (!ToSOrErr) { |
| 7937 | llvm::consumeError(ToSOrErr.takeError()); |
| 7938 | return nullptr; |
| 7939 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7940 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7941 | if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) { |
Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7942 | auto *FromE = cast<Expr>(FromS); |
| 7943 | // Copy ExprBitfields, which may not be handled in Expr subclasses |
| 7944 | // constructors. |
| 7945 | ToE->setValueKind(FromE->getValueKind()); |
| 7946 | ToE->setObjectKind(FromE->getObjectKind()); |
| 7947 | ToE->setTypeDependent(FromE->isTypeDependent()); |
| 7948 | ToE->setValueDependent(FromE->isValueDependent()); |
| 7949 | ToE->setInstantiationDependent(FromE->isInstantiationDependent()); |
| 7950 | ToE->setContainsUnexpandedParameterPack( |
| 7951 | FromE->containsUnexpandedParameterPack()); |
| 7952 | } |
| 7953 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7954 | // Record the imported declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7955 | ImportedStmts[FromS] = *ToSOrErr; |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7956 | return *ToSOrErr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7957 | } |
| 7958 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7959 | Expected<NestedNameSpecifier *> |
| 7960 | ASTImporter::Import_New(NestedNameSpecifier *FromNNS) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7961 | NestedNameSpecifier *ToNNS = Import(FromNNS); |
| 7962 | if (!ToNNS && FromNNS) |
| 7963 | return llvm::make_error<ImportError>(); |
| 7964 | return ToNNS; |
| 7965 | } |
| 7966 | NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7967 | if (!FromNNS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7968 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7969 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7970 | NestedNameSpecifier *prefix = Import(FromNNS->getPrefix()); |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7971 | |
| 7972 | switch (FromNNS->getKind()) { |
| 7973 | case NestedNameSpecifier::Identifier: |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7974 | if (IdentifierInfo *II = Import(FromNNS->getAsIdentifier())) { |
| 7975 | return NestedNameSpecifier::Create(ToContext, prefix, II); |
| 7976 | } |
| 7977 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7978 | |
| 7979 | case NestedNameSpecifier::Namespace: |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7980 | if (auto *NS = |
| 7981 | cast_or_null<NamespaceDecl>(Import(FromNNS->getAsNamespace()))) { |
| 7982 | return NestedNameSpecifier::Create(ToContext, prefix, NS); |
| 7983 | } |
| 7984 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7985 | |
| 7986 | case NestedNameSpecifier::NamespaceAlias: |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7987 | if (auto *NSAD = |
| 7988 | cast_or_null<NamespaceAliasDecl>(Import(FromNNS->getAsNamespaceAlias()))) { |
| 7989 | return NestedNameSpecifier::Create(ToContext, prefix, NSAD); |
| 7990 | } |
| 7991 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7992 | |
| 7993 | case NestedNameSpecifier::Global: |
| 7994 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 7995 | |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7996 | case NestedNameSpecifier::Super: |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7997 | if (auto *RD = |
| 7998 | cast_or_null<CXXRecordDecl>(Import(FromNNS->getAsRecordDecl()))) { |
| 7999 | return NestedNameSpecifier::SuperSpecifier(ToContext, RD); |
| 8000 | } |
| 8001 | return nullptr; |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8002 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8003 | case NestedNameSpecifier::TypeSpec: |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8004 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 8005 | QualType T = Import(QualType(FromNNS->getAsType(), 0u)); |
| 8006 | if (!T.isNull()) { |
| 8007 | bool bTemplate = FromNNS->getKind() == |
| 8008 | NestedNameSpecifier::TypeSpecWithTemplate; |
| 8009 | return NestedNameSpecifier::Create(ToContext, prefix, |
| 8010 | bTemplate, T.getTypePtr()); |
| 8011 | } |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8012 | } |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8013 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8014 | } |
| 8015 | |
| 8016 | llvm_unreachable("Invalid nested name specifier kind"); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8017 | } |
| 8018 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8019 | Expected<NestedNameSpecifierLoc> |
| 8020 | ASTImporter::Import_New(NestedNameSpecifierLoc FromNNS) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8021 | NestedNameSpecifierLoc ToNNS = Import(FromNNS); |
| 8022 | return ToNNS; |
| 8023 | } |
| 8024 | NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8025 | // Copied from NestedNameSpecifier mostly. |
| 8026 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 8027 | NestedNameSpecifierLoc NNS = FromNNS; |
| 8028 | |
| 8029 | // Push each of the nested-name-specifiers's onto a stack for |
| 8030 | // serialization in reverse order. |
| 8031 | while (NNS) { |
| 8032 | NestedNames.push_back(NNS); |
| 8033 | NNS = NNS.getPrefix(); |
| 8034 | } |
| 8035 | |
| 8036 | NestedNameSpecifierLocBuilder Builder; |
| 8037 | |
| 8038 | while (!NestedNames.empty()) { |
| 8039 | NNS = NestedNames.pop_back_val(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8040 | NestedNameSpecifier *Spec = Import(NNS.getNestedNameSpecifier()); |
| 8041 | if (!Spec) |
| 8042 | return NestedNameSpecifierLoc(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8043 | |
| 8044 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
| 8045 | switch (Kind) { |
| 8046 | case NestedNameSpecifier::Identifier: |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8047 | Builder.Extend(getToContext(), |
| 8048 | Spec->getAsIdentifier(), |
| 8049 | Import(NNS.getLocalBeginLoc()), |
| 8050 | Import(NNS.getLocalEndLoc())); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8051 | break; |
| 8052 | |
| 8053 | case NestedNameSpecifier::Namespace: |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8054 | Builder.Extend(getToContext(), |
| 8055 | Spec->getAsNamespace(), |
| 8056 | Import(NNS.getLocalBeginLoc()), |
| 8057 | Import(NNS.getLocalEndLoc())); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8058 | break; |
| 8059 | |
| 8060 | case NestedNameSpecifier::NamespaceAlias: |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8061 | Builder.Extend(getToContext(), |
| 8062 | Spec->getAsNamespaceAlias(), |
| 8063 | Import(NNS.getLocalBeginLoc()), |
| 8064 | Import(NNS.getLocalEndLoc())); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8065 | break; |
| 8066 | |
| 8067 | case NestedNameSpecifier::TypeSpec: |
| 8068 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 8069 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
| 8070 | QualType(Spec->getAsType(), 0)); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8071 | Builder.Extend(getToContext(), |
| 8072 | Import(NNS.getLocalBeginLoc()), |
| 8073 | TSI->getTypeLoc(), |
| 8074 | Import(NNS.getLocalEndLoc())); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8075 | break; |
| 8076 | } |
| 8077 | |
| 8078 | case NestedNameSpecifier::Global: |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8079 | Builder.MakeGlobal(getToContext(), Import(NNS.getLocalBeginLoc())); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8080 | break; |
| 8081 | |
| 8082 | case NestedNameSpecifier::Super: { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8083 | SourceRange ToRange = Import(NNS.getSourceRange()); |
| 8084 | Builder.MakeSuper(getToContext(), |
| 8085 | Spec->getAsRecordDecl(), |
| 8086 | ToRange.getBegin(), |
| 8087 | ToRange.getEnd()); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8088 | } |
| 8089 | } |
| 8090 | } |
| 8091 | |
| 8092 | return Builder.getWithLocInContext(getToContext()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 8093 | } |
| 8094 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8095 | Expected<TemplateName> ASTImporter::Import_New(TemplateName From) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8096 | TemplateName To = Import(From); |
| 8097 | if (To.isNull() && !From.isNull()) |
| 8098 | return llvm::make_error<ImportError>(); |
| 8099 | return To; |
| 8100 | } |
| 8101 | TemplateName ASTImporter::Import(TemplateName From) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8102 | switch (From.getKind()) { |
| 8103 | case TemplateName::Template: |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8104 | if (auto *ToTemplate = |
| 8105 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
| 8106 | return TemplateName(ToTemplate); |
| 8107 | |
| 8108 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8109 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8110 | case TemplateName::OverloadedTemplate: { |
| 8111 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 8112 | UnresolvedSet<2> ToTemplates; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8113 | for (auto *I : *FromStorage) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8114 | if (auto *To = cast_or_null<NamedDecl>(Import(I))) |
| 8115 | ToTemplates.addDecl(To); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8116 | else |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8117 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8118 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8119 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8120 | ToTemplates.end()); |
| 8121 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8122 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8123 | case TemplateName::QualifiedTemplate: { |
| 8124 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8125 | NestedNameSpecifier *Qualifier = Import(QTN->getQualifier()); |
| 8126 | if (!Qualifier) |
| 8127 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8128 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8129 | if (auto *ToTemplate = |
| 8130 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
| 8131 | return ToContext.getQualifiedTemplateName(Qualifier, |
| 8132 | QTN->hasTemplateKeyword(), |
| 8133 | ToTemplate); |
| 8134 | |
| 8135 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8136 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8137 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8138 | case TemplateName::DependentTemplate: { |
| 8139 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8140 | NestedNameSpecifier *Qualifier = Import(DTN->getQualifier()); |
| 8141 | if (!Qualifier) |
| 8142 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8143 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8144 | if (DTN->isIdentifier()) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8145 | return ToContext.getDependentTemplateName(Qualifier, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8146 | Import(DTN->getIdentifier())); |
| 8147 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8148 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8149 | return ToContext.getDependentTemplateName(Qualifier, DTN->getOperator()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8150 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8151 | |
| 8152 | case TemplateName::SubstTemplateTemplateParm: { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8153 | SubstTemplateTemplateParmStorage *subst |
| 8154 | = From.getAsSubstTemplateTemplateParm(); |
| 8155 | auto *param = |
| 8156 | cast_or_null<TemplateTemplateParmDecl>(Import(subst->getParameter())); |
| 8157 | if (!param) |
| 8158 | return {}; |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8159 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8160 | TemplateName replacement = Import(subst->getReplacement()); |
| 8161 | if (replacement.isNull()) |
| 8162 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8163 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8164 | return ToContext.getSubstTemplateTemplateParm(param, replacement); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8165 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8166 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8167 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 8168 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 8169 | = From.getAsSubstTemplateTemplateParmPack(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8170 | auto *Param = |
| 8171 | cast_or_null<TemplateTemplateParmDecl>( |
| 8172 | Import(SubstPack->getParameterPack())); |
| 8173 | if (!Param) |
| 8174 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8175 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8176 | ASTNodeImporter Importer(*this); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8177 | Expected<TemplateArgument> ArgPack |
| 8178 | = Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
| 8179 | if (!ArgPack) { |
| 8180 | llvm::consumeError(ArgPack.takeError()); |
| 8181 | return {}; |
| 8182 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8183 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8184 | return ToContext.getSubstTemplateTemplateParmPack(Param, *ArgPack); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8185 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8186 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8187 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8188 | llvm_unreachable("Invalid template name kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8189 | } |
| 8190 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8191 | Expected<SourceLocation> ASTImporter::Import_New(SourceLocation FromLoc) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8192 | SourceLocation ToLoc = Import(FromLoc); |
| 8193 | if (ToLoc.isInvalid() && !FromLoc.isInvalid()) |
| 8194 | return llvm::make_error<ImportError>(); |
| 8195 | return ToLoc; |
| 8196 | } |
| 8197 | SourceLocation ASTImporter::Import(SourceLocation FromLoc) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8198 | if (FromLoc.isInvalid()) |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8199 | return {}; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8200 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8201 | SourceManager &FromSM = FromContext.getSourceManager(); |
Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8202 | bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8203 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8204 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8205 | FileID ToFileID = Import(Decomposed.first, IsBuiltin); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8206 | if (ToFileID.isInvalid()) |
| 8207 | return {}; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8208 | SourceManager &ToSM = ToContext.getSourceManager(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8209 | return ToSM.getComposedLoc(ToFileID, Decomposed.second); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8210 | } |
| 8211 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8212 | Expected<SourceRange> ASTImporter::Import_New(SourceRange FromRange) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8213 | SourceRange ToRange = Import(FromRange); |
| 8214 | return ToRange; |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8215 | } |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8216 | SourceRange ASTImporter::Import(SourceRange FromRange) { |
| 8217 | return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd())); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8218 | } |
| 8219 | |
Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8220 | Expected<FileID> ASTImporter::Import_New(FileID FromID, bool IsBuiltin) { |
| 8221 | FileID ToID = Import(FromID, IsBuiltin); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8222 | if (ToID.isInvalid() && FromID.isValid()) |
| 8223 | return llvm::make_error<ImportError>(); |
| 8224 | return ToID; |
| 8225 | } |
Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8226 | FileID ASTImporter::Import(FileID FromID, bool IsBuiltin) { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8227 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8228 | if (Pos != ImportedFileIDs.end()) |
| 8229 | return Pos->second; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8230 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8231 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 8232 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 8233 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8234 | |
| 8235 | // Map the FromID to the "to" source manager. |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8236 | FileID ToID; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8237 | if (FromSLoc.isExpansion()) { |
| 8238 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8239 | SourceLocation ToSpLoc = Import(FromEx.getSpellingLoc()); |
| 8240 | SourceLocation ToExLocS = Import(FromEx.getExpansionLocStart()); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8241 | unsigned TokenLen = FromSM.getFileIDSize(FromID); |
| 8242 | SourceLocation MLoc; |
| 8243 | if (FromEx.isMacroArgExpansion()) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8244 | MLoc = ToSM.createMacroArgExpansionLoc(ToSpLoc, ToExLocS, TokenLen); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8245 | } else { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8246 | SourceLocation ToExLocE = Import(FromEx.getExpansionLocEnd()); |
| 8247 | MLoc = ToSM.createExpansionLoc(ToSpLoc, ToExLocS, ToExLocE, TokenLen, |
| 8248 | FromEx.isExpansionTokenRange()); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8249 | } |
| 8250 | ToID = ToSM.getFileID(MLoc); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8251 | } else { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8252 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8253 | |
| 8254 | if (!IsBuiltin) { |
| 8255 | // Include location of this file. |
| 8256 | SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); |
| 8257 | |
| 8258 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
| 8259 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 8260 | // disk again |
| 8261 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 8262 | // than mmap the files several times. |
| 8263 | const FileEntry *Entry = |
| 8264 | ToFileManager.getFile(Cache->OrigEntry->getName()); |
| 8265 | // FIXME: The filename may be a virtual name that does probably not |
| 8266 | // point to a valid file and we get no Entry here. In this case try with |
| 8267 | // the memory buffer below. |
| 8268 | if (Entry) |
| 8269 | ToID = ToSM.createFileID(Entry, ToIncludeLoc, |
| 8270 | FromSLoc.getFile().getFileCharacteristic()); |
| 8271 | } |
Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8272 | } |
Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8273 | |
| 8274 | if (ToID.isInvalid() || IsBuiltin) { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8275 | // FIXME: We want to re-use the existing MemoryBuffer! |
Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8276 | bool Invalid = true; |
| 8277 | const llvm::MemoryBuffer *FromBuf = Cache->getBuffer( |
| 8278 | FromContext.getDiagnostics(), FromSM, SourceLocation{}, &Invalid); |
| 8279 | if (!FromBuf || Invalid) |
| 8280 | return {}; |
| 8281 | |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8282 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = |
| 8283 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
| 8284 | FromBuf->getBufferIdentifier()); |
| 8285 | ToID = ToSM.createFileID(std::move(ToBuf), |
| 8286 | FromSLoc.getFile().getFileCharacteristic()); |
| 8287 | } |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8288 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8289 | |
Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8290 | assert(ToID.isValid() && "Unexpected invalid fileID was created."); |
| 8291 | |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 8292 | ImportedFileIDs[FromID] = ToID; |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8293 | return ToID; |
| 8294 | } |
| 8295 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8296 | Expected<CXXCtorInitializer *> |
| 8297 | ASTImporter::Import_New(CXXCtorInitializer *From) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8298 | CXXCtorInitializer *To = Import(From); |
| 8299 | if (!To && From) |
| 8300 | return llvm::make_error<ImportError>(); |
| 8301 | return To; |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8302 | } |
Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 8303 | CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8304 | Expr *ToExpr = Import(From->getInit()); |
| 8305 | if (!ToExpr && From->getInit()) |
| 8306 | return nullptr; |
| 8307 | |
| 8308 | if (From->isBaseInitializer()) { |
| 8309 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 8310 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 8311 | return nullptr; |
| 8312 | |
| 8313 | return new (ToContext) CXXCtorInitializer( |
| 8314 | ToContext, ToTInfo, From->isBaseVirtual(), Import(From->getLParenLoc()), |
| 8315 | ToExpr, Import(From->getRParenLoc()), |
| 8316 | From->isPackExpansion() ? Import(From->getEllipsisLoc()) |
| 8317 | : SourceLocation()); |
| 8318 | } else if (From->isMemberInitializer()) { |
| 8319 | auto *ToField = cast_or_null<FieldDecl>(Import(From->getMember())); |
| 8320 | if (!ToField && From->getMember()) |
| 8321 | return nullptr; |
| 8322 | |
| 8323 | return new (ToContext) CXXCtorInitializer( |
| 8324 | ToContext, ToField, Import(From->getMemberLocation()), |
| 8325 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 8326 | } else if (From->isIndirectMemberInitializer()) { |
| 8327 | auto *ToIField = cast_or_null<IndirectFieldDecl>( |
| 8328 | Import(From->getIndirectMember())); |
| 8329 | if (!ToIField && From->getIndirectMember()) |
| 8330 | return nullptr; |
| 8331 | |
| 8332 | return new (ToContext) CXXCtorInitializer( |
| 8333 | ToContext, ToIField, Import(From->getMemberLocation()), |
| 8334 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 8335 | } else if (From->isDelegatingInitializer()) { |
| 8336 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 8337 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 8338 | return nullptr; |
| 8339 | |
| 8340 | return new (ToContext) |
| 8341 | CXXCtorInitializer(ToContext, ToTInfo, Import(From->getLParenLoc()), |
| 8342 | ToExpr, Import(From->getRParenLoc())); |
| 8343 | } else { |
| 8344 | return nullptr; |
| 8345 | } |
Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 8346 | } |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8347 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8348 | Expected<CXXBaseSpecifier *> |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8349 | ASTImporter::Import_New(const CXXBaseSpecifier *From) { |
| 8350 | CXXBaseSpecifier *To = Import(From); |
| 8351 | if (!To && From) |
| 8352 | return llvm::make_error<ImportError>(); |
| 8353 | return To; |
| 8354 | } |
| 8355 | CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8356 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 8357 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 8358 | return Pos->second; |
| 8359 | |
| 8360 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8361 | Import(BaseSpec->getSourceRange()), |
| 8362 | BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 8363 | BaseSpec->getAccessSpecifierAsWritten(), |
| 8364 | Import(BaseSpec->getTypeSourceInfo()), |
| 8365 | Import(BaseSpec->getEllipsisLoc())); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8366 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 8367 | return Imported; |
| 8368 | } |
| 8369 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8370 | Error ASTImporter::ImportDefinition_New(Decl *From) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8371 | Decl *To = Import(From); |
| 8372 | if (!To) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8373 | return llvm::make_error<ImportError>(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8374 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8375 | if (auto *FromDC = cast<DeclContext>(From)) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8376 | ASTNodeImporter Importer(*this); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8377 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8378 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 8379 | if (!ToRecord->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8380 | return Importer.ImportDefinition( |
| 8381 | cast<RecordDecl>(FromDC), ToRecord, |
| 8382 | ASTNodeImporter::IDK_Everything); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8383 | } |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 8384 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8385 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8386 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8387 | if (!ToEnum->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8388 | return Importer.ImportDefinition( |
| 8389 | cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8390 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8391 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8392 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8393 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 8394 | if (!ToIFace->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8395 | return Importer.ImportDefinition( |
| 8396 | cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
| 8397 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 8398 | } |
| 8399 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8400 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8401 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 8402 | if (!ToProto->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8403 | return Importer.ImportDefinition( |
| 8404 | cast<ObjCProtocolDecl>(FromDC), ToProto, |
| 8405 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 8406 | } |
| 8407 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8408 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8409 | return Importer.ImportDeclContext(FromDC, true); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8410 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8411 | |
| 8412 | return Error::success(); |
| 8413 | } |
| 8414 | |
| 8415 | void ASTImporter::ImportDefinition(Decl *From) { |
| 8416 | Error Err = ImportDefinition_New(From); |
| 8417 | llvm::consumeError(std::move(Err)); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8418 | } |
| 8419 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8420 | Expected<DeclarationName> ASTImporter::Import_New(DeclarationName FromName) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8421 | DeclarationName ToName = Import(FromName); |
| 8422 | if (!ToName && FromName) |
| 8423 | return llvm::make_error<ImportError>(); |
| 8424 | return ToName; |
| 8425 | } |
| 8426 | DeclarationName ASTImporter::Import(DeclarationName FromName) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8427 | if (!FromName) |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8428 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8429 | |
| 8430 | switch (FromName.getNameKind()) { |
| 8431 | case DeclarationName::Identifier: |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8432 | return Import(FromName.getAsIdentifierInfo()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8433 | |
| 8434 | case DeclarationName::ObjCZeroArgSelector: |
| 8435 | case DeclarationName::ObjCOneArgSelector: |
| 8436 | case DeclarationName::ObjCMultiArgSelector: |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8437 | return Import(FromName.getObjCSelector()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8438 | |
| 8439 | case DeclarationName::CXXConstructorName: { |
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.getCXXConstructorName( |
| 8445 | ToContext.getCanonicalType(T)); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8446 | } |
| 8447 | |
| 8448 | case DeclarationName::CXXDestructorName: { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8449 | QualType T = Import(FromName.getCXXNameType()); |
| 8450 | if (T.isNull()) |
| 8451 | return {}; |
| 8452 | |
| 8453 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 8454 | ToContext.getCanonicalType(T)); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8455 | } |
| 8456 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8457 | case DeclarationName::CXXDeductionGuideName: { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8458 | auto *Template = cast_or_null<TemplateDecl>( |
| 8459 | Import(FromName.getCXXDeductionGuideTemplate())); |
| 8460 | if (!Template) |
| 8461 | return {}; |
| 8462 | return ToContext.DeclarationNames.getCXXDeductionGuideName(Template); |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8463 | } |
| 8464 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8465 | case DeclarationName::CXXConversionFunctionName: { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8466 | QualType T = Import(FromName.getCXXNameType()); |
| 8467 | if (T.isNull()) |
| 8468 | return {}; |
| 8469 | |
| 8470 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 8471 | ToContext.getCanonicalType(T)); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8472 | } |
| 8473 | |
| 8474 | case DeclarationName::CXXOperatorName: |
| 8475 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 8476 | FromName.getCXXOverloadedOperator()); |
| 8477 | |
| 8478 | case DeclarationName::CXXLiteralOperatorName: |
| 8479 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8480 | Import(FromName.getCXXLiteralIdentifier())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8481 | |
| 8482 | case DeclarationName::CXXUsingDirective: |
| 8483 | // FIXME: STATICS! |
| 8484 | return DeclarationName::getUsingDirectiveName(); |
| 8485 | } |
| 8486 | |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 8487 | llvm_unreachable("Invalid DeclarationName Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8488 | } |
| 8489 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8490 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8491 | if (!FromId) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8492 | return nullptr; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8493 | |
Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 8494 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 8495 | |
| 8496 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 8497 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 8498 | |
| 8499 | return ToId; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8500 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8501 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8502 | Expected<Selector> ASTImporter::Import_New(Selector FromSel) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8503 | Selector ToSel = Import(FromSel); |
| 8504 | if (ToSel.isNull() && !FromSel.isNull()) |
| 8505 | return llvm::make_error<ImportError>(); |
| 8506 | return ToSel; |
| 8507 | } |
| 8508 | Selector ASTImporter::Import(Selector FromSel) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8509 | if (FromSel.isNull()) |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8510 | return {}; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8511 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 8512 | SmallVector<IdentifierInfo *, 4> Idents; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8513 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 8514 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 8515 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 8516 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 8517 | } |
| 8518 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8519 | DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, |
| 8520 | DeclContext *DC, |
| 8521 | unsigned IDNS, |
| 8522 | NamedDecl **Decls, |
| 8523 | unsigned NumDecls) { |
| 8524 | return Name; |
| 8525 | } |
| 8526 | |
| 8527 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8528 | if (LastDiagFromFrom) |
| 8529 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8530 | FromContext.getDiagnostics()); |
| 8531 | LastDiagFromFrom = false; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8532 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8533 | } |
| 8534 | |
| 8535 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8536 | if (!LastDiagFromFrom) |
| 8537 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8538 | ToContext.getDiagnostics()); |
| 8539 | LastDiagFromFrom = true; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8540 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8541 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8542 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8543 | void ASTImporter::CompleteDecl (Decl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8544 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8545 | if (!ID->getDefinition()) |
| 8546 | ID->startDefinition(); |
| 8547 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8548 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8549 | if (!PD->getDefinition()) |
| 8550 | PD->startDefinition(); |
| 8551 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8552 | else if (auto *TD = dyn_cast<TagDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8553 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 8554 | TD->startDefinition(); |
| 8555 | TD->setCompleteDefinition(true); |
| 8556 | } |
| 8557 | } |
| 8558 | else { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8559 | assert(0 && "CompleteDecl called on a Decl that can't be completed"); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8560 | } |
| 8561 | } |
| 8562 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8563 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { |
| 8564 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); |
| 8565 | assert((Pos == ImportedDecls.end() || Pos->second == To) && |
| 8566 | "Try to import an already imported Decl"); |
| 8567 | if (Pos != ImportedDecls.end()) |
| 8568 | return Pos->second; |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8569 | ImportedDecls[From] = To; |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 8570 | // This mapping should be maintained only in this function. Therefore do not |
| 8571 | // check for additional consistency. |
| 8572 | ImportedFromDecls[To] = From; |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8573 | return To; |
Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 8574 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8575 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8576 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 8577 | bool Complain) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 8578 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8579 | = ImportedTypes.find(From.getTypePtr()); |
| 8580 | if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To)) |
| 8581 | return true; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 8582 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8583 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8584 | getStructuralEquivalenceKind(*this), false, |
| 8585 | Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 8586 | return Ctx.IsEquivalent(From, To); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8587 | } |