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 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 137 | class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>, |
| 138 | public DeclVisitor<ASTNodeImporter, ExpectedDecl>, |
| 139 | public StmtVisitor<ASTNodeImporter, ExpectedStmt> { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 140 | ASTImporter &Importer; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 141 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 142 | // Use this instead of Importer.importInto . |
| 143 | template <typename ImportT> |
| 144 | LLVM_NODISCARD Error importInto(ImportT &To, const ImportT &From) { |
| 145 | return Importer.importInto(To, From); |
| 146 | } |
| 147 | |
| 148 | // Use this to import pointers of specific type. |
| 149 | template <typename ImportT> |
| 150 | LLVM_NODISCARD Error importInto(ImportT *&To, ImportT *From) { |
Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 151 | auto ToOrErr = Importer.Import_New(From); |
| 152 | if (ToOrErr) |
| 153 | To = cast_or_null<ImportT>(*ToOrErr); |
| 154 | return ToOrErr.takeError(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | // Call the import function of ASTImporter for a baseclass of type `T` and |
| 158 | // cast the return value to `T`. |
| 159 | template <typename T> |
| 160 | Expected<T *> import(T *From) { |
Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 161 | auto ToOrErr = Importer.Import_New(From); |
| 162 | if (!ToOrErr) |
| 163 | return ToOrErr.takeError(); |
| 164 | return cast_or_null<T>(*ToOrErr); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | template <typename T> |
| 168 | Expected<T *> import(const T *From) { |
| 169 | return import(const_cast<T *>(From)); |
| 170 | } |
| 171 | |
| 172 | // Call the import function of ASTImporter for type `T`. |
| 173 | template <typename T> |
| 174 | Expected<T> import(const T &From) { |
Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 175 | return Importer.Import_New(From); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | template <class T> |
| 179 | Expected<std::tuple<T>> |
| 180 | importSeq(const T &From) { |
| 181 | Expected<T> ToOrErr = import(From); |
| 182 | if (!ToOrErr) |
| 183 | return ToOrErr.takeError(); |
| 184 | return std::make_tuple<T>(std::move(*ToOrErr)); |
| 185 | } |
| 186 | |
| 187 | // Import multiple objects with a single function call. |
| 188 | // This should work for every type for which a variant of `import` exists. |
| 189 | // The arguments are processed from left to right and import is stopped on |
| 190 | // first error. |
| 191 | template <class THead, class... TTail> |
| 192 | Expected<std::tuple<THead, TTail...>> |
| 193 | importSeq(const THead &FromHead, const TTail &...FromTail) { |
| 194 | Expected<std::tuple<THead>> ToHeadOrErr = importSeq(FromHead); |
| 195 | if (!ToHeadOrErr) |
| 196 | return ToHeadOrErr.takeError(); |
| 197 | Expected<std::tuple<TTail...>> ToTailOrErr = importSeq(FromTail...); |
| 198 | if (!ToTailOrErr) |
| 199 | return ToTailOrErr.takeError(); |
| 200 | return std::tuple_cat(*ToHeadOrErr, *ToTailOrErr); |
| 201 | } |
| 202 | |
| 203 | // Wrapper for an overload set. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 204 | template <typename ToDeclT> struct CallOverloadedCreateFun { |
| 205 | template <typename... Args> |
| 206 | auto operator()(Args &&... args) |
| 207 | -> decltype(ToDeclT::Create(std::forward<Args>(args)...)) { |
| 208 | return ToDeclT::Create(std::forward<Args>(args)...); |
| 209 | } |
| 210 | }; |
| 211 | |
| 212 | // Always use these functions to create a Decl during import. There are |
| 213 | // certain tasks which must be done after the Decl was created, e.g. we |
| 214 | // must immediately register that as an imported Decl. The parameter `ToD` |
| 215 | // will be set to the newly created Decl or if had been imported before |
| 216 | // then to the already imported Decl. Returns a bool value set to true if |
| 217 | // the `FromD` had been imported before. |
| 218 | template <typename ToDeclT, typename FromDeclT, typename... Args> |
| 219 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, |
| 220 | Args &&... args) { |
| 221 | // There may be several overloads of ToDeclT::Create. We must make sure |
| 222 | // to call the one which would be chosen by the arguments, thus we use a |
| 223 | // wrapper for the overload set. |
| 224 | CallOverloadedCreateFun<ToDeclT> OC; |
| 225 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, |
| 226 | std::forward<Args>(args)...); |
| 227 | } |
| 228 | // Use this overload if a special Type is needed to be created. E.g if we |
| 229 | // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl` |
| 230 | // then: |
| 231 | // TypedefNameDecl *ToTypedef; |
| 232 | // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...); |
| 233 | template <typename NewDeclT, typename ToDeclT, typename FromDeclT, |
| 234 | typename... Args> |
| 235 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, |
| 236 | Args &&... args) { |
| 237 | CallOverloadedCreateFun<NewDeclT> OC; |
| 238 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, |
| 239 | std::forward<Args>(args)...); |
| 240 | } |
| 241 | // Use this version if a special create function must be |
| 242 | // used, e.g. CXXRecordDecl::CreateLambda . |
| 243 | template <typename ToDeclT, typename CreateFunT, typename FromDeclT, |
| 244 | typename... Args> |
| 245 | LLVM_NODISCARD bool |
| 246 | GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun, |
| 247 | FromDeclT *FromD, Args &&... args) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 248 | // FIXME: This code is needed later. |
| 249 | //if (Importer.getImportDeclErrorIfAny(FromD)) { |
| 250 | // ToD = nullptr; |
| 251 | // return true; // Already imported but with error. |
| 252 | //} |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 253 | ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD)); |
| 254 | if (ToD) |
| 255 | return true; // Already imported. |
| 256 | ToD = CreateFun(std::forward<Args>(args)...); |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 257 | // Keep track of imported Decls. |
| 258 | Importer.MapImported(FromD, ToD); |
| 259 | Importer.AddToLookupTable(ToD); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 260 | InitializeImportedDecl(FromD, ToD); |
| 261 | return false; // A new Decl is created. |
| 262 | } |
| 263 | |
| 264 | void InitializeImportedDecl(Decl *FromD, Decl *ToD) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 265 | ToD->IdentifierNamespace = FromD->IdentifierNamespace; |
| 266 | if (FromD->hasAttrs()) |
Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 267 | for (const Attr *FromAttr : FromD->getAttrs()) { |
| 268 | // FIXME: Return of the error here is not possible until store of |
| 269 | // import errors is implemented. |
| 270 | auto ToAttrOrErr = import(FromAttr); |
| 271 | if (ToAttrOrErr) |
| 272 | ToD->addAttr(*ToAttrOrErr); |
| 273 | else |
| 274 | llvm::consumeError(ToAttrOrErr.takeError()); |
| 275 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 276 | if (FromD->isUsed()) |
| 277 | ToD->setIsUsed(); |
| 278 | if (FromD->isImplicit()) |
| 279 | ToD->setImplicit(); |
| 280 | } |
| 281 | |
Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 282 | // Check if we have found an existing definition. Returns with that |
| 283 | // definition if yes, otherwise returns null. |
| 284 | Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) { |
| 285 | const FunctionDecl *Definition = nullptr; |
| 286 | if (D->doesThisDeclarationHaveABody() && |
| 287 | FoundFunction->hasBody(Definition)) |
| 288 | return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition)); |
| 289 | return nullptr; |
| 290 | } |
| 291 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 292 | public: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 293 | explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {} |
Gabor Marton | 344b099 | 2018-05-16 11:48:11 +0000 | [diff] [blame] | 294 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 295 | using TypeVisitor<ASTNodeImporter, ExpectedType>::Visit; |
| 296 | using DeclVisitor<ASTNodeImporter, ExpectedDecl>::Visit; |
| 297 | using StmtVisitor<ASTNodeImporter, ExpectedStmt>::Visit; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 298 | |
| 299 | // Importing types |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 300 | ExpectedType VisitType(const Type *T); |
| 301 | ExpectedType VisitAtomicType(const AtomicType *T); |
| 302 | ExpectedType VisitBuiltinType(const BuiltinType *T); |
| 303 | ExpectedType VisitDecayedType(const DecayedType *T); |
| 304 | ExpectedType VisitComplexType(const ComplexType *T); |
| 305 | ExpectedType VisitPointerType(const PointerType *T); |
| 306 | ExpectedType VisitBlockPointerType(const BlockPointerType *T); |
| 307 | ExpectedType VisitLValueReferenceType(const LValueReferenceType *T); |
| 308 | ExpectedType VisitRValueReferenceType(const RValueReferenceType *T); |
| 309 | ExpectedType VisitMemberPointerType(const MemberPointerType *T); |
| 310 | ExpectedType VisitConstantArrayType(const ConstantArrayType *T); |
| 311 | ExpectedType VisitIncompleteArrayType(const IncompleteArrayType *T); |
| 312 | ExpectedType VisitVariableArrayType(const VariableArrayType *T); |
| 313 | ExpectedType VisitDependentSizedArrayType(const DependentSizedArrayType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 314 | // FIXME: DependentSizedExtVectorType |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 315 | ExpectedType VisitVectorType(const VectorType *T); |
| 316 | ExpectedType VisitExtVectorType(const ExtVectorType *T); |
| 317 | ExpectedType VisitFunctionNoProtoType(const FunctionNoProtoType *T); |
| 318 | ExpectedType VisitFunctionProtoType(const FunctionProtoType *T); |
| 319 | ExpectedType VisitUnresolvedUsingType(const UnresolvedUsingType *T); |
| 320 | ExpectedType VisitParenType(const ParenType *T); |
| 321 | ExpectedType VisitTypedefType(const TypedefType *T); |
| 322 | ExpectedType VisitTypeOfExprType(const TypeOfExprType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 323 | // FIXME: DependentTypeOfExprType |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 324 | ExpectedType VisitTypeOfType(const TypeOfType *T); |
| 325 | ExpectedType VisitDecltypeType(const DecltypeType *T); |
| 326 | ExpectedType VisitUnaryTransformType(const UnaryTransformType *T); |
| 327 | ExpectedType VisitAutoType(const AutoType *T); |
| 328 | ExpectedType VisitInjectedClassNameType(const InjectedClassNameType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 329 | // FIXME: DependentDecltypeType |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 330 | ExpectedType VisitRecordType(const RecordType *T); |
| 331 | ExpectedType VisitEnumType(const EnumType *T); |
| 332 | ExpectedType VisitAttributedType(const AttributedType *T); |
| 333 | ExpectedType VisitTemplateTypeParmType(const TemplateTypeParmType *T); |
| 334 | ExpectedType VisitSubstTemplateTypeParmType( |
| 335 | const SubstTemplateTypeParmType *T); |
| 336 | ExpectedType VisitTemplateSpecializationType( |
| 337 | const TemplateSpecializationType *T); |
| 338 | ExpectedType VisitElaboratedType(const ElaboratedType *T); |
| 339 | ExpectedType VisitDependentNameType(const DependentNameType *T); |
| 340 | ExpectedType VisitPackExpansionType(const PackExpansionType *T); |
| 341 | ExpectedType VisitDependentTemplateSpecializationType( |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 342 | const DependentTemplateSpecializationType *T); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 343 | ExpectedType VisitObjCInterfaceType(const ObjCInterfaceType *T); |
| 344 | ExpectedType VisitObjCObjectType(const ObjCObjectType *T); |
| 345 | ExpectedType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); |
Rafael Stahl | df55620 | 2018-05-29 08:12:15 +0000 | [diff] [blame] | 346 | |
| 347 | // Importing declarations |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 348 | Error ImportDeclParts( |
| 349 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, |
| 350 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc); |
| 351 | Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr); |
| 352 | Error ImportDeclarationNameLoc( |
| 353 | const DeclarationNameInfo &From, DeclarationNameInfo &To); |
| 354 | Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); |
| 355 | Error ImportDeclContext( |
| 356 | Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC); |
| 357 | Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 358 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 359 | Expected<CXXCastPath> ImportCastPath(CastExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 360 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 361 | using Designator = DesignatedInitExpr::Designator; |
| 362 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 363 | /// What we should import from the definition. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 364 | enum ImportDefinitionKind { |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 365 | /// Import the default subset of the definition, which might be |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 366 | /// nothing (if minimal import is set) or might be everything (if minimal |
| 367 | /// import is not set). |
| 368 | IDK_Default, |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 369 | /// Import everything. |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 370 | IDK_Everything, |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 371 | /// Import only the bare bones needed to establish a valid |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 372 | /// DeclContext. |
| 373 | IDK_Basic |
| 374 | }; |
| 375 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 376 | bool shouldForceImportDeclContext(ImportDefinitionKind IDK) { |
| 377 | return IDK == IDK_Everything || |
| 378 | (IDK == IDK_Default && !Importer.isMinimalImport()); |
| 379 | } |
| 380 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 381 | Error ImportInitializer(VarDecl *From, VarDecl *To); |
| 382 | Error ImportDefinition( |
| 383 | RecordDecl *From, RecordDecl *To, |
| 384 | ImportDefinitionKind Kind = IDK_Default); |
| 385 | Error ImportDefinition( |
| 386 | EnumDecl *From, EnumDecl *To, |
| 387 | ImportDefinitionKind Kind = IDK_Default); |
| 388 | Error ImportDefinition( |
| 389 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, |
| 390 | ImportDefinitionKind Kind = IDK_Default); |
| 391 | Error ImportDefinition( |
| 392 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, |
| 393 | ImportDefinitionKind Kind = IDK_Default); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 394 | Error ImportTemplateArguments( |
| 395 | const TemplateArgument *FromArgs, unsigned NumFromArgs, |
| 396 | SmallVectorImpl<TemplateArgument> &ToArgs); |
| 397 | Expected<TemplateArgument> |
| 398 | ImportTemplateArgument(const TemplateArgument &From); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 399 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 400 | template <typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 401 | Error ImportTemplateArgumentListInfo( |
| 402 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 403 | |
| 404 | template<typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 405 | Error ImportTemplateArgumentListInfo( |
| 406 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 407 | const InContainerTy &Container, TemplateArgumentListInfo &Result); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 408 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 409 | using TemplateArgsTy = SmallVector<TemplateArgument, 8>; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 410 | using FunctionTemplateAndArgsTy = |
| 411 | std::tuple<FunctionTemplateDecl *, TemplateArgsTy>; |
| 412 | Expected<FunctionTemplateAndArgsTy> |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 413 | ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 414 | FunctionDecl *FromFD); |
| 415 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 416 | Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 417 | |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 418 | Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD); |
| 419 | |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 420 | template <typename T> |
| 421 | bool hasSameVisibilityContext(T *Found, T *From); |
| 422 | |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 423 | bool IsStructuralMatch(Decl *From, Decl *To, bool Complain); |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 424 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, |
| 425 | bool Complain = true); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 426 | bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 427 | bool Complain = true); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 428 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 429 | bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 430 | bool IsStructuralMatch(FunctionTemplateDecl *From, |
| 431 | FunctionTemplateDecl *To); |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 432 | bool IsStructuralMatch(FunctionDecl *From, FunctionDecl *To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 433 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 434 | bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 435 | ExpectedDecl VisitDecl(Decl *D); |
| 436 | ExpectedDecl VisitImportDecl(ImportDecl *D); |
| 437 | ExpectedDecl VisitEmptyDecl(EmptyDecl *D); |
| 438 | ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D); |
| 439 | ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D); |
| 440 | ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D); |
| 441 | ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D); |
| 442 | ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
| 443 | ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); |
| 444 | ExpectedDecl VisitTypedefDecl(TypedefDecl *D); |
| 445 | ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D); |
| 446 | ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); |
| 447 | ExpectedDecl VisitLabelDecl(LabelDecl *D); |
| 448 | ExpectedDecl VisitEnumDecl(EnumDecl *D); |
| 449 | ExpectedDecl VisitRecordDecl(RecordDecl *D); |
| 450 | ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D); |
| 451 | ExpectedDecl VisitFunctionDecl(FunctionDecl *D); |
| 452 | ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D); |
| 453 | ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 454 | ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 455 | ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D); |
| 456 | ExpectedDecl VisitFieldDecl(FieldDecl *D); |
| 457 | ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D); |
| 458 | ExpectedDecl VisitFriendDecl(FriendDecl *D); |
| 459 | ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D); |
| 460 | ExpectedDecl VisitVarDecl(VarDecl *D); |
| 461 | ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D); |
| 462 | ExpectedDecl VisitParmVarDecl(ParmVarDecl *D); |
| 463 | ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D); |
| 464 | ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
| 465 | ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| 466 | ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| 467 | ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D); |
| 468 | ExpectedDecl VisitUsingDecl(UsingDecl *D); |
| 469 | ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D); |
| 470 | ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 471 | ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
| 472 | ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 473 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 474 | Expected<ObjCTypeParamList *> |
| 475 | ImportObjCTypeParamList(ObjCTypeParamList *list); |
| 476 | |
| 477 | ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
| 478 | ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| 479 | ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| 480 | ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| 481 | ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
| 482 | ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
| 483 | ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 484 | ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
| 485 | ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D); |
| 486 | ExpectedDecl VisitClassTemplateSpecializationDecl( |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 487 | ClassTemplateSpecializationDecl *D); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 488 | ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D); |
| 489 | ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); |
| 490 | ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 491 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 492 | // Importing statements |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 493 | ExpectedStmt VisitStmt(Stmt *S); |
| 494 | ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S); |
| 495 | ExpectedStmt VisitDeclStmt(DeclStmt *S); |
| 496 | ExpectedStmt VisitNullStmt(NullStmt *S); |
| 497 | ExpectedStmt VisitCompoundStmt(CompoundStmt *S); |
| 498 | ExpectedStmt VisitCaseStmt(CaseStmt *S); |
| 499 | ExpectedStmt VisitDefaultStmt(DefaultStmt *S); |
| 500 | ExpectedStmt VisitLabelStmt(LabelStmt *S); |
| 501 | ExpectedStmt VisitAttributedStmt(AttributedStmt *S); |
| 502 | ExpectedStmt VisitIfStmt(IfStmt *S); |
| 503 | ExpectedStmt VisitSwitchStmt(SwitchStmt *S); |
| 504 | ExpectedStmt VisitWhileStmt(WhileStmt *S); |
| 505 | ExpectedStmt VisitDoStmt(DoStmt *S); |
| 506 | ExpectedStmt VisitForStmt(ForStmt *S); |
| 507 | ExpectedStmt VisitGotoStmt(GotoStmt *S); |
| 508 | ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S); |
| 509 | ExpectedStmt VisitContinueStmt(ContinueStmt *S); |
| 510 | ExpectedStmt VisitBreakStmt(BreakStmt *S); |
| 511 | ExpectedStmt VisitReturnStmt(ReturnStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 512 | // FIXME: MSAsmStmt |
| 513 | // FIXME: SEHExceptStmt |
| 514 | // FIXME: SEHFinallyStmt |
| 515 | // FIXME: SEHTryStmt |
| 516 | // FIXME: SEHLeaveStmt |
| 517 | // FIXME: CapturedStmt |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 518 | ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S); |
| 519 | ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S); |
| 520 | ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 521 | // FIXME: MSDependentExistsStmt |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 522 | ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); |
| 523 | ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); |
| 524 | ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); |
| 525 | ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S); |
| 526 | ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); |
| 527 | ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); |
| 528 | ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 529 | |
| 530 | // Importing expressions |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 531 | ExpectedStmt VisitExpr(Expr *E); |
| 532 | ExpectedStmt VisitVAArgExpr(VAArgExpr *E); |
Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 533 | ExpectedStmt VisitChooseExpr(ChooseExpr *E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 534 | ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E); |
| 535 | ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E); |
| 536 | ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E); |
| 537 | ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E); |
| 538 | ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E); |
| 539 | ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); |
| 540 | ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E); |
| 541 | ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E); |
| 542 | ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E); |
| 543 | ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E); |
| 544 | ExpectedStmt VisitStringLiteral(StringLiteral *E); |
| 545 | ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
| 546 | ExpectedStmt VisitAtomicExpr(AtomicExpr *E); |
| 547 | ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E); |
Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 548 | ExpectedStmt VisitConstantExpr(ConstantExpr *E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 549 | ExpectedStmt VisitParenExpr(ParenExpr *E); |
| 550 | ExpectedStmt VisitParenListExpr(ParenListExpr *E); |
| 551 | ExpectedStmt VisitStmtExpr(StmtExpr *E); |
| 552 | ExpectedStmt VisitUnaryOperator(UnaryOperator *E); |
| 553 | ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); |
| 554 | ExpectedStmt VisitBinaryOperator(BinaryOperator *E); |
| 555 | ExpectedStmt VisitConditionalOperator(ConditionalOperator *E); |
| 556 | ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E); |
| 557 | ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E); |
| 558 | ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); |
| 559 | ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E); |
| 560 | ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
| 561 | ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E); |
| 562 | ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E); |
| 563 | ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 564 | ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE); |
| 565 | ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E); |
| 566 | ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E); |
| 567 | ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); |
| 568 | ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); |
| 569 | ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); |
| 570 | ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E); |
| 571 | ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); |
| 572 | ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E); |
| 573 | ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E); |
| 574 | ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E); |
| 575 | ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E); |
| 576 | ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E); |
| 577 | ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E); |
| 578 | ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); |
| 579 | ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E); |
| 580 | ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E); |
| 581 | ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); |
| 582 | ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E); |
| 583 | ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E); |
| 584 | ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E); |
| 585 | ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); |
| 586 | ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); |
| 587 | ExpectedStmt VisitMemberExpr(MemberExpr *E); |
| 588 | ExpectedStmt VisitCallExpr(CallExpr *E); |
| 589 | ExpectedStmt VisitLambdaExpr(LambdaExpr *LE); |
| 590 | ExpectedStmt VisitInitListExpr(InitListExpr *E); |
| 591 | ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E); |
| 592 | ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E); |
| 593 | ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); |
| 594 | ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); |
| 595 | ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); |
| 596 | ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E); |
| 597 | ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); |
| 598 | ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E); |
| 599 | ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 600 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 601 | template<typename IIter, typename OIter> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 602 | Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 603 | using ItemT = typename std::remove_reference<decltype(*Obegin)>::type; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 604 | for (; Ibegin != Iend; ++Ibegin, ++Obegin) { |
| 605 | Expected<ItemT> ToOrErr = import(*Ibegin); |
| 606 | if (!ToOrErr) |
| 607 | return ToOrErr.takeError(); |
| 608 | *Obegin = *ToOrErr; |
| 609 | } |
| 610 | return Error::success(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 611 | } |
| 612 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 613 | // Import every item from a container structure into an output container. |
| 614 | // If error occurs, stops at first error and returns the error. |
| 615 | // The output container should have space for all needed elements (it is not |
| 616 | // expanded, new items are put into from the beginning). |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 617 | template<typename InContainerTy, typename OutContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 618 | Error ImportContainerChecked( |
| 619 | const InContainerTy &InContainer, OutContainerTy &OutContainer) { |
| 620 | return ImportArrayChecked( |
| 621 | InContainer.begin(), InContainer.end(), OutContainer.begin()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | template<typename InContainerTy, typename OIter> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 625 | Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 626 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); |
| 627 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 628 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 629 | void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 630 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 631 | Expected<FunctionDecl *> FindFunctionTemplateSpecialization( |
| 632 | FunctionDecl *FromFD); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 633 | }; |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 634 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 635 | template <typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 636 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 637 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 638 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 639 | auto ToLAngleLocOrErr = import(FromLAngleLoc); |
| 640 | if (!ToLAngleLocOrErr) |
| 641 | return ToLAngleLocOrErr.takeError(); |
| 642 | auto ToRAngleLocOrErr = import(FromRAngleLoc); |
| 643 | if (!ToRAngleLocOrErr) |
| 644 | return ToRAngleLocOrErr.takeError(); |
| 645 | |
| 646 | TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr); |
| 647 | if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo)) |
| 648 | return Err; |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 649 | Result = ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 650 | return Error::success(); |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 651 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 652 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 653 | template <> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 654 | Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 655 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { |
| 656 | return ImportTemplateArgumentListInfo( |
| 657 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); |
| 658 | } |
| 659 | |
| 660 | template <> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 661 | Error ASTNodeImporter::ImportTemplateArgumentListInfo< |
| 662 | ASTTemplateArgumentListInfo>( |
| 663 | const ASTTemplateArgumentListInfo &From, |
| 664 | TemplateArgumentListInfo &Result) { |
| 665 | return ImportTemplateArgumentListInfo( |
| 666 | From.LAngleLoc, From.RAngleLoc, From.arguments(), Result); |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 667 | } |
| 668 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 669 | Expected<ASTNodeImporter::FunctionTemplateAndArgsTy> |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 670 | ASTNodeImporter::ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 671 | FunctionDecl *FromFD) { |
| 672 | assert(FromFD->getTemplatedKind() == |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 673 | FunctionDecl::TK_FunctionTemplateSpecialization); |
| 674 | |
| 675 | FunctionTemplateAndArgsTy Result; |
| 676 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 677 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 678 | if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate())) |
| 679 | return std::move(Err); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 680 | |
| 681 | // Import template arguments. |
| 682 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 683 | if (Error Err = ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), |
| 684 | std::get<1>(Result))) |
| 685 | return std::move(Err); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 686 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 687 | return Result; |
| 688 | } |
| 689 | |
| 690 | template <> |
| 691 | Expected<TemplateParameterList *> |
| 692 | ASTNodeImporter::import(TemplateParameterList *From) { |
| 693 | SmallVector<NamedDecl *, 4> To(From->size()); |
| 694 | if (Error Err = ImportContainerChecked(*From, To)) |
| 695 | return std::move(Err); |
| 696 | |
| 697 | ExpectedExpr ToRequiresClause = import(From->getRequiresClause()); |
| 698 | if (!ToRequiresClause) |
| 699 | return ToRequiresClause.takeError(); |
| 700 | |
| 701 | auto ToTemplateLocOrErr = import(From->getTemplateLoc()); |
| 702 | if (!ToTemplateLocOrErr) |
| 703 | return ToTemplateLocOrErr.takeError(); |
| 704 | auto ToLAngleLocOrErr = import(From->getLAngleLoc()); |
| 705 | if (!ToLAngleLocOrErr) |
| 706 | return ToLAngleLocOrErr.takeError(); |
| 707 | auto ToRAngleLocOrErr = import(From->getRAngleLoc()); |
| 708 | if (!ToRAngleLocOrErr) |
| 709 | return ToRAngleLocOrErr.takeError(); |
| 710 | |
| 711 | return TemplateParameterList::Create( |
| 712 | Importer.getToContext(), |
| 713 | *ToTemplateLocOrErr, |
| 714 | *ToLAngleLocOrErr, |
| 715 | To, |
| 716 | *ToRAngleLocOrErr, |
| 717 | *ToRequiresClause); |
| 718 | } |
| 719 | |
| 720 | template <> |
| 721 | Expected<TemplateArgument> |
| 722 | ASTNodeImporter::import(const TemplateArgument &From) { |
| 723 | switch (From.getKind()) { |
| 724 | case TemplateArgument::Null: |
| 725 | return TemplateArgument(); |
| 726 | |
| 727 | case TemplateArgument::Type: { |
| 728 | ExpectedType ToTypeOrErr = import(From.getAsType()); |
| 729 | if (!ToTypeOrErr) |
| 730 | return ToTypeOrErr.takeError(); |
| 731 | return TemplateArgument(*ToTypeOrErr); |
| 732 | } |
| 733 | |
| 734 | case TemplateArgument::Integral: { |
| 735 | ExpectedType ToTypeOrErr = import(From.getIntegralType()); |
| 736 | if (!ToTypeOrErr) |
| 737 | return ToTypeOrErr.takeError(); |
| 738 | return TemplateArgument(From, *ToTypeOrErr); |
| 739 | } |
| 740 | |
| 741 | case TemplateArgument::Declaration: { |
| 742 | Expected<ValueDecl *> ToOrErr = import(From.getAsDecl()); |
| 743 | if (!ToOrErr) |
| 744 | return ToOrErr.takeError(); |
| 745 | ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl()); |
| 746 | if (!ToTypeOrErr) |
| 747 | return ToTypeOrErr.takeError(); |
| 748 | return TemplateArgument(*ToOrErr, *ToTypeOrErr); |
| 749 | } |
| 750 | |
| 751 | case TemplateArgument::NullPtr: { |
| 752 | ExpectedType ToTypeOrErr = import(From.getNullPtrType()); |
| 753 | if (!ToTypeOrErr) |
| 754 | return ToTypeOrErr.takeError(); |
| 755 | return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true); |
| 756 | } |
| 757 | |
| 758 | case TemplateArgument::Template: { |
| 759 | Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate()); |
| 760 | if (!ToTemplateOrErr) |
| 761 | return ToTemplateOrErr.takeError(); |
| 762 | |
| 763 | return TemplateArgument(*ToTemplateOrErr); |
| 764 | } |
| 765 | |
| 766 | case TemplateArgument::TemplateExpansion: { |
| 767 | Expected<TemplateName> ToTemplateOrErr = |
| 768 | import(From.getAsTemplateOrTemplatePattern()); |
| 769 | if (!ToTemplateOrErr) |
| 770 | return ToTemplateOrErr.takeError(); |
| 771 | |
| 772 | return TemplateArgument( |
| 773 | *ToTemplateOrErr, From.getNumTemplateExpansions()); |
| 774 | } |
| 775 | |
| 776 | case TemplateArgument::Expression: |
| 777 | if (ExpectedExpr ToExpr = import(From.getAsExpr())) |
| 778 | return TemplateArgument(*ToExpr); |
| 779 | else |
| 780 | return ToExpr.takeError(); |
| 781 | |
| 782 | case TemplateArgument::Pack: { |
| 783 | SmallVector<TemplateArgument, 2> ToPack; |
| 784 | ToPack.reserve(From.pack_size()); |
| 785 | if (Error Err = ImportTemplateArguments( |
| 786 | From.pack_begin(), From.pack_size(), ToPack)) |
| 787 | return std::move(Err); |
| 788 | |
| 789 | return TemplateArgument( |
| 790 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | llvm_unreachable("Invalid template argument kind"); |
| 795 | } |
| 796 | |
| 797 | template <> |
| 798 | Expected<TemplateArgumentLoc> |
| 799 | ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) { |
| 800 | Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument()); |
| 801 | if (!ArgOrErr) |
| 802 | return ArgOrErr.takeError(); |
| 803 | TemplateArgument Arg = *ArgOrErr; |
| 804 | |
| 805 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); |
| 806 | |
| 807 | TemplateArgumentLocInfo ToInfo; |
| 808 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 809 | ExpectedExpr E = import(FromInfo.getAsExpr()); |
| 810 | if (!E) |
| 811 | return E.takeError(); |
| 812 | ToInfo = TemplateArgumentLocInfo(*E); |
| 813 | } else if (Arg.getKind() == TemplateArgument::Type) { |
| 814 | if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo())) |
| 815 | ToInfo = TemplateArgumentLocInfo(*TSIOrErr); |
| 816 | else |
| 817 | return TSIOrErr.takeError(); |
| 818 | } else { |
| 819 | auto ToTemplateQualifierLocOrErr = |
| 820 | import(FromInfo.getTemplateQualifierLoc()); |
| 821 | if (!ToTemplateQualifierLocOrErr) |
| 822 | return ToTemplateQualifierLocOrErr.takeError(); |
| 823 | auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc()); |
| 824 | if (!ToTemplateNameLocOrErr) |
| 825 | return ToTemplateNameLocOrErr.takeError(); |
| 826 | auto ToTemplateEllipsisLocOrErr = |
| 827 | import(FromInfo.getTemplateEllipsisLoc()); |
| 828 | if (!ToTemplateEllipsisLocOrErr) |
| 829 | return ToTemplateEllipsisLocOrErr.takeError(); |
| 830 | |
| 831 | ToInfo = TemplateArgumentLocInfo( |
| 832 | *ToTemplateQualifierLocOrErr, |
| 833 | *ToTemplateNameLocOrErr, |
| 834 | *ToTemplateEllipsisLocOrErr); |
| 835 | } |
| 836 | |
| 837 | return TemplateArgumentLoc(Arg, ToInfo); |
| 838 | } |
| 839 | |
| 840 | template <> |
| 841 | Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) { |
| 842 | if (DG.isNull()) |
| 843 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); |
| 844 | size_t NumDecls = DG.end() - DG.begin(); |
| 845 | SmallVector<Decl *, 1> ToDecls; |
| 846 | ToDecls.reserve(NumDecls); |
| 847 | for (Decl *FromD : DG) { |
| 848 | if (auto ToDOrErr = import(FromD)) |
| 849 | ToDecls.push_back(*ToDOrErr); |
| 850 | else |
| 851 | return ToDOrErr.takeError(); |
| 852 | } |
| 853 | return DeclGroupRef::Create(Importer.getToContext(), |
| 854 | ToDecls.begin(), |
| 855 | NumDecls); |
| 856 | } |
| 857 | |
| 858 | template <> |
| 859 | Expected<ASTNodeImporter::Designator> |
| 860 | ASTNodeImporter::import(const Designator &D) { |
| 861 | if (D.isFieldDesignator()) { |
| 862 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); |
| 863 | |
| 864 | ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc()); |
| 865 | if (!ToDotLocOrErr) |
| 866 | return ToDotLocOrErr.takeError(); |
| 867 | |
| 868 | ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc()); |
| 869 | if (!ToFieldLocOrErr) |
| 870 | return ToFieldLocOrErr.takeError(); |
| 871 | |
| 872 | return Designator(ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr); |
| 873 | } |
| 874 | |
| 875 | ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc()); |
| 876 | if (!ToLBracketLocOrErr) |
| 877 | return ToLBracketLocOrErr.takeError(); |
| 878 | |
| 879 | ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc()); |
| 880 | if (!ToRBracketLocOrErr) |
| 881 | return ToRBracketLocOrErr.takeError(); |
| 882 | |
| 883 | if (D.isArrayDesignator()) |
| 884 | return Designator(D.getFirstExprIndex(), |
| 885 | *ToLBracketLocOrErr, *ToRBracketLocOrErr); |
| 886 | |
| 887 | ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc()); |
| 888 | if (!ToEllipsisLocOrErr) |
| 889 | return ToEllipsisLocOrErr.takeError(); |
| 890 | |
| 891 | assert(D.isArrayRangeDesignator()); |
| 892 | return Designator( |
| 893 | D.getFirstExprIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr, |
| 894 | *ToRBracketLocOrErr); |
| 895 | } |
| 896 | |
| 897 | template <> |
| 898 | Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) { |
| 899 | VarDecl *Var = nullptr; |
| 900 | if (From.capturesVariable()) { |
| 901 | if (auto VarOrErr = import(From.getCapturedVar())) |
| 902 | Var = *VarOrErr; |
| 903 | else |
| 904 | return VarOrErr.takeError(); |
| 905 | } |
| 906 | |
| 907 | auto LocationOrErr = import(From.getLocation()); |
| 908 | if (!LocationOrErr) |
| 909 | return LocationOrErr.takeError(); |
| 910 | |
| 911 | SourceLocation EllipsisLoc; |
| 912 | if (From.isPackExpansion()) |
| 913 | if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc())) |
| 914 | return std::move(Err); |
| 915 | |
| 916 | return LambdaCapture( |
| 917 | *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var, |
| 918 | EllipsisLoc); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 919 | } |
| 920 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 921 | } // namespace clang |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 922 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 923 | //---------------------------------------------------------------------------- |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 924 | // Import Types |
| 925 | //---------------------------------------------------------------------------- |
| 926 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 927 | using namespace clang; |
| 928 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 929 | ExpectedType ASTNodeImporter::VisitType(const Type *T) { |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 930 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) |
| 931 | << T->getTypeClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 932 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 933 | } |
| 934 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 935 | ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ |
| 936 | ExpectedType UnderlyingTypeOrErr = import(T->getValueType()); |
| 937 | if (!UnderlyingTypeOrErr) |
| 938 | return UnderlyingTypeOrErr.takeError(); |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 939 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 940 | return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr); |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 941 | } |
| 942 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 943 | ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 944 | switch (T->getKind()) { |
Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 945 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 946 | case BuiltinType::Id: \ |
| 947 | return Importer.getToContext().SingletonId; |
Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 948 | #include "clang/Basic/OpenCLImageTypes.def" |
Andrew Savonichev | 3fee351 | 2018-11-08 11:25:41 +0000 | [diff] [blame] | 949 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ |
| 950 | case BuiltinType::Id: \ |
| 951 | return Importer.getToContext().Id##Ty; |
| 952 | #include "clang/Basic/OpenCLExtensionTypes.def" |
John McCall | e314e27 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 953 | #define SHARED_SINGLETON_TYPE(Expansion) |
| 954 | #define BUILTIN_TYPE(Id, SingletonId) \ |
| 955 | case BuiltinType::Id: return Importer.getToContext().SingletonId; |
| 956 | #include "clang/AST/BuiltinTypes.def" |
| 957 | |
| 958 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" |
| 959 | // context supports C++. |
| 960 | |
| 961 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" |
| 962 | // context supports ObjC. |
| 963 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 964 | case BuiltinType::Char_U: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 965 | // The context we're importing from has an unsigned 'char'. If we're |
| 966 | // importing into a context with a signed 'char', translate to |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 967 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 968 | if (Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 969 | return Importer.getToContext().UnsignedCharTy; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 970 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 971 | return Importer.getToContext().CharTy; |
| 972 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 973 | case BuiltinType::Char_S: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 974 | // The context we're importing from has an unsigned 'char'. If we're |
| 975 | // importing into a context with a signed 'char', translate to |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 976 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 977 | if (!Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 978 | return Importer.getToContext().SignedCharTy; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 979 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 980 | return Importer.getToContext().CharTy; |
| 981 | |
Chris Lattner | ad3467e | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 982 | case BuiltinType::WChar_S: |
| 983 | case BuiltinType::WChar_U: |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 984 | // FIXME: If not in C++, shall we translate to the C equivalent of |
| 985 | // wchar_t? |
| 986 | return Importer.getToContext().WCharTy; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 987 | } |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 988 | |
| 989 | llvm_unreachable("Invalid BuiltinType Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 990 | } |
| 991 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 992 | ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { |
| 993 | ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType()); |
| 994 | if (!ToOriginalTypeOrErr) |
| 995 | return ToOriginalTypeOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 996 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 997 | return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 998 | } |
| 999 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1000 | ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) { |
| 1001 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1002 | if (!ToElementTypeOrErr) |
| 1003 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1004 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1005 | return Importer.getToContext().getComplexType(*ToElementTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1008 | ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) { |
| 1009 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1010 | if (!ToPointeeTypeOrErr) |
| 1011 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1012 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1013 | return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1014 | } |
| 1015 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1016 | ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1017 | // FIXME: Check for blocks support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1018 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1019 | if (!ToPointeeTypeOrErr) |
| 1020 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1021 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1022 | return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1025 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1026 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1027 | // FIXME: Check for C++ support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1028 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); |
| 1029 | if (!ToPointeeTypeOrErr) |
| 1030 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1031 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1032 | return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1033 | } |
| 1034 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1035 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1036 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1037 | // FIXME: Check for C++0x support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1038 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); |
| 1039 | if (!ToPointeeTypeOrErr) |
| 1040 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1041 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1042 | return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1043 | } |
| 1044 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1045 | ExpectedType |
| 1046 | ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1047 | // FIXME: Check for C++ support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1048 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1049 | if (!ToPointeeTypeOrErr) |
| 1050 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1051 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1052 | ExpectedType ClassTypeOrErr = import(QualType(T->getClass(), 0)); |
| 1053 | if (!ClassTypeOrErr) |
| 1054 | return ClassTypeOrErr.takeError(); |
| 1055 | |
| 1056 | return Importer.getToContext().getMemberPointerType( |
| 1057 | *ToPointeeTypeOrErr, (*ClassTypeOrErr).getTypePtr()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1058 | } |
| 1059 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1060 | ExpectedType |
| 1061 | ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { |
| 1062 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1063 | if (!ToElementTypeOrErr) |
| 1064 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1065 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1066 | return Importer.getToContext().getConstantArrayType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1067 | T->getSize(), |
| 1068 | T->getSizeModifier(), |
| 1069 | T->getIndexTypeCVRQualifiers()); |
| 1070 | } |
| 1071 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1072 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1073 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1074 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1075 | if (!ToElementTypeOrErr) |
| 1076 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1077 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1078 | return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1079 | T->getSizeModifier(), |
| 1080 | T->getIndexTypeCVRQualifiers()); |
| 1081 | } |
| 1082 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1083 | ExpectedType |
| 1084 | ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { |
| 1085 | QualType ToElementType; |
| 1086 | Expr *ToSizeExpr; |
| 1087 | SourceRange ToBracketsRange; |
| 1088 | if (auto Imp = importSeq( |
| 1089 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) |
| 1090 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; |
| 1091 | else |
| 1092 | return Imp.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1093 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1094 | return Importer.getToContext().getVariableArrayType( |
| 1095 | ToElementType, ToSizeExpr, T->getSizeModifier(), |
| 1096 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1097 | } |
| 1098 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1099 | ExpectedType ASTNodeImporter::VisitDependentSizedArrayType( |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1100 | const DependentSizedArrayType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1101 | QualType ToElementType; |
| 1102 | Expr *ToSizeExpr; |
| 1103 | SourceRange ToBracketsRange; |
| 1104 | if (auto Imp = importSeq( |
| 1105 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) |
| 1106 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; |
| 1107 | else |
| 1108 | return Imp.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1109 | // SizeExpr may be null if size is not specified directly. |
| 1110 | // For example, 'int a[]'. |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1111 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1112 | return Importer.getToContext().getDependentSizedArrayType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1113 | ToElementType, ToSizeExpr, T->getSizeModifier(), |
| 1114 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1115 | } |
| 1116 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1117 | ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) { |
| 1118 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1119 | if (!ToElementTypeOrErr) |
| 1120 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1121 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1122 | return Importer.getToContext().getVectorType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1123 | T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 1124 | T->getVectorKind()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1127 | ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { |
| 1128 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1129 | if (!ToElementTypeOrErr) |
| 1130 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1131 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1132 | return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1133 | T->getNumElements()); |
| 1134 | } |
| 1135 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1136 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1137 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1138 | // FIXME: What happens if we're importing a function without a prototype |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1139 | // into C++? Should we make it variadic? |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1140 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); |
| 1141 | if (!ToReturnTypeOrErr) |
| 1142 | return ToReturnTypeOrErr.takeError(); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1143 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1144 | return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr, |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1145 | T->getExtInfo()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1146 | } |
| 1147 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1148 | ExpectedType |
| 1149 | ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { |
| 1150 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); |
| 1151 | if (!ToReturnTypeOrErr) |
| 1152 | return ToReturnTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1153 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1154 | // Import argument types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1155 | SmallVector<QualType, 4> ArgTypes; |
Aaron Ballman | 40bd0aa | 2014-03-17 15:23:01 +0000 | [diff] [blame] | 1156 | for (const auto &A : T->param_types()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1157 | ExpectedType TyOrErr = import(A); |
| 1158 | if (!TyOrErr) |
| 1159 | return TyOrErr.takeError(); |
| 1160 | ArgTypes.push_back(*TyOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1161 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1162 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1163 | // Import exception types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1164 | SmallVector<QualType, 4> ExceptionTypes; |
Aaron Ballman | b088fbe | 2014-03-17 15:38:09 +0000 | [diff] [blame] | 1165 | for (const auto &E : T->exceptions()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1166 | ExpectedType TyOrErr = import(E); |
| 1167 | if (!TyOrErr) |
| 1168 | return TyOrErr.takeError(); |
| 1169 | ExceptionTypes.push_back(*TyOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1170 | } |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 1171 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1172 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); |
| 1173 | FunctionProtoType::ExtProtoInfo ToEPI; |
| 1174 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1175 | auto Imp = importSeq( |
| 1176 | FromEPI.ExceptionSpec.NoexceptExpr, |
| 1177 | FromEPI.ExceptionSpec.SourceDecl, |
| 1178 | FromEPI.ExceptionSpec.SourceTemplate); |
| 1179 | if (!Imp) |
| 1180 | return Imp.takeError(); |
| 1181 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1182 | ToEPI.ExtInfo = FromEPI.ExtInfo; |
| 1183 | ToEPI.Variadic = FromEPI.Variadic; |
| 1184 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; |
| 1185 | ToEPI.TypeQuals = FromEPI.TypeQuals; |
| 1186 | ToEPI.RefQualifier = FromEPI.RefQualifier; |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 1187 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; |
| 1188 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1189 | std::tie( |
| 1190 | ToEPI.ExceptionSpec.NoexceptExpr, |
| 1191 | ToEPI.ExceptionSpec.SourceDecl, |
| 1192 | ToEPI.ExceptionSpec.SourceTemplate) = *Imp; |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1193 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1194 | return Importer.getToContext().getFunctionType( |
| 1195 | *ToReturnTypeOrErr, ArgTypes, ToEPI); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1196 | } |
| 1197 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1198 | ExpectedType ASTNodeImporter::VisitUnresolvedUsingType( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1199 | const UnresolvedUsingType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1200 | UnresolvedUsingTypenameDecl *ToD; |
| 1201 | Decl *ToPrevD; |
| 1202 | if (auto Imp = importSeq(T->getDecl(), T->getDecl()->getPreviousDecl())) |
| 1203 | std::tie(ToD, ToPrevD) = *Imp; |
| 1204 | else |
| 1205 | return Imp.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1206 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1207 | return Importer.getToContext().getTypeDeclType( |
| 1208 | ToD, cast_or_null<TypeDecl>(ToPrevD)); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1211 | ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) { |
| 1212 | ExpectedType ToInnerTypeOrErr = import(T->getInnerType()); |
| 1213 | if (!ToInnerTypeOrErr) |
| 1214 | return ToInnerTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1215 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1216 | return Importer.getToContext().getParenType(*ToInnerTypeOrErr); |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1219 | ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { |
| 1220 | Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1221 | if (!ToDeclOrErr) |
| 1222 | return ToDeclOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1223 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1224 | return Importer.getToContext().getTypeDeclType(*ToDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1225 | } |
| 1226 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1227 | ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { |
| 1228 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); |
| 1229 | if (!ToExprOrErr) |
| 1230 | return ToExprOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1231 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1232 | return Importer.getToContext().getTypeOfExprType(*ToExprOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1235 | ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { |
| 1236 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1237 | if (!ToUnderlyingTypeOrErr) |
| 1238 | return ToUnderlyingTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1239 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1240 | return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1241 | } |
| 1242 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1243 | ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1244 | // FIXME: Make sure that the "to" context supports C++0x! |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1245 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); |
| 1246 | if (!ToExprOrErr) |
| 1247 | return ToExprOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1248 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1249 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1250 | if (!ToUnderlyingTypeOrErr) |
| 1251 | return ToUnderlyingTypeOrErr.takeError(); |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 1252 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1253 | return Importer.getToContext().getDecltypeType( |
| 1254 | *ToExprOrErr, *ToUnderlyingTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1255 | } |
| 1256 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1257 | ExpectedType |
| 1258 | ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 1259 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); |
| 1260 | if (!ToBaseTypeOrErr) |
| 1261 | return ToBaseTypeOrErr.takeError(); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1262 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1263 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1264 | if (!ToUnderlyingTypeOrErr) |
| 1265 | return ToUnderlyingTypeOrErr.takeError(); |
| 1266 | |
| 1267 | return Importer.getToContext().getUnaryTransformType( |
| 1268 | *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind()); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1269 | } |
| 1270 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1271 | ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 1272 | // FIXME: Make sure that the "to" context supports C++11! |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1273 | ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType()); |
| 1274 | if (!ToDeducedTypeOrErr) |
| 1275 | return ToDeducedTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1276 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1277 | return Importer.getToContext().getAutoType(*ToDeducedTypeOrErr, |
| 1278 | T->getKeyword(), |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 1279 | /*IsDependent*/false); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1282 | ExpectedType ASTNodeImporter::VisitInjectedClassNameType( |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1283 | const InjectedClassNameType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1284 | Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1285 | if (!ToDeclOrErr) |
| 1286 | return ToDeclOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1287 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1288 | ExpectedType ToInjTypeOrErr = import(T->getInjectedSpecializationType()); |
| 1289 | if (!ToInjTypeOrErr) |
| 1290 | return ToInjTypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1291 | |
| 1292 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading |
| 1293 | // See comments in InjectedClassNameType definition for details |
| 1294 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); |
| 1295 | enum { |
| 1296 | TypeAlignmentInBits = 4, |
| 1297 | TypeAlignment = 1 << TypeAlignmentInBits |
| 1298 | }; |
| 1299 | |
| 1300 | return QualType(new (Importer.getToContext(), TypeAlignment) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1301 | InjectedClassNameType(*ToDeclOrErr, *ToInjTypeOrErr), 0); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1302 | } |
| 1303 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1304 | ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) { |
| 1305 | Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1306 | if (!ToDeclOrErr) |
| 1307 | return ToDeclOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1308 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1309 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1310 | } |
| 1311 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1312 | ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) { |
| 1313 | Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1314 | if (!ToDeclOrErr) |
| 1315 | return ToDeclOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1316 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1317 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1318 | } |
| 1319 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1320 | ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { |
| 1321 | ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType()); |
| 1322 | if (!ToModifiedTypeOrErr) |
| 1323 | return ToModifiedTypeOrErr.takeError(); |
| 1324 | ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType()); |
| 1325 | if (!ToEquivalentTypeOrErr) |
| 1326 | return ToEquivalentTypeOrErr.takeError(); |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1327 | |
| 1328 | return Importer.getToContext().getAttributedType(T->getAttrKind(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1329 | *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr); |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1330 | } |
| 1331 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1332 | ExpectedType ASTNodeImporter::VisitTemplateTypeParmType( |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1333 | const TemplateTypeParmType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1334 | Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1335 | if (!ToDeclOrErr) |
| 1336 | return ToDeclOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1337 | |
| 1338 | return Importer.getToContext().getTemplateTypeParmType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1339 | T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1340 | } |
| 1341 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1342 | ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType( |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1343 | const SubstTemplateTypeParmType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1344 | ExpectedType ReplacedOrErr = import(QualType(T->getReplacedParameter(), 0)); |
| 1345 | if (!ReplacedOrErr) |
| 1346 | return ReplacedOrErr.takeError(); |
| 1347 | const TemplateTypeParmType *Replaced = |
| 1348 | cast<TemplateTypeParmType>((*ReplacedOrErr).getTypePtr()); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1349 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1350 | ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType()); |
| 1351 | if (!ToReplacementTypeOrErr) |
| 1352 | return ToReplacementTypeOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1353 | |
| 1354 | return Importer.getToContext().getSubstTemplateTypeParmType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1355 | Replaced, (*ToReplacementTypeOrErr).getCanonicalType()); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1356 | } |
| 1357 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1358 | ExpectedType ASTNodeImporter::VisitTemplateSpecializationType( |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1359 | const TemplateSpecializationType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1360 | auto ToTemplateOrErr = import(T->getTemplateName()); |
| 1361 | if (!ToTemplateOrErr) |
| 1362 | return ToTemplateOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1363 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1364 | SmallVector<TemplateArgument, 2> ToTemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1365 | if (Error Err = ImportTemplateArguments( |
| 1366 | T->getArgs(), T->getNumArgs(), ToTemplateArgs)) |
| 1367 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1368 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1369 | QualType ToCanonType; |
| 1370 | if (!QualType(T, 0).isCanonical()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1371 | QualType FromCanonType |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1372 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1373 | if (ExpectedType TyOrErr = import(FromCanonType)) |
| 1374 | ToCanonType = *TyOrErr; |
| 1375 | else |
| 1376 | return TyOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1377 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1378 | return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr, |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 1379 | ToTemplateArgs, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1380 | ToCanonType); |
| 1381 | } |
| 1382 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1383 | ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1384 | // Note: the qualifier in an ElaboratedType is optional. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1385 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1386 | if (!ToQualifierOrErr) |
| 1387 | return ToQualifierOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1388 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1389 | ExpectedType ToNamedTypeOrErr = import(T->getNamedType()); |
| 1390 | if (!ToNamedTypeOrErr) |
| 1391 | return ToNamedTypeOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1392 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1393 | Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl()); |
| 1394 | if (!ToOwnedTagDeclOrErr) |
| 1395 | return ToOwnedTagDeclOrErr.takeError(); |
Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 1396 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1397 | return Importer.getToContext().getElaboratedType(T->getKeyword(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1398 | *ToQualifierOrErr, |
| 1399 | *ToNamedTypeOrErr, |
| 1400 | *ToOwnedTagDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1401 | } |
| 1402 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1403 | ExpectedType |
| 1404 | ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { |
| 1405 | ExpectedType ToPatternOrErr = import(T->getPattern()); |
| 1406 | if (!ToPatternOrErr) |
| 1407 | return ToPatternOrErr.takeError(); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1408 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1409 | return Importer.getToContext().getPackExpansionType(*ToPatternOrErr, |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1410 | T->getNumExpansions()); |
| 1411 | } |
| 1412 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1413 | ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType( |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1414 | const DependentTemplateSpecializationType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1415 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1416 | if (!ToQualifierOrErr) |
| 1417 | return ToQualifierOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1418 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1419 | IdentifierInfo *ToName = Importer.Import(T->getIdentifier()); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1420 | |
| 1421 | SmallVector<TemplateArgument, 2> ToPack; |
| 1422 | ToPack.reserve(T->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1423 | if (Error Err = ImportTemplateArguments( |
| 1424 | T->getArgs(), T->getNumArgs(), ToPack)) |
| 1425 | return std::move(Err); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1426 | |
| 1427 | return Importer.getToContext().getDependentTemplateSpecializationType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1428 | T->getKeyword(), *ToQualifierOrErr, ToName, ToPack); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1429 | } |
| 1430 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1431 | ExpectedType |
| 1432 | ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) { |
| 1433 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1434 | if (!ToQualifierOrErr) |
| 1435 | return ToQualifierOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1436 | |
| 1437 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1438 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1439 | QualType Canon; |
| 1440 | if (T != T->getCanonicalTypeInternal().getTypePtr()) { |
| 1441 | if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal())) |
| 1442 | Canon = (*TyOrErr).getCanonicalType(); |
| 1443 | else |
| 1444 | return TyOrErr.takeError(); |
| 1445 | } |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1446 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1447 | return Importer.getToContext().getDependentNameType(T->getKeyword(), |
| 1448 | *ToQualifierOrErr, |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1449 | Name, Canon); |
| 1450 | } |
| 1451 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1452 | ExpectedType |
| 1453 | ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
| 1454 | Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1455 | if (!ToDeclOrErr) |
| 1456 | return ToDeclOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1457 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1458 | return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1459 | } |
| 1460 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1461 | ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { |
| 1462 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); |
| 1463 | if (!ToBaseTypeOrErr) |
| 1464 | return ToBaseTypeOrErr.takeError(); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1465 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1466 | SmallVector<QualType, 4> TypeArgs; |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 1467 | for (auto TypeArg : T->getTypeArgsAsWritten()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1468 | if (ExpectedType TyOrErr = import(TypeArg)) |
| 1469 | TypeArgs.push_back(*TyOrErr); |
| 1470 | else |
| 1471 | return TyOrErr.takeError(); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1472 | } |
| 1473 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1474 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 1475 | for (auto *P : T->quals()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1476 | if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P)) |
| 1477 | Protocols.push_back(*ProtocolOrErr); |
| 1478 | else |
| 1479 | return ProtocolOrErr.takeError(); |
| 1480 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1483 | return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs, |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 1484 | Protocols, |
| 1485 | T->isKindOfTypeAsWritten()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1486 | } |
| 1487 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1488 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1489 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1490 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1491 | if (!ToPointeeTypeOrErr) |
| 1492 | return ToPointeeTypeOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1493 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1494 | return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1495 | } |
| 1496 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 1497 | //---------------------------------------------------------------------------- |
| 1498 | // Import Declarations |
| 1499 | //---------------------------------------------------------------------------- |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1500 | Error ASTNodeImporter::ImportDeclParts( |
| 1501 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, |
| 1502 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) { |
Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1503 | // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop. |
| 1504 | // example: int struct_in_proto(struct data_t{int a;int b;} *d); |
| 1505 | DeclContext *OrigDC = D->getDeclContext(); |
| 1506 | FunctionDecl *FunDecl; |
| 1507 | if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) && |
| 1508 | FunDecl->hasBody()) { |
Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1509 | auto getLeafPointeeType = [](const Type *T) { |
| 1510 | while (T->isPointerType() || T->isArrayType()) { |
| 1511 | T = T->getPointeeOrArrayElementType(); |
| 1512 | } |
| 1513 | return T; |
| 1514 | }; |
| 1515 | for (const ParmVarDecl *P : FunDecl->parameters()) { |
| 1516 | const Type *LeafT = |
| 1517 | getLeafPointeeType(P->getType().getCanonicalType().getTypePtr()); |
| 1518 | auto *RT = dyn_cast<RecordType>(LeafT); |
| 1519 | if (RT && RT->getDecl() == D) { |
| 1520 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 1521 | << D->getDeclKindName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1522 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1523 | } |
Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1524 | } |
| 1525 | } |
| 1526 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1527 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1528 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 1529 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1530 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1531 | // Import the name of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1532 | if (Error Err = importInto(Name, D->getDeclName())) |
| 1533 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1534 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1535 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1536 | if (Error Err = importInto(Loc, D->getLocation())) |
| 1537 | return Err; |
| 1538 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1539 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); |
Gabor Marton | be77a98 | 2018-12-12 11:22:55 +0000 | [diff] [blame] | 1540 | if (ToD) |
| 1541 | if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD)) |
| 1542 | return Err; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1543 | |
| 1544 | return Error::success(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1545 | } |
| 1546 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1547 | Error ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1548 | if (!FromD) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1549 | return Error::success(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1550 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1551 | if (!ToD) |
| 1552 | if (Error Err = importInto(ToD, FromD)) |
| 1553 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1554 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1555 | if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) { |
| 1556 | if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) { |
| 1557 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && |
| 1558 | !ToRecord->getDefinition()) { |
| 1559 | if (Error Err = ImportDefinition(FromRecord, ToRecord)) |
| 1560 | return Err; |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1561 | } |
| 1562 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1563 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1564 | } |
| 1565 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1566 | if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) { |
| 1567 | if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1568 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1569 | if (Error Err = ImportDefinition(FromEnum, ToEnum)) |
| 1570 | return Err; |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1571 | } |
| 1572 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1573 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1574 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1575 | |
| 1576 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1577 | } |
| 1578 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1579 | Error |
| 1580 | ASTNodeImporter::ImportDeclarationNameLoc( |
| 1581 | const DeclarationNameInfo &From, DeclarationNameInfo& To) { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1582 | // NOTE: To.Name and To.Loc are already imported. |
| 1583 | // We only have to import To.LocInfo. |
| 1584 | switch (To.getName().getNameKind()) { |
| 1585 | case DeclarationName::Identifier: |
| 1586 | case DeclarationName::ObjCZeroArgSelector: |
| 1587 | case DeclarationName::ObjCOneArgSelector: |
| 1588 | case DeclarationName::ObjCMultiArgSelector: |
| 1589 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1590 | case DeclarationName::CXXDeductionGuideName: |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1591 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1592 | |
| 1593 | case DeclarationName::CXXOperatorName: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1594 | if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange())) |
| 1595 | To.setCXXOperatorNameRange(*ToRangeOrErr); |
| 1596 | else |
| 1597 | return ToRangeOrErr.takeError(); |
| 1598 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1599 | } |
| 1600 | case DeclarationName::CXXLiteralOperatorName: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1601 | if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc())) |
| 1602 | To.setCXXLiteralOperatorNameLoc(*LocOrErr); |
| 1603 | else |
| 1604 | return LocOrErr.takeError(); |
| 1605 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1606 | } |
| 1607 | case DeclarationName::CXXConstructorName: |
| 1608 | case DeclarationName::CXXDestructorName: |
| 1609 | case DeclarationName::CXXConversionFunctionName: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1610 | if (auto ToTInfoOrErr = import(From.getNamedTypeInfo())) |
| 1611 | To.setNamedTypeInfo(*ToTInfoOrErr); |
| 1612 | else |
| 1613 | return ToTInfoOrErr.takeError(); |
| 1614 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1615 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1616 | } |
Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 1617 | llvm_unreachable("Unknown name kind."); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1618 | } |
| 1619 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1620 | Error |
| 1621 | ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1622 | if (Importer.isMinimalImport() && !ForceImport) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1623 | auto ToDCOrErr = Importer.ImportContext(FromDC); |
| 1624 | return ToDCOrErr.takeError(); |
| 1625 | } |
Davide Italiano | 93a64ef | 2018-10-30 20:46:29 +0000 | [diff] [blame] | 1626 | llvm::SmallVector<Decl *, 8> ImportedDecls; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1627 | for (auto *From : FromDC->decls()) { |
| 1628 | ExpectedDecl ImportedOrErr = import(From); |
Davide Italiano | 93a64ef | 2018-10-30 20:46:29 +0000 | [diff] [blame] | 1629 | if (!ImportedOrErr) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1630 | // Ignore the error, continue with next Decl. |
| 1631 | // FIXME: Handle this case somehow better. |
Davide Italiano | 93a64ef | 2018-10-30 20:46:29 +0000 | [diff] [blame] | 1632 | consumeError(ImportedOrErr.takeError()); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1633 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1634 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1635 | return Error::success(); |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 1636 | } |
| 1637 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1638 | Error ASTNodeImporter::ImportDeclContext( |
| 1639 | Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) { |
| 1640 | auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext()); |
| 1641 | if (!ToDCOrErr) |
| 1642 | return ToDCOrErr.takeError(); |
| 1643 | ToDC = *ToDCOrErr; |
| 1644 | |
| 1645 | if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) { |
| 1646 | auto ToLexicalDCOrErr = Importer.ImportContext( |
| 1647 | FromD->getLexicalDeclContext()); |
| 1648 | if (!ToLexicalDCOrErr) |
| 1649 | return ToLexicalDCOrErr.takeError(); |
| 1650 | ToLexicalDC = *ToLexicalDCOrErr; |
| 1651 | } else |
| 1652 | ToLexicalDC = ToDC; |
| 1653 | |
| 1654 | return Error::success(); |
| 1655 | } |
| 1656 | |
| 1657 | Error ASTNodeImporter::ImportImplicitMethods( |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1658 | const CXXRecordDecl *From, CXXRecordDecl *To) { |
| 1659 | assert(From->isCompleteDefinition() && To->getDefinition() == To && |
| 1660 | "Import implicit methods to or from non-definition"); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1661 | |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1662 | for (CXXMethodDecl *FromM : From->methods()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1663 | if (FromM->isImplicit()) { |
| 1664 | Expected<CXXMethodDecl *> ToMOrErr = import(FromM); |
| 1665 | if (!ToMOrErr) |
| 1666 | return ToMOrErr.takeError(); |
| 1667 | } |
| 1668 | |
| 1669 | return Error::success(); |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1670 | } |
| 1671 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1672 | static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, |
| 1673 | ASTImporter &Importer) { |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1674 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { |
Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 1675 | if (ExpectedDecl ToTypedefOrErr = Importer.Import_New(FromTypedef)) |
| 1676 | To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr)); |
| 1677 | else |
| 1678 | return ToTypedefOrErr.takeError(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1679 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1680 | return Error::success(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1681 | } |
| 1682 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1683 | Error ASTNodeImporter::ImportDefinition( |
| 1684 | RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1685 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1686 | if (Kind == IDK_Everything) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1687 | return ImportDeclContext(From, /*ForceImport=*/true); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1688 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1689 | return Error::success(); |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1690 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1691 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1692 | To->startDefinition(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1693 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1694 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 1695 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1696 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1697 | // Add base classes. |
Gabor Marton | 17d3967 | 2018-11-26 15:54:08 +0000 | [diff] [blame] | 1698 | auto *ToCXX = dyn_cast<CXXRecordDecl>(To); |
| 1699 | auto *FromCXX = dyn_cast<CXXRecordDecl>(From); |
| 1700 | if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) { |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1701 | |
| 1702 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); |
| 1703 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); |
| 1704 | ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1705 | ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1706 | ToData.Aggregate = FromData.Aggregate; |
| 1707 | ToData.PlainOldData = FromData.PlainOldData; |
| 1708 | ToData.Empty = FromData.Empty; |
| 1709 | ToData.Polymorphic = FromData.Polymorphic; |
| 1710 | ToData.Abstract = FromData.Abstract; |
| 1711 | ToData.IsStandardLayout = FromData.IsStandardLayout; |
Richard Smith | b6070db | 2018-04-05 18:55:37 +0000 | [diff] [blame] | 1712 | ToData.IsCXX11StandardLayout = FromData.IsCXX11StandardLayout; |
| 1713 | ToData.HasBasesWithFields = FromData.HasBasesWithFields; |
| 1714 | ToData.HasBasesWithNonStaticDataMembers = |
| 1715 | FromData.HasBasesWithNonStaticDataMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1716 | ToData.HasPrivateFields = FromData.HasPrivateFields; |
| 1717 | ToData.HasProtectedFields = FromData.HasProtectedFields; |
| 1718 | ToData.HasPublicFields = FromData.HasPublicFields; |
| 1719 | ToData.HasMutableFields = FromData.HasMutableFields; |
Richard Smith | ab44d5b | 2013-12-10 08:25:00 +0000 | [diff] [blame] | 1720 | ToData.HasVariantMembers = FromData.HasVariantMembers; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1721 | ToData.HasOnlyCMembers = FromData.HasOnlyCMembers; |
Richard Smith | e2648ba | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 1722 | ToData.HasInClassInitializer = FromData.HasInClassInitializer; |
Richard Smith | 593f993 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 1723 | ToData.HasUninitializedReferenceMember |
| 1724 | = FromData.HasUninitializedReferenceMember; |
Nico Weber | 6a6376b | 2016-02-19 01:52:46 +0000 | [diff] [blame] | 1725 | ToData.HasUninitializedFields = FromData.HasUninitializedFields; |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 1726 | ToData.HasInheritedConstructor = FromData.HasInheritedConstructor; |
| 1727 | ToData.HasInheritedAssignment = FromData.HasInheritedAssignment; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1728 | ToData.NeedOverloadResolutionForCopyConstructor |
| 1729 | = FromData.NeedOverloadResolutionForCopyConstructor; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1730 | ToData.NeedOverloadResolutionForMoveConstructor |
| 1731 | = FromData.NeedOverloadResolutionForMoveConstructor; |
| 1732 | ToData.NeedOverloadResolutionForMoveAssignment |
| 1733 | = FromData.NeedOverloadResolutionForMoveAssignment; |
| 1734 | ToData.NeedOverloadResolutionForDestructor |
| 1735 | = FromData.NeedOverloadResolutionForDestructor; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1736 | ToData.DefaultedCopyConstructorIsDeleted |
| 1737 | = FromData.DefaultedCopyConstructorIsDeleted; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1738 | ToData.DefaultedMoveConstructorIsDeleted |
| 1739 | = FromData.DefaultedMoveConstructorIsDeleted; |
| 1740 | ToData.DefaultedMoveAssignmentIsDeleted |
| 1741 | = FromData.DefaultedMoveAssignmentIsDeleted; |
| 1742 | ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1743 | ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers; |
| 1744 | ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1745 | ToData.HasConstexprNonCopyMoveConstructor |
| 1746 | = FromData.HasConstexprNonCopyMoveConstructor; |
Nico Weber | 72c57f4 | 2016-02-24 20:58:14 +0000 | [diff] [blame] | 1747 | ToData.HasDefaultedDefaultConstructor |
| 1748 | = FromData.HasDefaultedDefaultConstructor; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1749 | ToData.DefaultedDefaultConstructorIsConstexpr |
| 1750 | = FromData.DefaultedDefaultConstructorIsConstexpr; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1751 | ToData.HasConstexprDefaultConstructor |
| 1752 | = FromData.HasConstexprDefaultConstructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1753 | ToData.HasNonLiteralTypeFieldsOrBases |
| 1754 | = FromData.HasNonLiteralTypeFieldsOrBases; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1755 | // ComputedVisibleConversions not imported. |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1756 | ToData.UserProvidedDefaultConstructor |
| 1757 | = FromData.UserProvidedDefaultConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1758 | ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers; |
Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 1759 | ToData.ImplicitCopyConstructorCanHaveConstParamForVBase |
| 1760 | = FromData.ImplicitCopyConstructorCanHaveConstParamForVBase; |
| 1761 | ToData.ImplicitCopyConstructorCanHaveConstParamForNonVBase |
| 1762 | = FromData.ImplicitCopyConstructorCanHaveConstParamForNonVBase; |
Richard Smith | 1c33fe8 | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 1763 | ToData.ImplicitCopyAssignmentHasConstParam |
| 1764 | = FromData.ImplicitCopyAssignmentHasConstParam; |
| 1765 | ToData.HasDeclaredCopyConstructorWithConstParam |
| 1766 | = FromData.HasDeclaredCopyConstructorWithConstParam; |
| 1767 | ToData.HasDeclaredCopyAssignmentWithConstParam |
| 1768 | = FromData.HasDeclaredCopyAssignmentWithConstParam; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1769 | |
Shafik Yaghmour | 16b9073 | 2019-04-26 18:51:28 +0000 | [diff] [blame^] | 1770 | // Copy over the data stored in RecordDeclBits |
| 1771 | ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions()); |
| 1772 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1773 | SmallVector<CXXBaseSpecifier *, 4> Bases; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1774 | for (const auto &Base1 : FromCXX->bases()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1775 | ExpectedType TyOrErr = import(Base1.getType()); |
| 1776 | if (!TyOrErr) |
| 1777 | return TyOrErr.takeError(); |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1778 | |
| 1779 | SourceLocation EllipsisLoc; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1780 | if (Base1.isPackExpansion()) { |
| 1781 | if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc())) |
| 1782 | EllipsisLoc = *LocOrErr; |
| 1783 | else |
| 1784 | return LocOrErr.takeError(); |
| 1785 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1786 | |
| 1787 | // Ensure that we have a definition for the base. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1788 | if (Error Err = |
| 1789 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl())) |
| 1790 | return Err; |
| 1791 | |
| 1792 | auto RangeOrErr = import(Base1.getSourceRange()); |
| 1793 | if (!RangeOrErr) |
| 1794 | return RangeOrErr.takeError(); |
| 1795 | |
| 1796 | auto TSIOrErr = import(Base1.getTypeSourceInfo()); |
| 1797 | if (!TSIOrErr) |
| 1798 | return TSIOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1799 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1800 | Bases.push_back( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1801 | new (Importer.getToContext()) CXXBaseSpecifier( |
| 1802 | *RangeOrErr, |
| 1803 | Base1.isVirtual(), |
| 1804 | Base1.isBaseOfClass(), |
| 1805 | Base1.getAccessSpecifierAsWritten(), |
| 1806 | *TSIOrErr, |
| 1807 | EllipsisLoc)); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1808 | } |
| 1809 | if (!Bases.empty()) |
Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1810 | ToCXX->setBases(Bases.data(), Bases.size()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1811 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1812 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1813 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1814 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 1815 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1816 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1817 | To->completeDefinition(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1818 | return Error::success(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1819 | } |
| 1820 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1821 | Error ASTNodeImporter::ImportInitializer(VarDecl *From, VarDecl *To) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1822 | if (To->getAnyInitializer()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1823 | return Error::success(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1824 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1825 | Expr *FromInit = From->getInit(); |
| 1826 | if (!FromInit) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1827 | return Error::success(); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1828 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1829 | ExpectedExpr ToInitOrErr = import(FromInit); |
| 1830 | if (!ToInitOrErr) |
| 1831 | return ToInitOrErr.takeError(); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1832 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1833 | To->setInit(*ToInitOrErr); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1834 | if (From->isInitKnownICE()) { |
| 1835 | EvaluatedStmt *Eval = To->ensureEvaluatedStmt(); |
| 1836 | Eval->CheckedICE = true; |
| 1837 | Eval->IsICE = From->isInitICE(); |
| 1838 | } |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1839 | |
| 1840 | // FIXME: Other bits to merge? |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1841 | return Error::success(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1842 | } |
| 1843 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1844 | Error ASTNodeImporter::ImportDefinition( |
| 1845 | EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1846 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1847 | if (Kind == IDK_Everything) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1848 | return ImportDeclContext(From, /*ForceImport=*/true); |
| 1849 | return Error::success(); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1850 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1851 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1852 | To->startDefinition(); |
| 1853 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1854 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 1855 | return Err; |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1856 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1857 | ExpectedType ToTypeOrErr = |
| 1858 | import(Importer.getFromContext().getTypeDeclType(From)); |
| 1859 | if (!ToTypeOrErr) |
| 1860 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1861 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1862 | ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType()); |
| 1863 | if (!ToPromotionTypeOrErr) |
| 1864 | return ToPromotionTypeOrErr.takeError(); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1865 | |
| 1866 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1867 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 1868 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1869 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1870 | // FIXME: we might need to merge the number of positive or negative bits |
| 1871 | // if the enumerator lists don't match. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1872 | To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr, |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1873 | From->getNumPositiveBits(), |
| 1874 | From->getNumNegativeBits()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1875 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1876 | } |
| 1877 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1878 | Error ASTNodeImporter::ImportTemplateArguments( |
| 1879 | const TemplateArgument *FromArgs, unsigned NumFromArgs, |
| 1880 | SmallVectorImpl<TemplateArgument> &ToArgs) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1881 | for (unsigned I = 0; I != NumFromArgs; ++I) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1882 | if (auto ToOrErr = import(FromArgs[I])) |
| 1883 | ToArgs.push_back(*ToOrErr); |
| 1884 | else |
| 1885 | return ToOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1886 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1887 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1888 | return Error::success(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1889 | } |
| 1890 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1891 | // FIXME: Do not forget to remove this and use only 'import'. |
| 1892 | Expected<TemplateArgument> |
| 1893 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { |
| 1894 | return import(From); |
| 1895 | } |
| 1896 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1897 | template <typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1898 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1899 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { |
| 1900 | for (const auto &FromLoc : Container) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1901 | if (auto ToLocOrErr = import(FromLoc)) |
| 1902 | ToTAInfo.addArgument(*ToLocOrErr); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1903 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1904 | return ToLocOrErr.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1905 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1906 | return Error::success(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1907 | } |
| 1908 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1909 | static StructuralEquivalenceKind |
| 1910 | getStructuralEquivalenceKind(const ASTImporter &Importer) { |
| 1911 | return Importer.isMinimalImport() ? StructuralEquivalenceKind::Minimal |
| 1912 | : StructuralEquivalenceKind::Default; |
| 1913 | } |
| 1914 | |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1915 | bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) { |
| 1916 | StructuralEquivalenceContext Ctx( |
| 1917 | Importer.getFromContext(), Importer.getToContext(), |
| 1918 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1919 | false, Complain); |
| 1920 | return Ctx.IsEquivalent(From, To); |
| 1921 | } |
| 1922 | |
| 1923 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1924 | RecordDecl *ToRecord, bool Complain) { |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1925 | // Eliminate a potential failure point where we attempt to re-import |
| 1926 | // something we're trying to import while completing ToRecord. |
| 1927 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); |
| 1928 | if (ToOrigin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1929 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1930 | if (ToOriginRecord) |
| 1931 | ToRecord = ToOriginRecord; |
| 1932 | } |
| 1933 | |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1934 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1935 | ToRecord->getASTContext(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1936 | Importer.getNonEquivalentDecls(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1937 | getStructuralEquivalenceKind(Importer), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1938 | false, Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1939 | return Ctx.IsEquivalent(FromRecord, ToRecord); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1940 | } |
| 1941 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1942 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 1943 | bool Complain) { |
| 1944 | StructuralEquivalenceContext Ctx( |
| 1945 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1946 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1947 | false, Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1948 | return Ctx.IsEquivalent(FromVar, ToVar); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1949 | } |
| 1950 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1951 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { |
Shafik Yaghmour | e5094d6 | 2019-03-27 17:47:36 +0000 | [diff] [blame] | 1952 | // Eliminate a potential failure point where we attempt to re-import |
Raphael Isemann | fa26c20 | 2019-04-09 14:18:23 +0000 | [diff] [blame] | 1953 | // something we're trying to import while completing ToEnum. |
Shafik Yaghmour | e5094d6 | 2019-03-27 17:47:36 +0000 | [diff] [blame] | 1954 | if (Decl *ToOrigin = Importer.GetOriginalDecl(ToEnum)) |
| 1955 | if (auto *ToOriginEnum = dyn_cast<EnumDecl>(ToOrigin)) |
| 1956 | ToEnum = ToOriginEnum; |
| 1957 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1958 | StructuralEquivalenceContext Ctx( |
| 1959 | Importer.getFromContext(), Importer.getToContext(), |
| 1960 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1961 | return Ctx.IsEquivalent(FromEnum, ToEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1962 | } |
| 1963 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1964 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, |
| 1965 | FunctionTemplateDecl *To) { |
| 1966 | StructuralEquivalenceContext Ctx( |
| 1967 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1968 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1969 | false, false); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1970 | return Ctx.IsEquivalent(From, To); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1971 | } |
| 1972 | |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 1973 | bool ASTNodeImporter::IsStructuralMatch(FunctionDecl *From, FunctionDecl *To) { |
| 1974 | StructuralEquivalenceContext Ctx( |
| 1975 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1976 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1977 | false, false); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1978 | return Ctx.IsEquivalent(From, To); |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 1979 | } |
| 1980 | |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1981 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1982 | EnumConstantDecl *ToEC) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1983 | const llvm::APSInt &FromVal = FromEC->getInitVal(); |
| 1984 | const llvm::APSInt &ToVal = ToEC->getInitVal(); |
| 1985 | |
| 1986 | return FromVal.isSigned() == ToVal.isSigned() && |
| 1987 | FromVal.getBitWidth() == ToVal.getBitWidth() && |
| 1988 | FromVal == ToVal; |
| 1989 | } |
| 1990 | |
| 1991 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1992 | ClassTemplateDecl *To) { |
| 1993 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 1994 | Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1995 | Importer.getNonEquivalentDecls(), |
| 1996 | getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1997 | return Ctx.IsEquivalent(From, To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1998 | } |
| 1999 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2000 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, |
| 2001 | VarTemplateDecl *To) { |
| 2002 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2003 | Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2004 | Importer.getNonEquivalentDecls(), |
| 2005 | getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2006 | return Ctx.IsEquivalent(From, To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2007 | } |
| 2008 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2009 | ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 2010 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2011 | << D->getDeclKindName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2012 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2013 | } |
| 2014 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2015 | ExpectedDecl ASTNodeImporter::VisitImportDecl(ImportDecl *D) { |
| 2016 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 2017 | << D->getDeclKindName(); |
| 2018 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| 2019 | } |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2020 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2021 | ExpectedDecl ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { |
| 2022 | // Import the context of this declaration. |
| 2023 | DeclContext *DC, *LexicalDC; |
| 2024 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 2025 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2026 | |
| 2027 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2028 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2029 | if (!LocOrErr) |
| 2030 | return LocOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2031 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2032 | EmptyDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2033 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2034 | return ToD; |
| 2035 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2036 | ToD->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2037 | LexicalDC->addDeclInternal(ToD); |
| 2038 | return ToD; |
| 2039 | } |
| 2040 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2041 | ExpectedDecl ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2042 | TranslationUnitDecl *ToD = |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2043 | Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2044 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2045 | Importer.MapImported(D, ToD); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2046 | |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2047 | return ToD; |
| 2048 | } |
| 2049 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2050 | ExpectedDecl ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
| 2051 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2052 | if (!LocOrErr) |
| 2053 | return LocOrErr.takeError(); |
| 2054 | auto ColonLocOrErr = import(D->getColonLoc()); |
| 2055 | if (!ColonLocOrErr) |
| 2056 | return ColonLocOrErr.takeError(); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2057 | |
| 2058 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2059 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2060 | if (!DCOrErr) |
| 2061 | return DCOrErr.takeError(); |
| 2062 | DeclContext *DC = *DCOrErr; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2063 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2064 | AccessSpecDecl *ToD; |
| 2065 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2066 | DC, *LocOrErr, *ColonLocOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2067 | return ToD; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2068 | |
| 2069 | // Lexical DeclContext and Semantic DeclContext |
| 2070 | // is always the same for the accessSpec. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2071 | ToD->setLexicalDeclContext(DC); |
| 2072 | DC->addDeclInternal(ToD); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2073 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2074 | return ToD; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2075 | } |
| 2076 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2077 | ExpectedDecl ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 2078 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2079 | if (!DCOrErr) |
| 2080 | return DCOrErr.takeError(); |
| 2081 | DeclContext *DC = *DCOrErr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2082 | DeclContext *LexicalDC = DC; |
| 2083 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2084 | SourceLocation ToLocation, ToRParenLoc; |
| 2085 | Expr *ToAssertExpr; |
| 2086 | StringLiteral *ToMessage; |
| 2087 | if (auto Imp = importSeq( |
| 2088 | D->getLocation(), D->getAssertExpr(), D->getMessage(), D->getRParenLoc())) |
| 2089 | std::tie(ToLocation, ToAssertExpr, ToMessage, ToRParenLoc) = *Imp; |
| 2090 | else |
| 2091 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2092 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2093 | StaticAssertDecl *ToD; |
| 2094 | if (GetImportedOrCreateDecl( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2095 | ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage, |
| 2096 | ToRParenLoc, D->isFailed())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2097 | return ToD; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2098 | |
| 2099 | ToD->setLexicalDeclContext(LexicalDC); |
| 2100 | LexicalDC->addDeclInternal(ToD); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2101 | return ToD; |
| 2102 | } |
| 2103 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2104 | ExpectedDecl ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2105 | // Import the major distinguishing characteristics of this namespace. |
| 2106 | DeclContext *DC, *LexicalDC; |
| 2107 | DeclarationName Name; |
| 2108 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2109 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2110 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2111 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2112 | if (ToD) |
| 2113 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2114 | |
| 2115 | NamespaceDecl *MergeWithNamespace = nullptr; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2116 | if (!Name) { |
| 2117 | // This is an anonymous namespace. Adopt an existing anonymous |
| 2118 | // namespace if we can. |
| 2119 | // FIXME: Not testable. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2120 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2121 | MergeWithNamespace = TU->getAnonymousNamespace(); |
| 2122 | else |
| 2123 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); |
| 2124 | } else { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2125 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2126 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2127 | for (auto *FoundDecl : FoundDecls) { |
| 2128 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2129 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2130 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2131 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2132 | MergeWithNamespace = FoundNS; |
| 2133 | ConflictingDecls.clear(); |
| 2134 | break; |
| 2135 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2136 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2137 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2138 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2139 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2140 | if (!ConflictingDecls.empty()) { |
John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 2141 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2142 | ConflictingDecls.data(), |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2143 | ConflictingDecls.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2144 | if (!Name) |
| 2145 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2146 | } |
| 2147 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2148 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2149 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2150 | if (!BeginLocOrErr) |
| 2151 | return BeginLocOrErr.takeError(); |
| 2152 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2153 | // Create the "to" namespace, if needed. |
| 2154 | NamespaceDecl *ToNamespace = MergeWithNamespace; |
| 2155 | if (!ToNamespace) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2156 | if (GetImportedOrCreateDecl( |
| 2157 | ToNamespace, D, Importer.getToContext(), DC, D->isInline(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2158 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2159 | /*PrevDecl=*/nullptr)) |
| 2160 | return ToNamespace; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2161 | ToNamespace->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2162 | LexicalDC->addDeclInternal(ToNamespace); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2163 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2164 | // If this is an anonymous namespace, register it as the anonymous |
| 2165 | // namespace within its context. |
| 2166 | if (!Name) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2167 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2168 | TU->setAnonymousNamespace(ToNamespace); |
| 2169 | else |
| 2170 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); |
| 2171 | } |
| 2172 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2173 | Importer.MapImported(D, ToNamespace); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2174 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2175 | if (Error Err = ImportDeclContext(D)) |
| 2176 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2177 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2178 | return ToNamespace; |
| 2179 | } |
| 2180 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2181 | ExpectedDecl ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2182 | // Import the major distinguishing characteristics of this namespace. |
| 2183 | DeclContext *DC, *LexicalDC; |
| 2184 | DeclarationName Name; |
| 2185 | SourceLocation Loc; |
| 2186 | NamedDecl *LookupD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2187 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) |
| 2188 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2189 | if (LookupD) |
| 2190 | return LookupD; |
| 2191 | |
| 2192 | // NOTE: No conflict resolution is done for namespace aliases now. |
| 2193 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2194 | SourceLocation ToNamespaceLoc, ToAliasLoc, ToTargetNameLoc; |
| 2195 | NestedNameSpecifierLoc ToQualifierLoc; |
| 2196 | NamespaceDecl *ToNamespace; |
| 2197 | if (auto Imp = importSeq( |
| 2198 | D->getNamespaceLoc(), D->getAliasLoc(), D->getQualifierLoc(), |
| 2199 | D->getTargetNameLoc(), D->getNamespace())) |
| 2200 | std::tie( |
| 2201 | ToNamespaceLoc, ToAliasLoc, ToQualifierLoc, ToTargetNameLoc, |
| 2202 | ToNamespace) = *Imp; |
| 2203 | else |
| 2204 | return Imp.takeError(); |
| 2205 | IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier()); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2206 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2207 | NamespaceAliasDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2208 | if (GetImportedOrCreateDecl( |
| 2209 | ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc, |
| 2210 | ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2211 | return ToD; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2212 | |
| 2213 | ToD->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2214 | LexicalDC->addDeclInternal(ToD); |
| 2215 | |
| 2216 | return ToD; |
| 2217 | } |
| 2218 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2219 | ExpectedDecl |
| 2220 | ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2221 | // Import the major distinguishing characteristics of this typedef. |
| 2222 | DeclContext *DC, *LexicalDC; |
| 2223 | DeclarationName Name; |
| 2224 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2225 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2226 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2227 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2228 | if (ToD) |
| 2229 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2230 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2231 | // If this typedef is not in block scope, determine whether we've |
| 2232 | // seen a typedef with the same name (that we can merge with) or any |
| 2233 | // other entity by that name (which name lookup could conflict with). |
| 2234 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2235 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2236 | unsigned IDNS = Decl::IDNS_Ordinary; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2237 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2238 | for (auto *FoundDecl : FoundDecls) { |
| 2239 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2240 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2241 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2242 | QualType FromUT = D->getUnderlyingType(); |
| 2243 | QualType FoundUT = FoundTypedef->getUnderlyingType(); |
| 2244 | if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) { |
| 2245 | // If the "From" context has a complete underlying type but we |
| 2246 | // already have a complete underlying type then return with that. |
| 2247 | if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2248 | return Importer.MapImported(D, FoundTypedef); |
Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2249 | } |
| 2250 | // FIXME Handle redecl chain. |
| 2251 | break; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2252 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2253 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2254 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2255 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2256 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2257 | if (!ConflictingDecls.empty()) { |
| 2258 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2259 | ConflictingDecls.data(), |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2260 | ConflictingDecls.size()); |
| 2261 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2262 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2263 | } |
| 2264 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2265 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2266 | QualType ToUnderlyingType; |
| 2267 | TypeSourceInfo *ToTypeSourceInfo; |
| 2268 | SourceLocation ToBeginLoc; |
| 2269 | if (auto Imp = importSeq( |
| 2270 | D->getUnderlyingType(), D->getTypeSourceInfo(), D->getBeginLoc())) |
| 2271 | std::tie(ToUnderlyingType, ToTypeSourceInfo, ToBeginLoc) = *Imp; |
| 2272 | else |
| 2273 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2274 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2275 | // Create the new typedef node. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2276 | // FIXME: ToUnderlyingType is not used. |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2277 | TypedefNameDecl *ToTypedef; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2278 | if (IsAlias) { |
| 2279 | if (GetImportedOrCreateDecl<TypeAliasDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2280 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2281 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2282 | return ToTypedef; |
| 2283 | } else if (GetImportedOrCreateDecl<TypedefDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2284 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2285 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2286 | return ToTypedef; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2287 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2288 | ToTypedef->setAccess(D->getAccess()); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2289 | ToTypedef->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2290 | |
| 2291 | // Templated declarations should not appear in DeclContext. |
| 2292 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; |
| 2293 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) |
| 2294 | LexicalDC->addDeclInternal(ToTypedef); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2295 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2296 | return ToTypedef; |
| 2297 | } |
| 2298 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2299 | ExpectedDecl ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2300 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); |
| 2301 | } |
| 2302 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2303 | ExpectedDecl ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2304 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); |
| 2305 | } |
| 2306 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2307 | ExpectedDecl |
| 2308 | ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2309 | // Import the major distinguishing characteristics of this typedef. |
| 2310 | DeclContext *DC, *LexicalDC; |
| 2311 | DeclarationName Name; |
| 2312 | SourceLocation Loc; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2313 | NamedDecl *FoundD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2314 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) |
| 2315 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2316 | if (FoundD) |
| 2317 | return FoundD; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2318 | |
| 2319 | // If this typedef is not in block scope, determine whether we've |
| 2320 | // seen a typedef with the same name (that we can merge with) or any |
| 2321 | // other entity by that name (which name lookup could conflict with). |
| 2322 | if (!DC->isFunctionOrMethod()) { |
| 2323 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 2324 | unsigned IDNS = Decl::IDNS_Ordinary; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2325 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2326 | for (auto *FoundDecl : FoundDecls) { |
| 2327 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2328 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2329 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2330 | return Importer.MapImported(D, FoundAlias); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2331 | ConflictingDecls.push_back(FoundDecl); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2332 | } |
| 2333 | |
| 2334 | if (!ConflictingDecls.empty()) { |
| 2335 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2336 | ConflictingDecls.data(), |
| 2337 | ConflictingDecls.size()); |
| 2338 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2339 | return make_error<ImportError>(ImportError::NameConflict); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2340 | } |
| 2341 | } |
| 2342 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2343 | TemplateParameterList *ToTemplateParameters; |
| 2344 | TypeAliasDecl *ToTemplatedDecl; |
| 2345 | if (auto Imp = importSeq(D->getTemplateParameters(), D->getTemplatedDecl())) |
| 2346 | std::tie(ToTemplateParameters, ToTemplatedDecl) = *Imp; |
| 2347 | else |
| 2348 | return Imp.takeError(); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2349 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2350 | TypeAliasTemplateDecl *ToAlias; |
| 2351 | if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2352 | Name, ToTemplateParameters, ToTemplatedDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2353 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2354 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2355 | ToTemplatedDecl->setDescribedAliasTemplate(ToAlias); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2356 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2357 | ToAlias->setAccess(D->getAccess()); |
| 2358 | ToAlias->setLexicalDeclContext(LexicalDC); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2359 | LexicalDC->addDeclInternal(ToAlias); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2360 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2361 | } |
| 2362 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2363 | ExpectedDecl ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2364 | // Import the major distinguishing characteristics of this label. |
| 2365 | DeclContext *DC, *LexicalDC; |
| 2366 | DeclarationName Name; |
| 2367 | SourceLocation Loc; |
| 2368 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2369 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2370 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2371 | if (ToD) |
| 2372 | return ToD; |
| 2373 | |
| 2374 | assert(LexicalDC->isFunctionOrMethod()); |
| 2375 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2376 | LabelDecl *ToLabel; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2377 | if (D->isGnuLocal()) { |
| 2378 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2379 | if (!BeginLocOrErr) |
| 2380 | return BeginLocOrErr.takeError(); |
| 2381 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2382 | Name.getAsIdentifierInfo(), *BeginLocOrErr)) |
| 2383 | return ToLabel; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2384 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2385 | } else { |
| 2386 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2387 | Name.getAsIdentifierInfo())) |
| 2388 | return ToLabel; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2389 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2390 | } |
| 2391 | |
| 2392 | Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt()); |
| 2393 | if (!ToStmtOrErr) |
| 2394 | return ToStmtOrErr.takeError(); |
| 2395 | |
| 2396 | ToLabel->setStmt(*ToStmtOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2397 | ToLabel->setLexicalDeclContext(LexicalDC); |
| 2398 | LexicalDC->addDeclInternal(ToLabel); |
| 2399 | return ToLabel; |
| 2400 | } |
| 2401 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2402 | ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2403 | // Import the major distinguishing characteristics of this enum. |
| 2404 | DeclContext *DC, *LexicalDC; |
| 2405 | DeclarationName Name; |
| 2406 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2407 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2408 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2409 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2410 | if (ToD) |
| 2411 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2412 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2413 | // Figure out what enum name we're looking for. |
| 2414 | unsigned IDNS = Decl::IDNS_Tag; |
| 2415 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2416 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2417 | if (Error Err = importInto( |
| 2418 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2419 | return std::move(Err); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2420 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2421 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2422 | IDNS |= Decl::IDNS_Ordinary; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2423 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2424 | // We may already have an enum of the same name; try to find and match it. |
| 2425 | if (!DC->isFunctionOrMethod() && SearchName) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2426 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2427 | auto FoundDecls = |
| 2428 | Importer.findDeclsInToCtx(DC, SearchName); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2429 | for (auto *FoundDecl : FoundDecls) { |
| 2430 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2431 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2432 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2433 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2434 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2435 | FoundDecl = Tag->getDecl(); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2436 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2437 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2438 | if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) { |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2439 | if (IsStructuralMatch(D, FoundEnum)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2440 | return Importer.MapImported(D, FoundEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2441 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2442 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2443 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2444 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2445 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2446 | if (!ConflictingDecls.empty()) { |
Shafik Yaghmour | d426312 | 2019-04-08 20:50:21 +0000 | [diff] [blame] | 2447 | Name = Importer.HandleNameConflict(SearchName, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2448 | ConflictingDecls.data(), |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2449 | ConflictingDecls.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2450 | if (!Name) |
| 2451 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2452 | } |
| 2453 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2454 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2455 | SourceLocation ToBeginLoc; |
| 2456 | NestedNameSpecifierLoc ToQualifierLoc; |
| 2457 | QualType ToIntegerType; |
| 2458 | if (auto Imp = importSeq( |
| 2459 | D->getBeginLoc(), D->getQualifierLoc(), D->getIntegerType())) |
| 2460 | std::tie(ToBeginLoc, ToQualifierLoc, ToIntegerType) = *Imp; |
| 2461 | else |
| 2462 | return Imp.takeError(); |
| 2463 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2464 | // Create the enum declaration. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2465 | EnumDecl *D2; |
| 2466 | if (GetImportedOrCreateDecl( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2467 | D2, D, Importer.getToContext(), DC, ToBeginLoc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2468 | Loc, Name.getAsIdentifierInfo(), nullptr, D->isScoped(), |
| 2469 | D->isScopedUsingClassTag(), D->isFixed())) |
| 2470 | return D2; |
| 2471 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2472 | D2->setQualifierInfo(ToQualifierLoc); |
| 2473 | D2->setIntegerType(ToIntegerType); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2474 | D2->setAccess(D->getAccess()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2475 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2476 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2477 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2478 | // Import the definition |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2479 | if (D->isCompleteDefinition()) |
| 2480 | if (Error Err = ImportDefinition(D, D2)) |
| 2481 | return std::move(Err); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2482 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2483 | return D2; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2484 | } |
| 2485 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2486 | ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2487 | bool IsFriendTemplate = false; |
| 2488 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2489 | IsFriendTemplate = |
| 2490 | DCXX->getDescribedClassTemplate() && |
| 2491 | DCXX->getDescribedClassTemplate()->getFriendObjectKind() != |
| 2492 | Decl::FOK_None; |
| 2493 | } |
| 2494 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2495 | // Import the major distinguishing characteristics of this record. |
| 2496 | DeclContext *DC, *LexicalDC; |
| 2497 | DeclarationName Name; |
| 2498 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2499 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2500 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2501 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2502 | if (ToD) |
| 2503 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2504 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2505 | // Figure out what structure name we're looking for. |
| 2506 | unsigned IDNS = Decl::IDNS_Tag; |
| 2507 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2508 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2509 | if (Error Err = importInto( |
| 2510 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2511 | return std::move(Err); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2512 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2513 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2514 | IDNS |= Decl::IDNS_Ordinary | Decl::IDNS_TagFriend; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2515 | |
| 2516 | // 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] | 2517 | RecordDecl *PrevDecl = nullptr; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2518 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2519 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2520 | auto FoundDecls = |
| 2521 | Importer.findDeclsInToCtx(DC, SearchName); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2522 | if (!FoundDecls.empty()) { |
Gabor Marton | 41e3892 | 2019-03-05 11:23:24 +0000 | [diff] [blame] | 2523 | // We're going to have to compare D against potentially conflicting Decls, |
| 2524 | // so complete it. |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2525 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) |
| 2526 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 2527 | } |
| 2528 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2529 | for (auto *FoundDecl : FoundDecls) { |
| 2530 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2531 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2532 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2533 | Decl *Found = FoundDecl; |
| 2534 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 2535 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2536 | Found = Tag->getDecl(); |
| 2537 | } |
Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2538 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2539 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2540 | // Do not emit false positive diagnostic in case of unnamed |
| 2541 | // struct/union and in case of anonymous structs. Would be false |
| 2542 | // because there may be several anonymous/unnamed structs in a class. |
| 2543 | // E.g. these are both valid: |
| 2544 | // struct A { // unnamed structs |
| 2545 | // struct { struct A *next; } entry0; |
| 2546 | // struct { struct A *next; } entry1; |
| 2547 | // }; |
| 2548 | // struct X { struct { int a; }; struct { int b; }; }; // anon structs |
| 2549 | if (!SearchName) |
Gabor Marton | 0bebf95 | 2018-07-05 09:51:13 +0000 | [diff] [blame] | 2550 | if (!IsStructuralMatch(D, FoundRecord, false)) |
| 2551 | continue; |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2552 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2553 | if (IsStructuralMatch(D, FoundRecord)) { |
| 2554 | RecordDecl *FoundDef = FoundRecord->getDefinition(); |
| 2555 | if (D->isThisDeclarationADefinition() && FoundDef) { |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2556 | // FIXME: Structural equivalence check should check for same |
| 2557 | // user-defined methods. |
| 2558 | Importer.MapImported(D, FoundDef); |
| 2559 | if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2560 | auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef); |
| 2561 | assert(FoundCXX && "Record type mismatch"); |
| 2562 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2563 | if (!Importer.isMinimalImport()) |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2564 | // FoundDef may not have every implicit method that D has |
| 2565 | // because implicit methods are created only if they are used. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2566 | if (Error Err = ImportImplicitMethods(DCXX, FoundCXX)) |
| 2567 | return std::move(Err); |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2568 | } |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2569 | } |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2570 | PrevDecl = FoundRecord->getMostRecentDecl(); |
| 2571 | break; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2572 | } |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2573 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2574 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2575 | ConflictingDecls.push_back(FoundDecl); |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2576 | } // for |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2577 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2578 | if (!ConflictingDecls.empty() && SearchName) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2579 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2580 | ConflictingDecls.data(), |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2581 | ConflictingDecls.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2582 | if (!Name) |
| 2583 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2584 | } |
| 2585 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2586 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2587 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2588 | if (!BeginLocOrErr) |
| 2589 | return BeginLocOrErr.takeError(); |
| 2590 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2591 | // Create the record declaration. |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2592 | RecordDecl *D2 = nullptr; |
| 2593 | CXXRecordDecl *D2CXX = nullptr; |
| 2594 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2595 | if (DCXX->isLambda()) { |
| 2596 | auto TInfoOrErr = import(DCXX->getLambdaTypeInfo()); |
| 2597 | if (!TInfoOrErr) |
| 2598 | return TInfoOrErr.takeError(); |
| 2599 | if (GetImportedOrCreateSpecialDecl( |
| 2600 | D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(), |
| 2601 | DC, *TInfoOrErr, Loc, DCXX->isDependentLambda(), |
| 2602 | DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault())) |
| 2603 | return D2CXX; |
| 2604 | ExpectedDecl CDeclOrErr = import(DCXX->getLambdaContextDecl()); |
| 2605 | if (!CDeclOrErr) |
| 2606 | return CDeclOrErr.takeError(); |
| 2607 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), *CDeclOrErr); |
| 2608 | } else if (DCXX->isInjectedClassName()) { |
| 2609 | // We have to be careful to do a similar dance to the one in |
| 2610 | // Sema::ActOnStartCXXMemberDeclarations |
| 2611 | const bool DelayTypeCreation = true; |
| 2612 | if (GetImportedOrCreateDecl( |
| 2613 | D2CXX, D, Importer.getToContext(), D->getTagKind(), DC, |
| 2614 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), |
| 2615 | cast_or_null<CXXRecordDecl>(PrevDecl), DelayTypeCreation)) |
| 2616 | return D2CXX; |
| 2617 | Importer.getToContext().getTypeDeclType( |
| 2618 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); |
| 2619 | } else { |
| 2620 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), |
| 2621 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
| 2622 | Name.getAsIdentifierInfo(), |
| 2623 | cast_or_null<CXXRecordDecl>(PrevDecl))) |
| 2624 | return D2CXX; |
| 2625 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2626 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2627 | D2 = D2CXX; |
| 2628 | D2->setAccess(D->getAccess()); |
| 2629 | D2->setLexicalDeclContext(LexicalDC); |
| 2630 | if (!DCXX->getDescribedClassTemplate() || DCXX->isImplicit()) |
| 2631 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2632 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2633 | if (LexicalDC != DC && D->isInIdentifierNamespace(Decl::IDNS_TagFriend)) |
| 2634 | DC->makeDeclVisibleInContext(D2); |
| 2635 | |
| 2636 | if (ClassTemplateDecl *FromDescribed = |
| 2637 | DCXX->getDescribedClassTemplate()) { |
| 2638 | ClassTemplateDecl *ToDescribed; |
| 2639 | if (Error Err = importInto(ToDescribed, FromDescribed)) |
| 2640 | return std::move(Err); |
| 2641 | D2CXX->setDescribedClassTemplate(ToDescribed); |
| 2642 | if (!DCXX->isInjectedClassName() && !IsFriendTemplate) { |
| 2643 | // In a record describing a template the type should be an |
| 2644 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the |
| 2645 | // previously set type to the correct value here (ToDescribed is not |
| 2646 | // available at record create). |
| 2647 | // FIXME: The previous type is cleared but not removed from |
| 2648 | // ASTContext's internal storage. |
| 2649 | CXXRecordDecl *Injected = nullptr; |
| 2650 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { |
| 2651 | auto *Record = dyn_cast<CXXRecordDecl>(Found); |
| 2652 | if (Record && Record->isInjectedClassName()) { |
| 2653 | Injected = Record; |
| 2654 | break; |
Gabor Marton | 5915777e | 2018-06-26 13:44:24 +0000 | [diff] [blame] | 2655 | } |
| 2656 | } |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2657 | // Create an injected type for the whole redecl chain. |
| 2658 | SmallVector<Decl *, 2> Redecls = |
| 2659 | getCanonicalForwardRedeclChain(D2CXX); |
| 2660 | for (auto *R : Redecls) { |
| 2661 | auto *RI = cast<CXXRecordDecl>(R); |
| 2662 | RI->setTypeForDecl(nullptr); |
| 2663 | // Below we create a new injected type and assign that to the |
| 2664 | // canonical decl, subsequent declarations in the chain will reuse |
| 2665 | // that type. |
| 2666 | Importer.getToContext().getInjectedClassNameType( |
| 2667 | RI, ToDescribed->getInjectedClassNameSpecialization()); |
| 2668 | } |
| 2669 | // Set the new type for the previous injected decl too. |
| 2670 | if (Injected) { |
| 2671 | Injected->setTypeForDecl(nullptr); |
| 2672 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); |
| 2673 | } |
| 2674 | } |
| 2675 | } else if (MemberSpecializationInfo *MemberInfo = |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2676 | DCXX->getMemberSpecializationInfo()) { |
| 2677 | TemplateSpecializationKind SK = |
| 2678 | MemberInfo->getTemplateSpecializationKind(); |
| 2679 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2680 | |
| 2681 | if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst)) |
| 2682 | D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK); |
| 2683 | else |
| 2684 | return ToInstOrErr.takeError(); |
| 2685 | |
| 2686 | if (ExpectedSLoc POIOrErr = |
| 2687 | import(MemberInfo->getPointOfInstantiation())) |
| 2688 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( |
| 2689 | *POIOrErr); |
| 2690 | else |
| 2691 | return POIOrErr.takeError(); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2692 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2693 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2694 | } else { |
| 2695 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), |
| 2696 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
| 2697 | Name.getAsIdentifierInfo(), PrevDecl)) |
| 2698 | return D2; |
| 2699 | D2->setLexicalDeclContext(LexicalDC); |
| 2700 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2701 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2702 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2703 | if (auto QualifierLocOrErr = import(D->getQualifierLoc())) |
| 2704 | D2->setQualifierInfo(*QualifierLocOrErr); |
| 2705 | else |
| 2706 | return QualifierLocOrErr.takeError(); |
| 2707 | |
| 2708 | if (D->isAnonymousStructOrUnion()) |
| 2709 | D2->setAnonymousStructOrUnion(true); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2710 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2711 | if (D->isCompleteDefinition()) |
| 2712 | if (Error Err = ImportDefinition(D, D2, IDK_Default)) |
| 2713 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2714 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2715 | return D2; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2716 | } |
| 2717 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2718 | ExpectedDecl ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2719 | // Import the major distinguishing characteristics of this enumerator. |
| 2720 | DeclContext *DC, *LexicalDC; |
| 2721 | DeclarationName Name; |
| 2722 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2723 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2724 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2725 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2726 | if (ToD) |
| 2727 | return ToD; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2728 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2729 | // Determine whether there are any other declarations with the same name and |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2730 | // in the same context. |
| 2731 | if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2732 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2733 | unsigned IDNS = Decl::IDNS_Ordinary; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2734 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2735 | for (auto *FoundDecl : FoundDecls) { |
| 2736 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2737 | continue; |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2738 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2739 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2740 | if (IsStructuralMatch(D, FoundEnumConstant)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2741 | return Importer.MapImported(D, FoundEnumConstant); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2742 | } |
| 2743 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2744 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2745 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2746 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2747 | if (!ConflictingDecls.empty()) { |
| 2748 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2749 | ConflictingDecls.data(), |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2750 | ConflictingDecls.size()); |
| 2751 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2752 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2753 | } |
| 2754 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2755 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2756 | ExpectedType TypeOrErr = import(D->getType()); |
| 2757 | if (!TypeOrErr) |
| 2758 | return TypeOrErr.takeError(); |
| 2759 | |
| 2760 | ExpectedExpr InitOrErr = import(D->getInitExpr()); |
| 2761 | if (!InitOrErr) |
| 2762 | return InitOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2763 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2764 | EnumConstantDecl *ToEnumerator; |
| 2765 | if (GetImportedOrCreateDecl( |
| 2766 | ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2767 | Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2768 | return ToEnumerator; |
| 2769 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2770 | ToEnumerator->setAccess(D->getAccess()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2771 | ToEnumerator->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2772 | LexicalDC->addDeclInternal(ToEnumerator); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2773 | return ToEnumerator; |
| 2774 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2775 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2776 | Error ASTNodeImporter::ImportTemplateInformation( |
| 2777 | FunctionDecl *FromFD, FunctionDecl *ToFD) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2778 | switch (FromFD->getTemplatedKind()) { |
| 2779 | case FunctionDecl::TK_NonTemplate: |
| 2780 | case FunctionDecl::TK_FunctionTemplate: |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2781 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2782 | |
| 2783 | case FunctionDecl::TK_MemberSpecialization: { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2784 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2785 | |
| 2786 | if (Expected<FunctionDecl *> InstFDOrErr = |
| 2787 | import(FromFD->getInstantiatedFromMemberFunction())) |
| 2788 | ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK); |
| 2789 | else |
| 2790 | return InstFDOrErr.takeError(); |
| 2791 | |
| 2792 | if (ExpectedSLoc POIOrErr = import( |
| 2793 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation())) |
| 2794 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr); |
| 2795 | else |
| 2796 | return POIOrErr.takeError(); |
| 2797 | |
| 2798 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2799 | } |
| 2800 | |
| 2801 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2802 | auto FunctionAndArgsOrErr = |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2803 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2804 | if (!FunctionAndArgsOrErr) |
| 2805 | return FunctionAndArgsOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2806 | |
| 2807 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2808 | Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr)); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2809 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2810 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2811 | TemplateArgumentListInfo ToTAInfo; |
| 2812 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2813 | if (FromTAArgsAsWritten) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2814 | if (Error Err = ImportTemplateArgumentListInfo( |
| 2815 | *FromTAArgsAsWritten, ToTAInfo)) |
| 2816 | return Err; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2817 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2818 | ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation()); |
| 2819 | if (!POIOrErr) |
| 2820 | return POIOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2821 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2822 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2823 | ToFD->setFunctionTemplateSpecialization( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2824 | std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr, |
| 2825 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr); |
| 2826 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2827 | } |
| 2828 | |
| 2829 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 2830 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); |
| 2831 | UnresolvedSet<8> TemplDecls; |
| 2832 | unsigned NumTemplates = FromInfo->getNumTemplates(); |
| 2833 | for (unsigned I = 0; I < NumTemplates; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2834 | if (Expected<FunctionTemplateDecl *> ToFTDOrErr = |
| 2835 | import(FromInfo->getTemplate(I))) |
| 2836 | TemplDecls.addDecl(*ToFTDOrErr); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2837 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2838 | return ToFTDOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2839 | } |
| 2840 | |
| 2841 | // Import TemplateArgumentListInfo. |
| 2842 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2843 | if (Error Err = ImportTemplateArgumentListInfo( |
| 2844 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), |
| 2845 | llvm::makeArrayRef( |
| 2846 | FromInfo->getTemplateArgs(), FromInfo->getNumTemplateArgs()), |
| 2847 | ToTAInfo)) |
| 2848 | return Err; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2849 | |
| 2850 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), |
| 2851 | TemplDecls, ToTAInfo); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2852 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2853 | } |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2854 | } |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2855 | llvm_unreachable("All cases should be covered!"); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2856 | } |
| 2857 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2858 | Expected<FunctionDecl *> |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2859 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2860 | auto FunctionAndArgsOrErr = |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2861 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2862 | if (!FunctionAndArgsOrErr) |
| 2863 | return FunctionAndArgsOrErr.takeError(); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2864 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2865 | FunctionTemplateDecl *Template; |
| 2866 | TemplateArgsTy ToTemplArgs; |
| 2867 | std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2868 | void *InsertPos = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2869 | auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2870 | return FoundSpec; |
| 2871 | } |
| 2872 | |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 2873 | Error ASTNodeImporter::ImportFunctionDeclBody(FunctionDecl *FromFD, |
| 2874 | FunctionDecl *ToFD) { |
| 2875 | if (Stmt *FromBody = FromFD->getBody()) { |
| 2876 | if (ExpectedStmt ToBodyOrErr = import(FromBody)) |
| 2877 | ToFD->setBody(*ToBodyOrErr); |
| 2878 | else |
| 2879 | return ToBodyOrErr.takeError(); |
| 2880 | } |
| 2881 | return Error::success(); |
| 2882 | } |
| 2883 | |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 2884 | template <typename T> |
| 2885 | bool ASTNodeImporter::hasSameVisibilityContext(T *Found, T *From) { |
| 2886 | if (From->hasExternalFormalLinkage()) |
| 2887 | return Found->hasExternalFormalLinkage(); |
| 2888 | if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl()) |
| 2889 | return false; |
| 2890 | if (From->isInAnonymousNamespace()) |
| 2891 | return Found->isInAnonymousNamespace(); |
| 2892 | else |
| 2893 | return !Found->isInAnonymousNamespace() && |
| 2894 | !Found->hasExternalFormalLinkage(); |
| 2895 | } |
| 2896 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2897 | ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2898 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2899 | SmallVector<Decl *, 2> Redecls = getCanonicalForwardRedeclChain(D); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2900 | auto RedeclIt = Redecls.begin(); |
| 2901 | // Import the first part of the decl chain. I.e. import all previous |
| 2902 | // declarations starting from the canonical decl. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2903 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 2904 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 2905 | if (!ToRedeclOrErr) |
| 2906 | return ToRedeclOrErr.takeError(); |
| 2907 | } |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2908 | assert(*RedeclIt == D); |
| 2909 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2910 | // Import the major distinguishing characteristics of this function. |
| 2911 | DeclContext *DC, *LexicalDC; |
| 2912 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2913 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2914 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2915 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2916 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2917 | if (ToD) |
| 2918 | return ToD; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2919 | |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 2920 | FunctionDecl *FoundByLookup = nullptr; |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 2921 | FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2922 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2923 | // 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] | 2924 | // existing specialization in the "to" context. The lookup below will not |
| 2925 | // find any specialization, but would find the primary template; thus, we |
| 2926 | // have to skip normal lookup in case of specializations. |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2927 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? |
| 2928 | if (D->getTemplatedKind() == |
| 2929 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2930 | auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D); |
| 2931 | if (!FoundFunctionOrErr) |
| 2932 | return FoundFunctionOrErr.takeError(); |
| 2933 | if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) { |
Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 2934 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) |
| 2935 | return Def; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2936 | FoundByLookup = FoundFunction; |
| 2937 | } |
| 2938 | } |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2939 | // Try to find a function in our own ("to") context with the same name, same |
| 2940 | // type, and in the same context as the function we're importing. |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2941 | else if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2942 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2943 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2944 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2945 | for (auto *FoundDecl : FoundDecls) { |
| 2946 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2947 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2948 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2949 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 2950 | if (!hasSameVisibilityContext(FoundFunction, D)) |
| 2951 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2952 | |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 2953 | if (IsStructuralMatch(D, FoundFunction)) { |
Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 2954 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) |
| 2955 | return Def; |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 2956 | FoundByLookup = FoundFunction; |
| 2957 | break; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2958 | } |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 2959 | // FIXME: Check for overloading more carefully, e.g., by boosting |
| 2960 | // Sema::IsOverload out to the AST library. |
| 2961 | |
| 2962 | // Function overloading is okay in C++. |
| 2963 | if (Importer.getToContext().getLangOpts().CPlusPlus) |
| 2964 | continue; |
| 2965 | |
| 2966 | // Complain about inconsistent function types. |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 2967 | Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent) |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 2968 | << Name << D->getType() << FoundFunction->getType(); |
| 2969 | Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here) |
| 2970 | << FoundFunction->getType(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2971 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2972 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2973 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2974 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2975 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2976 | if (!ConflictingDecls.empty()) { |
| 2977 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2978 | ConflictingDecls.data(), |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2979 | ConflictingDecls.size()); |
| 2980 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2981 | return make_error<ImportError>(ImportError::NameConflict); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2982 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2983 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2984 | |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 2985 | // We do not allow more than one in-class declaration of a function. This is |
| 2986 | // because AST clients like VTableBuilder asserts on this. VTableBuilder |
| 2987 | // assumes there is only one in-class declaration. Building a redecl |
| 2988 | // chain would result in more than one in-class declaration for |
| 2989 | // overrides (even if they are part of the same redecl chain inside the |
| 2990 | // derived class.) |
| 2991 | if (FoundByLookup) { |
Mikael Holmen | c1c97aa | 2019-01-29 06:53:31 +0000 | [diff] [blame] | 2992 | if (isa<CXXMethodDecl>(FoundByLookup)) { |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 2993 | if (D->getLexicalDeclContext() == D->getDeclContext()) { |
| 2994 | if (!D->doesThisDeclarationHaveABody()) |
| 2995 | return Importer.MapImported(D, FoundByLookup); |
| 2996 | else { |
| 2997 | // Let's continue and build up the redecl chain in this case. |
| 2998 | // FIXME Merge the functions into one decl. |
| 2999 | } |
| 3000 | } |
| 3001 | } |
| 3002 | } |
| 3003 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3004 | DeclarationNameInfo NameInfo(Name, Loc); |
| 3005 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3006 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 3007 | return std::move(Err); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3008 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3009 | QualType FromTy = D->getType(); |
| 3010 | bool usedDifferentExceptionSpec = false; |
| 3011 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3012 | if (const auto *FromFPT = D->getType()->getAs<FunctionProtoType>()) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3013 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); |
| 3014 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the |
| 3015 | // FunctionDecl that we are importing the FunctionProtoType for. |
| 3016 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| 3017 | // with a simplified function type and update it afterwards. |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 3018 | if (FromEPI.ExceptionSpec.SourceDecl || |
| 3019 | FromEPI.ExceptionSpec.SourceTemplate || |
| 3020 | FromEPI.ExceptionSpec.NoexceptExpr) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3021 | FunctionProtoType::ExtProtoInfo DefaultEPI; |
| 3022 | FromTy = Importer.getFromContext().getFunctionType( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3023 | FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI); |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3024 | usedDifferentExceptionSpec = true; |
| 3025 | } |
| 3026 | } |
| 3027 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3028 | QualType T; |
| 3029 | TypeSourceInfo *TInfo; |
| 3030 | SourceLocation ToInnerLocStart, ToEndLoc; |
| 3031 | NestedNameSpecifierLoc ToQualifierLoc; |
| 3032 | if (auto Imp = importSeq( |
| 3033 | FromTy, D->getTypeSourceInfo(), D->getInnerLocStart(), |
| 3034 | D->getQualifierLoc(), D->getEndLoc())) |
| 3035 | std::tie(T, TInfo, ToInnerLocStart, ToQualifierLoc, ToEndLoc) = *Imp; |
| 3036 | else |
| 3037 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3038 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3039 | // Import the function parameters. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3040 | SmallVector<ParmVarDecl *, 8> Parameters; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3041 | for (auto P : D->parameters()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3042 | if (Expected<ParmVarDecl *> ToPOrErr = import(P)) |
| 3043 | Parameters.push_back(*ToPOrErr); |
| 3044 | else |
| 3045 | return ToPOrErr.takeError(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3046 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3047 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3048 | // Create the imported function. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3049 | FunctionDecl *ToFunction = nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3050 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3051 | if (GetImportedOrCreateDecl<CXXConstructorDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3052 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3053 | ToInnerLocStart, NameInfo, T, TInfo, |
| 3054 | FromConstructor->isExplicit(), |
| 3055 | D->isInlineSpecified(), D->isImplicit(), D->isConstexpr())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3056 | return ToFunction; |
Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3057 | } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) { |
| 3058 | |
| 3059 | auto Imp = |
| 3060 | importSeq(const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()), |
| 3061 | FromDtor->getOperatorDeleteThisArg()); |
| 3062 | |
| 3063 | if (!Imp) |
| 3064 | return Imp.takeError(); |
| 3065 | |
| 3066 | FunctionDecl *ToOperatorDelete; |
| 3067 | Expr *ToThisArg; |
| 3068 | std::tie(ToOperatorDelete, ToThisArg) = *Imp; |
| 3069 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3070 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3071 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3072 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| 3073 | D->isImplicit())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3074 | return ToFunction; |
Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3075 | |
| 3076 | CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction); |
| 3077 | |
| 3078 | ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3079 | } else if (CXXConversionDecl *FromConversion = |
| 3080 | dyn_cast<CXXConversionDecl>(D)) { |
| 3081 | if (GetImportedOrCreateDecl<CXXConversionDecl>( |
| 3082 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3083 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3084 | FromConversion->isExplicit(), D->isConstexpr(), SourceLocation())) |
| 3085 | return ToFunction; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3086 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3087 | if (GetImportedOrCreateDecl<CXXMethodDecl>( |
| 3088 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3089 | ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3090 | Method->isInlineSpecified(), D->isConstexpr(), SourceLocation())) |
| 3091 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3092 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3093 | if (GetImportedOrCreateDecl(ToFunction, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3094 | ToInnerLocStart, NameInfo, T, TInfo, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3095 | D->getStorageClass(), D->isInlineSpecified(), |
| 3096 | D->hasWrittenPrototype(), D->isConstexpr())) |
| 3097 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3098 | } |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3099 | |
Gabor Marton | f5e4f0a | 2018-11-20 14:19:39 +0000 | [diff] [blame] | 3100 | // Connect the redecl chain. |
| 3101 | if (FoundByLookup) { |
| 3102 | auto *Recent = const_cast<FunctionDecl *>( |
| 3103 | FoundByLookup->getMostRecentDecl()); |
| 3104 | ToFunction->setPreviousDecl(Recent); |
| 3105 | } |
| 3106 | |
| 3107 | // Import Ctor initializers. |
| 3108 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
| 3109 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
| 3110 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers); |
| 3111 | // Import first, then allocate memory and copy if there was no error. |
| 3112 | if (Error Err = ImportContainerChecked( |
| 3113 | FromConstructor->inits(), CtorInitializers)) |
| 3114 | return std::move(Err); |
| 3115 | auto **Memory = |
| 3116 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 3117 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
| 3118 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); |
| 3119 | ToCtor->setCtorInitializers(Memory); |
| 3120 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 3121 | } |
| 3122 | } |
| 3123 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3124 | ToFunction->setQualifierInfo(ToQualifierLoc); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3125 | ToFunction->setAccess(D->getAccess()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3126 | ToFunction->setLexicalDeclContext(LexicalDC); |
John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 3127 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 3128 | ToFunction->setTrivial(D->isTrivial()); |
| 3129 | ToFunction->setPure(D->isPure()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3130 | ToFunction->setRangeEnd(ToEndLoc); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3131 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3132 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3133 | for (auto *Param : Parameters) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3134 | Param->setOwningFunction(ToFunction); |
| 3135 | ToFunction->addDeclInternal(Param); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3136 | } |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 3137 | ToFunction->setParams(Parameters); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3138 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3139 | // We need to complete creation of FunctionProtoTypeLoc manually with setting |
| 3140 | // params it refers to. |
| 3141 | if (TInfo) { |
| 3142 | if (auto ProtoLoc = |
| 3143 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { |
| 3144 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) |
| 3145 | ProtoLoc.setParam(I, Parameters[I]); |
| 3146 | } |
| 3147 | } |
| 3148 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3149 | if (usedDifferentExceptionSpec) { |
| 3150 | // Update FunctionProtoType::ExtProtoInfo. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3151 | if (ExpectedType TyOrErr = import(D->getType())) |
| 3152 | ToFunction->setType(*TyOrErr); |
| 3153 | else |
| 3154 | return TyOrErr.takeError(); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 3155 | } |
| 3156 | |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3157 | // Import the describing template function, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3158 | if (FromFT) { |
| 3159 | auto ToFTOrErr = import(FromFT); |
| 3160 | if (!ToFTOrErr) |
| 3161 | return ToFTOrErr.takeError(); |
| 3162 | } |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3163 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3164 | if (D->doesThisDeclarationHaveABody()) { |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3165 | Error Err = ImportFunctionDeclBody(D, ToFunction); |
| 3166 | |
| 3167 | if (Err) |
| 3168 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3169 | } |
| 3170 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3171 | // FIXME: Other bits to merge? |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3172 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3173 | // If it is a template, import all related things. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3174 | if (Error Err = ImportTemplateInformation(D, ToFunction)) |
| 3175 | return std::move(Err); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3176 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3177 | bool IsFriend = D->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend); |
| 3178 | |
| 3179 | // TODO Can we generalize this approach to other AST nodes as well? |
| 3180 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 3181 | DC->addDeclInternal(ToFunction); |
| 3182 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3183 | LexicalDC->addDeclInternal(ToFunction); |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3184 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3185 | // Friend declaration's lexical context is the befriending class, but the |
| 3186 | // semantic context is the enclosing scope of the befriending class. |
| 3187 | // We want the friend functions to be found in the semantic context by lookup. |
| 3188 | // FIXME should we handle this generically in VisitFriendDecl? |
| 3189 | // In Other cases when LexicalDC != DC we don't want it to be added, |
| 3190 | // e.g out-of-class definitions like void B::f() {} . |
| 3191 | if (LexicalDC != DC && IsFriend) { |
| 3192 | DC->makeDeclVisibleInContext(ToFunction); |
| 3193 | } |
| 3194 | |
Gabor Marton | 7a0841e | 2018-10-29 10:18:28 +0000 | [diff] [blame] | 3195 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) |
| 3196 | ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod); |
| 3197 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3198 | // Import the rest of the chain. I.e. import all subsequent declarations. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3199 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3200 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 3201 | if (!ToRedeclOrErr) |
| 3202 | return ToRedeclOrErr.takeError(); |
| 3203 | } |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3204 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3205 | return ToFunction; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3206 | } |
| 3207 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3208 | ExpectedDecl ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3209 | return VisitFunctionDecl(D); |
| 3210 | } |
| 3211 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3212 | ExpectedDecl ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3213 | return VisitCXXMethodDecl(D); |
| 3214 | } |
| 3215 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3216 | ExpectedDecl ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3217 | return VisitCXXMethodDecl(D); |
| 3218 | } |
| 3219 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3220 | ExpectedDecl ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3221 | return VisitCXXMethodDecl(D); |
| 3222 | } |
| 3223 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3224 | ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3225 | // Import the major distinguishing characteristics of a variable. |
| 3226 | DeclContext *DC, *LexicalDC; |
| 3227 | DeclarationName Name; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3228 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3229 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3230 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3231 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3232 | if (ToD) |
| 3233 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3234 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3235 | // Determine whether we've already imported this field. |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3236 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3237 | for (auto *FoundDecl : FoundDecls) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3238 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3239 | // For anonymous fields, match up by index. |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3240 | if (!Name && |
| 3241 | ASTImporter::getFieldIndex(D) != |
| 3242 | ASTImporter::getFieldIndex(FoundField)) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3243 | continue; |
| 3244 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3245 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3246 | FoundField->getType())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3247 | Importer.MapImported(D, FoundField); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3248 | // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the |
| 3249 | // initializer of a FieldDecl might not had been instantiated in the |
| 3250 | // "To" context. However, the "From" context might instantiated that, |
| 3251 | // thus we have to merge that. |
| 3252 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
| 3253 | // We don't have yet the initializer set. |
| 3254 | if (FoundField->hasInClassInitializer() && |
| 3255 | !FoundField->getInClassInitializer()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3256 | if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) |
| 3257 | FoundField->setInClassInitializer(*ToInitializerOrErr); |
| 3258 | else { |
| 3259 | // We can't return error here, |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3260 | // since we already mapped D as imported. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3261 | // FIXME: warning message? |
| 3262 | consumeError(ToInitializerOrErr.takeError()); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3263 | return FoundField; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3264 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3265 | } |
| 3266 | } |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3267 | return FoundField; |
| 3268 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3269 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3270 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3271 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3272 | << Name << D->getType() << FoundField->getType(); |
| 3273 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3274 | << FoundField->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3275 | |
| 3276 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3277 | } |
| 3278 | } |
| 3279 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3280 | QualType ToType; |
| 3281 | TypeSourceInfo *ToTInfo; |
| 3282 | Expr *ToBitWidth; |
| 3283 | SourceLocation ToInnerLocStart; |
| 3284 | Expr *ToInitializer; |
| 3285 | if (auto Imp = importSeq( |
| 3286 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), |
| 3287 | D->getInnerLocStart(), D->getInClassInitializer())) |
| 3288 | std::tie( |
| 3289 | ToType, ToTInfo, ToBitWidth, ToInnerLocStart, ToInitializer) = *Imp; |
| 3290 | else |
| 3291 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3292 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3293 | FieldDecl *ToField; |
| 3294 | if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3295 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3296 | ToType, ToTInfo, ToBitWidth, D->isMutable(), |
| 3297 | D->getInClassInitStyle())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3298 | return ToField; |
| 3299 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3300 | ToField->setAccess(D->getAccess()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3301 | ToField->setLexicalDeclContext(LexicalDC); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3302 | if (ToInitializer) |
| 3303 | ToField->setInClassInitializer(ToInitializer); |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3304 | ToField->setImplicit(D->isImplicit()); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3305 | LexicalDC->addDeclInternal(ToField); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3306 | return ToField; |
| 3307 | } |
| 3308 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3309 | ExpectedDecl ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3310 | // Import the major distinguishing characteristics of a variable. |
| 3311 | DeclContext *DC, *LexicalDC; |
| 3312 | DeclarationName Name; |
| 3313 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3314 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3315 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3316 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3317 | if (ToD) |
| 3318 | return ToD; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3319 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3320 | // Determine whether we've already imported this field. |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3321 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3322 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3323 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3324 | // For anonymous indirect fields, match up by index. |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3325 | if (!Name && |
| 3326 | ASTImporter::getFieldIndex(D) != |
| 3327 | ASTImporter::getFieldIndex(FoundField)) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3328 | continue; |
| 3329 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3330 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3331 | FoundField->getType(), |
David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 3332 | !Name.isEmpty())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3333 | Importer.MapImported(D, FoundField); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3334 | return FoundField; |
| 3335 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3336 | |
| 3337 | // If there are more anonymous fields to check, continue. |
| 3338 | if (!Name && I < N-1) |
| 3339 | continue; |
| 3340 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3341 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3342 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3343 | << Name << D->getType() << FoundField->getType(); |
| 3344 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3345 | << FoundField->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3346 | |
| 3347 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3348 | } |
| 3349 | } |
| 3350 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3351 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3352 | auto TypeOrErr = import(D->getType()); |
| 3353 | if (!TypeOrErr) |
| 3354 | return TypeOrErr.takeError(); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3355 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3356 | auto **NamedChain = |
| 3357 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3358 | |
| 3359 | unsigned i = 0; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3360 | for (auto *PI : D->chain()) |
| 3361 | if (Expected<NamedDecl *> ToD = import(PI)) |
| 3362 | NamedChain[i++] = *ToD; |
| 3363 | else |
| 3364 | return ToD.takeError(); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3365 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3366 | llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()}; |
| 3367 | IndirectFieldDecl *ToIndirectField; |
| 3368 | if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3369 | Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3370 | // FIXME here we leak `NamedChain` which is allocated before |
| 3371 | return ToIndirectField; |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 3372 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3373 | ToIndirectField->setAccess(D->getAccess()); |
| 3374 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3375 | LexicalDC->addDeclInternal(ToIndirectField); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3376 | return ToIndirectField; |
| 3377 | } |
| 3378 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3379 | ExpectedDecl ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3380 | // Import the major distinguishing characteristics of a declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3381 | DeclContext *DC, *LexicalDC; |
| 3382 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 3383 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3384 | |
| 3385 | // Determine whether we've already imported this decl. |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3386 | // FriendDecl is not a NamedDecl so we cannot use lookup. |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3387 | auto *RD = cast<CXXRecordDecl>(DC); |
| 3388 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3389 | |
| 3390 | while (ImportedFriend) { |
| 3391 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 3392 | if (IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(), |
| 3393 | /*Complain=*/false)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3394 | return Importer.MapImported(D, ImportedFriend); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3395 | |
| 3396 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| 3397 | if (Importer.IsStructurallyEquivalent( |
| 3398 | D->getFriendType()->getType(), |
| 3399 | ImportedFriend->getFriendType()->getType(), true)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3400 | return Importer.MapImported(D, ImportedFriend); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3401 | } |
| 3402 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 3403 | } |
| 3404 | |
| 3405 | // Not found. Create it. |
| 3406 | FriendDecl::FriendUnion ToFU; |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3407 | if (NamedDecl *FriendD = D->getFriendDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3408 | NamedDecl *ToFriendD; |
| 3409 | if (Error Err = importInto(ToFriendD, FriendD)) |
| 3410 | return std::move(Err); |
| 3411 | |
| 3412 | if (FriendD->getFriendObjectKind() != Decl::FOK_None && |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3413 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) |
| 3414 | ToFriendD->setObjectOfFriendDecl(false); |
| 3415 | |
| 3416 | ToFU = ToFriendD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3417 | } else { // The friend is a type, not a decl. |
| 3418 | if (auto TSIOrErr = import(D->getFriendType())) |
| 3419 | ToFU = *TSIOrErr; |
| 3420 | else |
| 3421 | return TSIOrErr.takeError(); |
| 3422 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3423 | |
| 3424 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3425 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3426 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 3427 | if (auto ListOrErr = import(FromTPLists[I])) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3428 | ToTPLists[I] = *ListOrErr; |
| 3429 | else |
| 3430 | return ListOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3431 | } |
| 3432 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3433 | auto LocationOrErr = import(D->getLocation()); |
| 3434 | if (!LocationOrErr) |
| 3435 | return LocationOrErr.takeError(); |
| 3436 | auto FriendLocOrErr = import(D->getFriendLoc()); |
| 3437 | if (!FriendLocOrErr) |
| 3438 | return FriendLocOrErr.takeError(); |
| 3439 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3440 | FriendDecl *FrD; |
| 3441 | if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3442 | *LocationOrErr, ToFU, |
| 3443 | *FriendLocOrErr, ToTPLists)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3444 | return FrD; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3445 | |
| 3446 | FrD->setAccess(D->getAccess()); |
| 3447 | FrD->setLexicalDeclContext(LexicalDC); |
| 3448 | LexicalDC->addDeclInternal(FrD); |
| 3449 | return FrD; |
| 3450 | } |
| 3451 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3452 | ExpectedDecl ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3453 | // Import the major distinguishing characteristics of an ivar. |
| 3454 | DeclContext *DC, *LexicalDC; |
| 3455 | DeclarationName Name; |
| 3456 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3457 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3458 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3459 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3460 | if (ToD) |
| 3461 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3462 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3463 | // Determine whether we've already imported this ivar |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3464 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3465 | for (auto *FoundDecl : FoundDecls) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3466 | if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3467 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3468 | FoundIvar->getType())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3469 | Importer.MapImported(D, FoundIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3470 | return FoundIvar; |
| 3471 | } |
| 3472 | |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3473 | Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent) |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3474 | << Name << D->getType() << FoundIvar->getType(); |
| 3475 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) |
| 3476 | << FoundIvar->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3477 | |
| 3478 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3479 | } |
| 3480 | } |
| 3481 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3482 | QualType ToType; |
| 3483 | TypeSourceInfo *ToTypeSourceInfo; |
| 3484 | Expr *ToBitWidth; |
| 3485 | SourceLocation ToInnerLocStart; |
| 3486 | if (auto Imp = importSeq( |
| 3487 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), D->getInnerLocStart())) |
| 3488 | std::tie(ToType, ToTypeSourceInfo, ToBitWidth, ToInnerLocStart) = *Imp; |
| 3489 | else |
| 3490 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3491 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3492 | ObjCIvarDecl *ToIvar; |
| 3493 | if (GetImportedOrCreateDecl( |
| 3494 | ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3495 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3496 | ToType, ToTypeSourceInfo, |
| 3497 | D->getAccessControl(),ToBitWidth, D->getSynthesize())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3498 | return ToIvar; |
| 3499 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3500 | ToIvar->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3501 | LexicalDC->addDeclInternal(ToIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3502 | return ToIvar; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3503 | } |
| 3504 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3505 | ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) { |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3506 | |
| 3507 | SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D); |
| 3508 | auto RedeclIt = Redecls.begin(); |
| 3509 | // Import the first part of the decl chain. I.e. import all previous |
| 3510 | // declarations starting from the canonical decl. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3511 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 3512 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3513 | if (!RedeclOrErr) |
| 3514 | return RedeclOrErr.takeError(); |
| 3515 | } |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3516 | assert(*RedeclIt == D); |
| 3517 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3518 | // Import the major distinguishing characteristics of a variable. |
| 3519 | DeclContext *DC, *LexicalDC; |
| 3520 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3521 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3522 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3523 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3524 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3525 | if (ToD) |
| 3526 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3527 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3528 | // Try to find a variable in our own ("to") context with the same name and |
| 3529 | // in the same context as the variable we're importing. |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3530 | VarDecl *FoundByLookup = nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3531 | if (D->isFileVarDecl()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3532 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3533 | unsigned IDNS = Decl::IDNS_Ordinary; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3534 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3535 | for (auto *FoundDecl : FoundDecls) { |
| 3536 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3537 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3538 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3539 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3540 | if (!hasSameVisibilityContext(FoundVar, D)) |
| 3541 | continue; |
| 3542 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| 3543 | FoundVar->getType())) { |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3544 | |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3545 | // The VarDecl in the "From" context has a definition, but in the |
| 3546 | // "To" context we already have a definition. |
| 3547 | VarDecl *FoundDef = FoundVar->getDefinition(); |
| 3548 | if (D->isThisDeclarationADefinition() && FoundDef) |
| 3549 | // FIXME Check for ODR error if the two definitions have |
| 3550 | // different initializers? |
| 3551 | return Importer.MapImported(D, FoundDef); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3552 | |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3553 | // The VarDecl in the "From" context has an initializer, but in the |
| 3554 | // "To" context we already have an initializer. |
| 3555 | const VarDecl *FoundDInit = nullptr; |
| 3556 | if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit)) |
| 3557 | // FIXME Diagnose ODR error if the two initializers are different? |
| 3558 | return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit)); |
| 3559 | |
| 3560 | FoundByLookup = FoundVar; |
| 3561 | break; |
| 3562 | } |
| 3563 | |
| 3564 | const ArrayType *FoundArray |
| 3565 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 3566 | const ArrayType *TArray |
| 3567 | = Importer.getToContext().getAsArrayType(D->getType()); |
| 3568 | if (FoundArray && TArray) { |
| 3569 | if (isa<IncompleteArrayType>(FoundArray) && |
| 3570 | isa<ConstantArrayType>(TArray)) { |
| 3571 | // Import the type. |
| 3572 | if (auto TyOrErr = import(D->getType())) |
| 3573 | FoundVar->setType(*TyOrErr); |
| 3574 | else |
| 3575 | return TyOrErr.takeError(); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3576 | |
| 3577 | FoundByLookup = FoundVar; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3578 | break; |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3579 | } else if (isa<IncompleteArrayType>(TArray) && |
| 3580 | isa<ConstantArrayType>(FoundArray)) { |
| 3581 | FoundByLookup = FoundVar; |
| 3582 | break; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3583 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3584 | } |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3585 | |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3586 | Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent) |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3587 | << Name << D->getType() << FoundVar->getType(); |
| 3588 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 3589 | << FoundVar->getType(); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3590 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3591 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3592 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3593 | } |
| 3594 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3595 | if (!ConflictingDecls.empty()) { |
| 3596 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3597 | ConflictingDecls.data(), |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3598 | ConflictingDecls.size()); |
| 3599 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3600 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3601 | } |
| 3602 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3603 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3604 | QualType ToType; |
| 3605 | TypeSourceInfo *ToTypeSourceInfo; |
| 3606 | SourceLocation ToInnerLocStart; |
| 3607 | NestedNameSpecifierLoc ToQualifierLoc; |
| 3608 | if (auto Imp = importSeq( |
| 3609 | D->getType(), D->getTypeSourceInfo(), D->getInnerLocStart(), |
| 3610 | D->getQualifierLoc())) |
| 3611 | std::tie(ToType, ToTypeSourceInfo, ToInnerLocStart, ToQualifierLoc) = *Imp; |
| 3612 | else |
| 3613 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3614 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3615 | // Create the imported variable. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3616 | VarDecl *ToVar; |
| 3617 | if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3618 | ToInnerLocStart, Loc, |
| 3619 | Name.getAsIdentifierInfo(), |
| 3620 | ToType, ToTypeSourceInfo, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3621 | D->getStorageClass())) |
| 3622 | return ToVar; |
| 3623 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3624 | ToVar->setQualifierInfo(ToQualifierLoc); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3625 | ToVar->setAccess(D->getAccess()); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3626 | ToVar->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3627 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3628 | if (FoundByLookup) { |
| 3629 | auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl()); |
| 3630 | ToVar->setPreviousDecl(Recent); |
| 3631 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3632 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3633 | if (Error Err = ImportInitializer(D, ToVar)) |
| 3634 | return std::move(Err); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3635 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3636 | if (D->isConstexpr()) |
| 3637 | ToVar->setConstexpr(true); |
| 3638 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3639 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 3640 | DC->addDeclInternal(ToVar); |
| 3641 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
| 3642 | LexicalDC->addDeclInternal(ToVar); |
| 3643 | |
| 3644 | // Import the rest of the chain. I.e. import all subsequent declarations. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3645 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3646 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3647 | if (!RedeclOrErr) |
| 3648 | return RedeclOrErr.takeError(); |
| 3649 | } |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3650 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3651 | return ToVar; |
| 3652 | } |
| 3653 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3654 | ExpectedDecl ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3655 | // Parameters are created in the translation unit's context, then moved |
| 3656 | // into the function declaration's context afterward. |
| 3657 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3658 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3659 | DeclarationName ToDeclName; |
| 3660 | SourceLocation ToLocation; |
| 3661 | QualType ToType; |
| 3662 | if (auto Imp = importSeq(D->getDeclName(), D->getLocation(), D->getType())) |
| 3663 | std::tie(ToDeclName, ToLocation, ToType) = *Imp; |
| 3664 | else |
| 3665 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3666 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3667 | // Create the imported parameter. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3668 | ImplicitParamDecl *ToParm = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3669 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
| 3670 | ToLocation, ToDeclName.getAsIdentifierInfo(), |
| 3671 | ToType, D->getParameterKind())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3672 | return ToParm; |
| 3673 | return ToParm; |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3674 | } |
| 3675 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3676 | ExpectedDecl ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3677 | // Parameters are created in the translation unit's context, then moved |
| 3678 | // into the function declaration's context afterward. |
| 3679 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3680 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3681 | DeclarationName ToDeclName; |
| 3682 | SourceLocation ToLocation, ToInnerLocStart; |
| 3683 | QualType ToType; |
| 3684 | TypeSourceInfo *ToTypeSourceInfo; |
| 3685 | if (auto Imp = importSeq( |
| 3686 | D->getDeclName(), D->getLocation(), D->getType(), D->getInnerLocStart(), |
| 3687 | D->getTypeSourceInfo())) |
| 3688 | std::tie( |
| 3689 | ToDeclName, ToLocation, ToType, ToInnerLocStart, |
| 3690 | ToTypeSourceInfo) = *Imp; |
| 3691 | else |
| 3692 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3693 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3694 | ParmVarDecl *ToParm; |
| 3695 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3696 | ToInnerLocStart, ToLocation, |
| 3697 | ToDeclName.getAsIdentifierInfo(), ToType, |
| 3698 | ToTypeSourceInfo, D->getStorageClass(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3699 | /*DefaultArg*/ nullptr)) |
| 3700 | return ToParm; |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3701 | |
| 3702 | // Set the default argument. |
John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 3703 | ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg()); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3704 | ToParm->setKNRPromoted(D->isKNRPromoted()); |
| 3705 | |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3706 | if (D->hasUninstantiatedDefaultArg()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3707 | if (auto ToDefArgOrErr = import(D->getUninstantiatedDefaultArg())) |
| 3708 | ToParm->setUninstantiatedDefaultArg(*ToDefArgOrErr); |
| 3709 | else |
| 3710 | return ToDefArgOrErr.takeError(); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3711 | } else if (D->hasUnparsedDefaultArg()) { |
| 3712 | ToParm->setUnparsedDefaultArg(); |
| 3713 | } else if (D->hasDefaultArg()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3714 | if (auto ToDefArgOrErr = import(D->getDefaultArg())) |
| 3715 | ToParm->setDefaultArg(*ToDefArgOrErr); |
| 3716 | else |
| 3717 | return ToDefArgOrErr.takeError(); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3718 | } |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3719 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3720 | if (D->isObjCMethodParameter()) { |
| 3721 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); |
| 3722 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); |
| 3723 | } else { |
| 3724 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), |
| 3725 | D->getFunctionScopeIndex()); |
| 3726 | } |
| 3727 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3728 | return ToParm; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3729 | } |
| 3730 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3731 | ExpectedDecl ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3732 | // Import the major distinguishing characteristics of a method. |
| 3733 | DeclContext *DC, *LexicalDC; |
| 3734 | DeclarationName Name; |
| 3735 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3736 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3737 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3738 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3739 | if (ToD) |
| 3740 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3741 | |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3742 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3743 | for (auto *FoundDecl : FoundDecls) { |
| 3744 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3745 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 3746 | continue; |
| 3747 | |
| 3748 | // Check return types. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3749 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 3750 | FoundMethod->getReturnType())) { |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3751 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent) |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3752 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 3753 | << FoundMethod->getReturnType(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3754 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3755 | diag::note_odr_objc_method_here) |
| 3756 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3757 | |
| 3758 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3759 | } |
| 3760 | |
| 3761 | // Check the number of parameters. |
| 3762 | if (D->param_size() != FoundMethod->param_size()) { |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3763 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent) |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3764 | << D->isInstanceMethod() << Name |
| 3765 | << D->param_size() << FoundMethod->param_size(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3766 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3767 | diag::note_odr_objc_method_here) |
| 3768 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3769 | |
| 3770 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3771 | } |
| 3772 | |
| 3773 | // Check parameter types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3774 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3775 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 3776 | P != PEnd; ++P, ++FoundP) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3777 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3778 | (*FoundP)->getType())) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3779 | Importer.FromDiag((*P)->getLocation(), |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3780 | diag::warn_odr_objc_method_param_type_inconsistent) |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3781 | << D->isInstanceMethod() << Name |
| 3782 | << (*P)->getType() << (*FoundP)->getType(); |
| 3783 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 3784 | << (*FoundP)->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3785 | |
| 3786 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3787 | } |
| 3788 | } |
| 3789 | |
| 3790 | // Check variadic/non-variadic. |
| 3791 | // Check the number of parameters. |
| 3792 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3793 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent) |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3794 | << D->isInstanceMethod() << Name; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3795 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3796 | diag::note_odr_objc_method_here) |
| 3797 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3798 | |
| 3799 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3800 | } |
| 3801 | |
| 3802 | // FIXME: Any other bits we need to merge? |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3803 | return Importer.MapImported(D, FoundMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3804 | } |
| 3805 | } |
| 3806 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3807 | SourceLocation ToEndLoc; |
| 3808 | QualType ToReturnType; |
| 3809 | TypeSourceInfo *ToReturnTypeSourceInfo; |
| 3810 | if (auto Imp = importSeq( |
| 3811 | D->getEndLoc(), D->getReturnType(), D->getReturnTypeSourceInfo())) |
| 3812 | std::tie(ToEndLoc, ToReturnType, ToReturnTypeSourceInfo) = *Imp; |
| 3813 | else |
| 3814 | return Imp.takeError(); |
Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 3815 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3816 | ObjCMethodDecl *ToMethod; |
| 3817 | if (GetImportedOrCreateDecl( |
| 3818 | ToMethod, D, Importer.getToContext(), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3819 | ToEndLoc, Name.getObjCSelector(), ToReturnType, |
| 3820 | ToReturnTypeSourceInfo, DC, D->isInstanceMethod(), D->isVariadic(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3821 | D->isPropertyAccessor(), D->isImplicit(), D->isDefined(), |
| 3822 | D->getImplementationControl(), D->hasRelatedResultType())) |
| 3823 | return ToMethod; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3824 | |
| 3825 | // FIXME: When we decide to merge method definitions, we'll need to |
| 3826 | // deal with implicit parameters. |
| 3827 | |
| 3828 | // Import the parameters |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3829 | SmallVector<ParmVarDecl *, 5> ToParams; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3830 | for (auto *FromP : D->parameters()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3831 | if (Expected<ParmVarDecl *> ToPOrErr = import(FromP)) |
| 3832 | ToParams.push_back(*ToPOrErr); |
| 3833 | else |
| 3834 | return ToPOrErr.takeError(); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3835 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3836 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3837 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3838 | for (auto *ToParam : ToParams) { |
| 3839 | ToParam->setOwningFunction(ToMethod); |
| 3840 | ToMethod->addDeclInternal(ToParam); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3841 | } |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3842 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3843 | SmallVector<SourceLocation, 12> FromSelLocs; |
| 3844 | D->getSelectorLocs(FromSelLocs); |
| 3845 | SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size()); |
| 3846 | if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs)) |
| 3847 | return std::move(Err); |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3848 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3849 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3850 | |
| 3851 | ToMethod->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3852 | LexicalDC->addDeclInternal(ToMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3853 | return ToMethod; |
| 3854 | } |
| 3855 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3856 | ExpectedDecl ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3857 | // Import the major distinguishing characteristics of a category. |
| 3858 | DeclContext *DC, *LexicalDC; |
| 3859 | DeclarationName Name; |
| 3860 | SourceLocation Loc; |
| 3861 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3862 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3863 | return std::move(Err); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3864 | if (ToD) |
| 3865 | return ToD; |
| 3866 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3867 | SourceLocation ToVarianceLoc, ToLocation, ToColonLoc; |
| 3868 | TypeSourceInfo *ToTypeSourceInfo; |
| 3869 | if (auto Imp = importSeq( |
| 3870 | D->getVarianceLoc(), D->getLocation(), D->getColonLoc(), |
| 3871 | D->getTypeSourceInfo())) |
| 3872 | std::tie(ToVarianceLoc, ToLocation, ToColonLoc, ToTypeSourceInfo) = *Imp; |
| 3873 | else |
| 3874 | return Imp.takeError(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3875 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3876 | ObjCTypeParamDecl *Result; |
| 3877 | if (GetImportedOrCreateDecl( |
| 3878 | Result, D, Importer.getToContext(), DC, D->getVariance(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3879 | ToVarianceLoc, D->getIndex(), |
| 3880 | ToLocation, Name.getAsIdentifierInfo(), |
| 3881 | ToColonLoc, ToTypeSourceInfo)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3882 | return Result; |
| 3883 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3884 | Result->setLexicalDeclContext(LexicalDC); |
| 3885 | return Result; |
| 3886 | } |
| 3887 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3888 | ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3889 | // Import the major distinguishing characteristics of a category. |
| 3890 | DeclContext *DC, *LexicalDC; |
| 3891 | DeclarationName Name; |
| 3892 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3893 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3894 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3895 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3896 | if (ToD) |
| 3897 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3898 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3899 | ObjCInterfaceDecl *ToInterface; |
| 3900 | if (Error Err = importInto(ToInterface, D->getClassInterface())) |
| 3901 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3902 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3903 | // Determine if we've already encountered this category. |
| 3904 | ObjCCategoryDecl *MergeWithCategory |
| 3905 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 3906 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 3907 | if (!ToCategory) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3908 | SourceLocation ToAtStartLoc, ToCategoryNameLoc; |
| 3909 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; |
| 3910 | if (auto Imp = importSeq( |
| 3911 | D->getAtStartLoc(), D->getCategoryNameLoc(), |
| 3912 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) |
| 3913 | std::tie( |
| 3914 | ToAtStartLoc, ToCategoryNameLoc, |
| 3915 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; |
| 3916 | else |
| 3917 | return Imp.takeError(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3918 | |
| 3919 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3920 | ToAtStartLoc, Loc, |
| 3921 | ToCategoryNameLoc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3922 | Name.getAsIdentifierInfo(), ToInterface, |
| 3923 | /*TypeParamList=*/nullptr, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3924 | ToIvarLBraceLoc, |
| 3925 | ToIvarRBraceLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3926 | return ToCategory; |
| 3927 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3928 | ToCategory->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3929 | LexicalDC->addDeclInternal(ToCategory); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3930 | // Import the type parameter list after MapImported, to avoid |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3931 | // loops when bringing in their DeclContext. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3932 | if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList())) |
| 3933 | ToCategory->setTypeParamList(*PListOrErr); |
| 3934 | else |
| 3935 | return PListOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3936 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3937 | // Import protocols |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3938 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3939 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3940 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 3941 | = D->protocol_loc_begin(); |
| 3942 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 3943 | FromProtoEnd = D->protocol_end(); |
| 3944 | FromProto != FromProtoEnd; |
| 3945 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3946 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 3947 | Protocols.push_back(*ToProtoOrErr); |
| 3948 | else |
| 3949 | return ToProtoOrErr.takeError(); |
| 3950 | |
| 3951 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 3952 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 3953 | else |
| 3954 | return ToProtoLocOrErr.takeError(); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3955 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3956 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3957 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3958 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 3959 | ProtocolLocs.data(), Importer.getToContext()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3960 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3961 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3962 | Importer.MapImported(D, ToCategory); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3963 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3964 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3965 | // Import all of the members of this category. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3966 | if (Error Err = ImportDeclContext(D)) |
| 3967 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3968 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3969 | // If we have an implementation, import it as well. |
| 3970 | if (D->getImplementation()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3971 | if (Expected<ObjCCategoryImplDecl *> ToImplOrErr = |
| 3972 | import(D->getImplementation())) |
| 3973 | ToCategory->setImplementation(*ToImplOrErr); |
| 3974 | else |
| 3975 | return ToImplOrErr.takeError(); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3976 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3977 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3978 | return ToCategory; |
| 3979 | } |
| 3980 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3981 | Error ASTNodeImporter::ImportDefinition( |
| 3982 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3983 | if (To->getDefinition()) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3984 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3985 | if (Error Err = ImportDeclContext(From)) |
| 3986 | return Err; |
| 3987 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3988 | } |
| 3989 | |
| 3990 | // Start the protocol definition |
| 3991 | To->startDefinition(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3992 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3993 | // Import protocols |
| 3994 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3995 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3996 | ObjCProtocolDecl::protocol_loc_iterator FromProtoLoc = |
| 3997 | From->protocol_loc_begin(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3998 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 3999 | FromProtoEnd = From->protocol_end(); |
| 4000 | FromProto != FromProtoEnd; |
| 4001 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4002 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4003 | Protocols.push_back(*ToProtoOrErr); |
| 4004 | else |
| 4005 | return ToProtoOrErr.takeError(); |
| 4006 | |
| 4007 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4008 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4009 | else |
| 4010 | return ToProtoLocOrErr.takeError(); |
| 4011 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4012 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4013 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4014 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4015 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4016 | ProtocolLocs.data(), Importer.getToContext()); |
| 4017 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4018 | if (shouldForceImportDeclContext(Kind)) { |
| 4019 | // Import all of the members of this protocol. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4020 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4021 | return Err; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4022 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4023 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4024 | } |
| 4025 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4026 | ExpectedDecl ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4027 | // 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] | 4028 | // from, but this particular declaration is not that definition, import the |
| 4029 | // definition and map to that. |
| 4030 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 4031 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4032 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4033 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4034 | else |
| 4035 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4036 | } |
| 4037 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4038 | // Import the major distinguishing characteristics of a protocol. |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4039 | DeclContext *DC, *LexicalDC; |
| 4040 | DeclarationName Name; |
| 4041 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4042 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4043 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4044 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4045 | if (ToD) |
| 4046 | return ToD; |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4047 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4048 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4049 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4050 | for (auto *FoundDecl : FoundDecls) { |
| 4051 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4052 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4053 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4054 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4055 | break; |
| 4056 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4057 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4058 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4059 | if (!ToProto) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4060 | auto ToAtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4061 | if (!ToAtBeginLocOrErr) |
| 4062 | return ToAtBeginLocOrErr.takeError(); |
| 4063 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4064 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, |
| 4065 | Name.getAsIdentifierInfo(), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4066 | *ToAtBeginLocOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4067 | /*PrevDecl=*/nullptr)) |
| 4068 | return ToProto; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4069 | ToProto->setLexicalDeclContext(LexicalDC); |
| 4070 | LexicalDC->addDeclInternal(ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4071 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4072 | |
| 4073 | Importer.MapImported(D, ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4074 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4075 | if (D->isThisDeclarationADefinition()) |
| 4076 | if (Error Err = ImportDefinition(D, ToProto)) |
| 4077 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4078 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4079 | return ToProto; |
| 4080 | } |
| 4081 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4082 | ExpectedDecl ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 4083 | DeclContext *DC, *LexicalDC; |
| 4084 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4085 | return std::move(Err); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4086 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4087 | ExpectedSLoc ExternLocOrErr = import(D->getExternLoc()); |
| 4088 | if (!ExternLocOrErr) |
| 4089 | return ExternLocOrErr.takeError(); |
| 4090 | |
| 4091 | ExpectedSLoc LangLocOrErr = import(D->getLocation()); |
| 4092 | if (!LangLocOrErr) |
| 4093 | return LangLocOrErr.takeError(); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4094 | |
| 4095 | bool HasBraces = D->hasBraces(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4096 | |
| 4097 | LinkageSpecDecl *ToLinkageSpec; |
| 4098 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4099 | *ExternLocOrErr, *LangLocOrErr, |
| 4100 | D->getLanguage(), HasBraces)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4101 | return ToLinkageSpec; |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4102 | |
| 4103 | if (HasBraces) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4104 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); |
| 4105 | if (!RBraceLocOrErr) |
| 4106 | return RBraceLocOrErr.takeError(); |
| 4107 | ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4108 | } |
| 4109 | |
| 4110 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 4111 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 4112 | |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4113 | return ToLinkageSpec; |
| 4114 | } |
| 4115 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4116 | ExpectedDecl ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4117 | DeclContext *DC, *LexicalDC; |
| 4118 | DeclarationName Name; |
| 4119 | SourceLocation Loc; |
| 4120 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4121 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4122 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4123 | if (ToD) |
| 4124 | return ToD; |
| 4125 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4126 | SourceLocation ToLoc, ToUsingLoc; |
| 4127 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4128 | if (auto Imp = importSeq( |
| 4129 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc())) |
| 4130 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc) = *Imp; |
| 4131 | else |
| 4132 | return Imp.takeError(); |
| 4133 | |
| 4134 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4135 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4136 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4137 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4138 | UsingDecl *ToUsing; |
| 4139 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4140 | ToUsingLoc, ToQualifierLoc, NameInfo, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4141 | D->hasTypename())) |
| 4142 | return ToUsing; |
| 4143 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4144 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4145 | LexicalDC->addDeclInternal(ToUsing); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4146 | |
| 4147 | if (NamedDecl *FromPattern = |
| 4148 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4149 | if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern)) |
| 4150 | Importer.getToContext().setInstantiatedFromUsingDecl( |
| 4151 | ToUsing, *ToPatternOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4152 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4153 | return ToPatternOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4154 | } |
| 4155 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4156 | for (UsingShadowDecl *FromShadow : D->shadows()) { |
| 4157 | if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow)) |
| 4158 | ToUsing->addShadowDecl(*ToShadowOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4159 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4160 | // FIXME: We return error here but the definition is already created |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4161 | // and available with lookups. How to fix this?.. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4162 | return ToShadowOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4163 | } |
| 4164 | return ToUsing; |
| 4165 | } |
| 4166 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4167 | ExpectedDecl ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4168 | DeclContext *DC, *LexicalDC; |
| 4169 | DeclarationName Name; |
| 4170 | SourceLocation Loc; |
| 4171 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4172 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4173 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4174 | if (ToD) |
| 4175 | return ToD; |
| 4176 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4177 | Expected<UsingDecl *> ToUsingOrErr = import(D->getUsingDecl()); |
| 4178 | if (!ToUsingOrErr) |
| 4179 | return ToUsingOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4180 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4181 | Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl()); |
| 4182 | if (!ToTargetOrErr) |
| 4183 | return ToTargetOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4184 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4185 | UsingShadowDecl *ToShadow; |
| 4186 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4187 | *ToUsingOrErr, *ToTargetOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4188 | return ToShadow; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4189 | |
| 4190 | ToShadow->setLexicalDeclContext(LexicalDC); |
| 4191 | ToShadow->setAccess(D->getAccess()); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4192 | |
| 4193 | if (UsingShadowDecl *FromPattern = |
| 4194 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4195 | if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern)) |
| 4196 | Importer.getToContext().setInstantiatedFromUsingShadowDecl( |
| 4197 | ToShadow, *ToPatternOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4198 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4199 | // FIXME: We return error here but the definition is already created |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4200 | // and available with lookups. How to fix this?.. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4201 | return ToPatternOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4202 | } |
| 4203 | |
| 4204 | LexicalDC->addDeclInternal(ToShadow); |
| 4205 | |
| 4206 | return ToShadow; |
| 4207 | } |
| 4208 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4209 | ExpectedDecl ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4210 | DeclContext *DC, *LexicalDC; |
| 4211 | DeclarationName Name; |
| 4212 | SourceLocation Loc; |
| 4213 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4214 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4215 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4216 | if (ToD) |
| 4217 | return ToD; |
| 4218 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4219 | auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor()); |
| 4220 | if (!ToComAncestorOrErr) |
| 4221 | return ToComAncestorOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4222 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4223 | NamespaceDecl *ToNominatedNamespace; |
| 4224 | SourceLocation ToUsingLoc, ToNamespaceKeyLocation, ToIdentLocation; |
| 4225 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4226 | if (auto Imp = importSeq( |
| 4227 | D->getNominatedNamespace(), D->getUsingLoc(), |
| 4228 | D->getNamespaceKeyLocation(), D->getQualifierLoc(), |
| 4229 | D->getIdentLocation())) |
| 4230 | std::tie( |
| 4231 | ToNominatedNamespace, ToUsingLoc, ToNamespaceKeyLocation, |
| 4232 | ToQualifierLoc, ToIdentLocation) = *Imp; |
| 4233 | else |
| 4234 | return Imp.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4235 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4236 | UsingDirectiveDecl *ToUsingDir; |
| 4237 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4238 | ToUsingLoc, |
| 4239 | ToNamespaceKeyLocation, |
| 4240 | ToQualifierLoc, |
| 4241 | ToIdentLocation, |
| 4242 | ToNominatedNamespace, *ToComAncestorOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4243 | return ToUsingDir; |
| 4244 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4245 | ToUsingDir->setLexicalDeclContext(LexicalDC); |
| 4246 | LexicalDC->addDeclInternal(ToUsingDir); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4247 | |
| 4248 | return ToUsingDir; |
| 4249 | } |
| 4250 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4251 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4252 | UnresolvedUsingValueDecl *D) { |
| 4253 | DeclContext *DC, *LexicalDC; |
| 4254 | DeclarationName Name; |
| 4255 | SourceLocation Loc; |
| 4256 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4257 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4258 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4259 | if (ToD) |
| 4260 | return ToD; |
| 4261 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4262 | SourceLocation ToLoc, ToUsingLoc, ToEllipsisLoc; |
| 4263 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4264 | if (auto Imp = importSeq( |
| 4265 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc(), |
| 4266 | D->getEllipsisLoc())) |
| 4267 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; |
| 4268 | else |
| 4269 | return Imp.takeError(); |
| 4270 | |
| 4271 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4272 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4273 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4274 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4275 | UnresolvedUsingValueDecl *ToUsingValue; |
| 4276 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4277 | ToUsingLoc, ToQualifierLoc, NameInfo, |
| 4278 | ToEllipsisLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4279 | return ToUsingValue; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4280 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4281 | ToUsingValue->setAccess(D->getAccess()); |
| 4282 | ToUsingValue->setLexicalDeclContext(LexicalDC); |
| 4283 | LexicalDC->addDeclInternal(ToUsingValue); |
| 4284 | |
| 4285 | return ToUsingValue; |
| 4286 | } |
| 4287 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4288 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4289 | UnresolvedUsingTypenameDecl *D) { |
| 4290 | DeclContext *DC, *LexicalDC; |
| 4291 | DeclarationName Name; |
| 4292 | SourceLocation Loc; |
| 4293 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4294 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4295 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4296 | if (ToD) |
| 4297 | return ToD; |
| 4298 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4299 | SourceLocation ToUsingLoc, ToTypenameLoc, ToEllipsisLoc; |
| 4300 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4301 | if (auto Imp = importSeq( |
| 4302 | D->getUsingLoc(), D->getTypenameLoc(), D->getQualifierLoc(), |
| 4303 | D->getEllipsisLoc())) |
| 4304 | std::tie(ToUsingLoc, ToTypenameLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; |
| 4305 | else |
| 4306 | return Imp.takeError(); |
| 4307 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4308 | UnresolvedUsingTypenameDecl *ToUsing; |
| 4309 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4310 | ToUsingLoc, ToTypenameLoc, |
| 4311 | ToQualifierLoc, Loc, Name, ToEllipsisLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4312 | return ToUsing; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4313 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4314 | ToUsing->setAccess(D->getAccess()); |
| 4315 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4316 | LexicalDC->addDeclInternal(ToUsing); |
| 4317 | |
| 4318 | return ToUsing; |
| 4319 | } |
| 4320 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4321 | |
| 4322 | Error ASTNodeImporter::ImportDefinition( |
| 4323 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4324 | if (To->getDefinition()) { |
| 4325 | // Check consistency of superclass. |
| 4326 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 4327 | if (FromSuper) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4328 | if (auto FromSuperOrErr = import(FromSuper)) |
| 4329 | FromSuper = *FromSuperOrErr; |
| 4330 | else |
| 4331 | return FromSuperOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4332 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4333 | |
| 4334 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4335 | if ((bool)FromSuper != (bool)ToSuper || |
| 4336 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4337 | Importer.ToDiag(To->getLocation(), |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4338 | diag::warn_odr_objc_superclass_inconsistent) |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4339 | << To->getDeclName(); |
| 4340 | if (ToSuper) |
| 4341 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 4342 | << To->getSuperClass()->getDeclName(); |
| 4343 | else |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4344 | Importer.ToDiag(To->getLocation(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4345 | diag::note_odr_objc_missing_superclass); |
| 4346 | if (From->getSuperClass()) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4347 | Importer.FromDiag(From->getSuperClassLoc(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4348 | diag::note_odr_objc_superclass) |
| 4349 | << From->getSuperClass()->getDeclName(); |
| 4350 | else |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4351 | Importer.FromDiag(From->getLocation(), |
| 4352 | diag::note_odr_objc_missing_superclass); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4353 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4354 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4355 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4356 | if (Error Err = ImportDeclContext(From)) |
| 4357 | return Err; |
| 4358 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4359 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4360 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4361 | // Start the definition. |
| 4362 | To->startDefinition(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4363 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4364 | // If this class has a superclass, import it. |
| 4365 | if (From->getSuperClass()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4366 | if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo())) |
| 4367 | To->setSuperClass(*SuperTInfoOrErr); |
| 4368 | else |
| 4369 | return SuperTInfoOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4370 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4371 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4372 | // Import protocols |
| 4373 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4374 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4375 | ObjCInterfaceDecl::protocol_loc_iterator FromProtoLoc = |
| 4376 | From->protocol_loc_begin(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4377 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4378 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4379 | FromProtoEnd = From->protocol_end(); |
| 4380 | FromProto != FromProtoEnd; |
| 4381 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4382 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4383 | Protocols.push_back(*ToProtoOrErr); |
| 4384 | else |
| 4385 | return ToProtoOrErr.takeError(); |
| 4386 | |
| 4387 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4388 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4389 | else |
| 4390 | return ToProtoLocOrErr.takeError(); |
| 4391 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4392 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4393 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4394 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4395 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4396 | ProtocolLocs.data(), Importer.getToContext()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4397 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4398 | // Import categories. When the categories themselves are imported, they'll |
| 4399 | // hook themselves into this interface. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4400 | for (auto *Cat : From->known_categories()) { |
| 4401 | auto ToCatOrErr = import(Cat); |
| 4402 | if (!ToCatOrErr) |
| 4403 | return ToCatOrErr.takeError(); |
| 4404 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4405 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4406 | // If we have an @implementation, import it as well. |
| 4407 | if (From->getImplementation()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4408 | if (Expected<ObjCImplementationDecl *> ToImplOrErr = |
| 4409 | import(From->getImplementation())) |
| 4410 | To->setImplementation(*ToImplOrErr); |
| 4411 | else |
| 4412 | return ToImplOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4413 | } |
| 4414 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4415 | if (shouldForceImportDeclContext(Kind)) { |
| 4416 | // Import all of the members of this class. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4417 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4418 | return Err; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4419 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4420 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4421 | } |
| 4422 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4423 | Expected<ObjCTypeParamList *> |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4424 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 4425 | if (!list) |
| 4426 | return nullptr; |
| 4427 | |
| 4428 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4429 | for (auto *fromTypeParam : *list) { |
| 4430 | if (auto toTypeParamOrErr = import(fromTypeParam)) |
| 4431 | toTypeParams.push_back(*toTypeParamOrErr); |
| 4432 | else |
| 4433 | return toTypeParamOrErr.takeError(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4434 | } |
| 4435 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4436 | auto LAngleLocOrErr = import(list->getLAngleLoc()); |
| 4437 | if (!LAngleLocOrErr) |
| 4438 | return LAngleLocOrErr.takeError(); |
| 4439 | |
| 4440 | auto RAngleLocOrErr = import(list->getRAngleLoc()); |
| 4441 | if (!RAngleLocOrErr) |
| 4442 | return RAngleLocOrErr.takeError(); |
| 4443 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4444 | return ObjCTypeParamList::create(Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4445 | *LAngleLocOrErr, |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4446 | toTypeParams, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4447 | *RAngleLocOrErr); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4448 | } |
| 4449 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4450 | ExpectedDecl ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4451 | // If this class has a definition in the translation unit we're coming from, |
| 4452 | // but this particular declaration is not that definition, import the |
| 4453 | // definition and map to that. |
| 4454 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 4455 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4456 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4457 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4458 | else |
| 4459 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4460 | } |
| 4461 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4462 | // Import the major distinguishing characteristics of an @interface. |
| 4463 | DeclContext *DC, *LexicalDC; |
| 4464 | DeclarationName Name; |
| 4465 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4466 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4467 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4468 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4469 | if (ToD) |
| 4470 | return ToD; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4471 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4472 | // Look for an existing interface with the same name. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4473 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4474 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4475 | for (auto *FoundDecl : FoundDecls) { |
| 4476 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4477 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4478 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4479 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4480 | break; |
| 4481 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4482 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4483 | // Create an interface declaration, if one does not already exist. |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4484 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4485 | if (!ToIface) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4486 | ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4487 | if (!AtBeginLocOrErr) |
| 4488 | return AtBeginLocOrErr.takeError(); |
| 4489 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4490 | if (GetImportedOrCreateDecl( |
| 4491 | ToIface, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4492 | *AtBeginLocOrErr, Name.getAsIdentifierInfo(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4493 | /*TypeParamList=*/nullptr, |
| 4494 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) |
| 4495 | return ToIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4496 | ToIface->setLexicalDeclContext(LexicalDC); |
| 4497 | LexicalDC->addDeclInternal(ToIface); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4498 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4499 | Importer.MapImported(D, ToIface); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4500 | // Import the type parameter list after MapImported, to avoid |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4501 | // loops when bringing in their DeclContext. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4502 | if (auto ToPListOrErr = |
| 4503 | ImportObjCTypeParamList(D->getTypeParamListAsWritten())) |
| 4504 | ToIface->setTypeParamList(*ToPListOrErr); |
| 4505 | else |
| 4506 | return ToPListOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4507 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4508 | if (D->isThisDeclarationADefinition()) |
| 4509 | if (Error Err = ImportDefinition(D, ToIface)) |
| 4510 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4511 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4512 | return ToIface; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4513 | } |
| 4514 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4515 | ExpectedDecl |
| 4516 | ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 4517 | ObjCCategoryDecl *Category; |
| 4518 | if (Error Err = importInto(Category, D->getCategoryDecl())) |
| 4519 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4520 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4521 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 4522 | if (!ToImpl) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4523 | DeclContext *DC, *LexicalDC; |
| 4524 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4525 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4526 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4527 | SourceLocation ToLocation, ToAtStartLoc, ToCategoryNameLoc; |
| 4528 | if (auto Imp = importSeq( |
| 4529 | D->getLocation(), D->getAtStartLoc(), D->getCategoryNameLoc())) |
| 4530 | std::tie(ToLocation, ToAtStartLoc, ToCategoryNameLoc) = *Imp; |
| 4531 | else |
| 4532 | return Imp.takeError(); |
| 4533 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4534 | if (GetImportedOrCreateDecl( |
| 4535 | ToImpl, D, Importer.getToContext(), DC, |
| 4536 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4537 | ToLocation, ToAtStartLoc, ToCategoryNameLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4538 | return ToImpl; |
| 4539 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4540 | ToImpl->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4541 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4542 | Category->setImplementation(ToImpl); |
| 4543 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4544 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4545 | Importer.MapImported(D, ToImpl); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4546 | if (Error Err = ImportDeclContext(D)) |
| 4547 | return std::move(Err); |
| 4548 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4549 | return ToImpl; |
| 4550 | } |
| 4551 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4552 | ExpectedDecl |
| 4553 | ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4554 | // Find the corresponding interface. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4555 | ObjCInterfaceDecl *Iface; |
| 4556 | if (Error Err = importInto(Iface, D->getClassInterface())) |
| 4557 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4558 | |
| 4559 | // Import the superclass, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4560 | ObjCInterfaceDecl *Super; |
| 4561 | if (Error Err = importInto(Super, D->getSuperClass())) |
| 4562 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4563 | |
| 4564 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 4565 | if (!Impl) { |
| 4566 | // We haven't imported an implementation yet. Create a new @implementation |
| 4567 | // now. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4568 | DeclContext *DC, *LexicalDC; |
| 4569 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4570 | return std::move(Err); |
| 4571 | |
| 4572 | SourceLocation ToLocation, ToAtStartLoc, ToSuperClassLoc; |
| 4573 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; |
| 4574 | if (auto Imp = importSeq( |
| 4575 | D->getLocation(), D->getAtStartLoc(), D->getSuperClassLoc(), |
| 4576 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) |
| 4577 | std::tie( |
| 4578 | ToLocation, ToAtStartLoc, ToSuperClassLoc, |
| 4579 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; |
| 4580 | else |
| 4581 | return Imp.takeError(); |
| 4582 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4583 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4584 | DC, Iface, Super, |
| 4585 | ToLocation, |
| 4586 | ToAtStartLoc, |
| 4587 | ToSuperClassLoc, |
| 4588 | ToIvarLBraceLoc, |
| 4589 | ToIvarRBraceLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4590 | return Impl; |
| 4591 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4592 | Impl->setLexicalDeclContext(LexicalDC); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4593 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4594 | // Associate the implementation with the class it implements. |
| 4595 | Iface->setImplementation(Impl); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4596 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4597 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4598 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4599 | |
| 4600 | // Verify that the existing @implementation has the same superclass. |
| 4601 | if ((Super && !Impl->getSuperClass()) || |
| 4602 | (!Super && Impl->getSuperClass()) || |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4603 | (Super && Impl->getSuperClass() && |
| 4604 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 4605 | Impl->getSuperClass()))) { |
| 4606 | Importer.ToDiag(Impl->getLocation(), |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4607 | diag::warn_odr_objc_superclass_inconsistent) |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4608 | << Iface->getDeclName(); |
| 4609 | // FIXME: It would be nice to have the location of the superclass |
| 4610 | // below. |
| 4611 | if (Impl->getSuperClass()) |
| 4612 | Importer.ToDiag(Impl->getLocation(), |
| 4613 | diag::note_odr_objc_superclass) |
| 4614 | << Impl->getSuperClass()->getDeclName(); |
| 4615 | else |
| 4616 | Importer.ToDiag(Impl->getLocation(), |
| 4617 | diag::note_odr_objc_missing_superclass); |
| 4618 | if (D->getSuperClass()) |
| 4619 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4620 | diag::note_odr_objc_superclass) |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4621 | << D->getSuperClass()->getDeclName(); |
| 4622 | else |
| 4623 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4624 | diag::note_odr_objc_missing_superclass); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4625 | |
| 4626 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4627 | } |
| 4628 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4629 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4630 | // Import all of the members of this @implementation. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4631 | if (Error Err = ImportDeclContext(D)) |
| 4632 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4633 | |
| 4634 | return Impl; |
| 4635 | } |
| 4636 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4637 | ExpectedDecl ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4638 | // Import the major distinguishing characteristics of an @property. |
| 4639 | DeclContext *DC, *LexicalDC; |
| 4640 | DeclarationName Name; |
| 4641 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4642 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4643 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4644 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4645 | if (ToD) |
| 4646 | return ToD; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4647 | |
| 4648 | // Check whether we have already imported this property. |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4649 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4650 | for (auto *FoundDecl : FoundDecls) { |
| 4651 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4652 | // Check property types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4653 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4654 | FoundProp->getType())) { |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4655 | Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent) |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4656 | << Name << D->getType() << FoundProp->getType(); |
| 4657 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 4658 | << FoundProp->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4659 | |
| 4660 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4661 | } |
| 4662 | |
| 4663 | // FIXME: Check property attributes, getters, setters, etc.? |
| 4664 | |
| 4665 | // Consider these properties to be equivalent. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4666 | Importer.MapImported(D, FoundProp); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4667 | return FoundProp; |
| 4668 | } |
| 4669 | } |
| 4670 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4671 | QualType ToType; |
| 4672 | TypeSourceInfo *ToTypeSourceInfo; |
| 4673 | SourceLocation ToAtLoc, ToLParenLoc; |
| 4674 | if (auto Imp = importSeq( |
| 4675 | D->getType(), D->getTypeSourceInfo(), D->getAtLoc(), D->getLParenLoc())) |
| 4676 | std::tie(ToType, ToTypeSourceInfo, ToAtLoc, ToLParenLoc) = *Imp; |
| 4677 | else |
| 4678 | return Imp.takeError(); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4679 | |
| 4680 | // Create the new property. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4681 | ObjCPropertyDecl *ToProperty; |
| 4682 | if (GetImportedOrCreateDecl( |
| 4683 | ToProperty, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4684 | Name.getAsIdentifierInfo(), ToAtLoc, |
| 4685 | ToLParenLoc, ToType, |
| 4686 | ToTypeSourceInfo, D->getPropertyImplementation())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4687 | return ToProperty; |
| 4688 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4689 | Selector ToGetterName, ToSetterName; |
| 4690 | SourceLocation ToGetterNameLoc, ToSetterNameLoc; |
| 4691 | ObjCMethodDecl *ToGetterMethodDecl, *ToSetterMethodDecl; |
| 4692 | ObjCIvarDecl *ToPropertyIvarDecl; |
| 4693 | if (auto Imp = importSeq( |
| 4694 | D->getGetterName(), D->getSetterName(), |
| 4695 | D->getGetterNameLoc(), D->getSetterNameLoc(), |
| 4696 | D->getGetterMethodDecl(), D->getSetterMethodDecl(), |
| 4697 | D->getPropertyIvarDecl())) |
| 4698 | std::tie( |
| 4699 | ToGetterName, ToSetterName, |
| 4700 | ToGetterNameLoc, ToSetterNameLoc, |
| 4701 | ToGetterMethodDecl, ToSetterMethodDecl, |
| 4702 | ToPropertyIvarDecl) = *Imp; |
| 4703 | else |
| 4704 | return Imp.takeError(); |
| 4705 | |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4706 | ToProperty->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4707 | LexicalDC->addDeclInternal(ToProperty); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4708 | |
| 4709 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 4710 | ToProperty->setPropertyAttributesAsWritten( |
| 4711 | D->getPropertyAttributesAsWritten()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4712 | ToProperty->setGetterName(ToGetterName, ToGetterNameLoc); |
| 4713 | ToProperty->setSetterName(ToSetterName, ToSetterNameLoc); |
| 4714 | ToProperty->setGetterMethodDecl(ToGetterMethodDecl); |
| 4715 | ToProperty->setSetterMethodDecl(ToSetterMethodDecl); |
| 4716 | ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4717 | return ToProperty; |
| 4718 | } |
| 4719 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4720 | ExpectedDecl |
| 4721 | ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 4722 | ObjCPropertyDecl *Property; |
| 4723 | if (Error Err = importInto(Property, D->getPropertyDecl())) |
| 4724 | return std::move(Err); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4725 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4726 | DeclContext *DC, *LexicalDC; |
| 4727 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4728 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4729 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4730 | auto *InImpl = cast<ObjCImplDecl>(LexicalDC); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4731 | |
| 4732 | // Import the ivar (for an @synthesize). |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4733 | ObjCIvarDecl *Ivar = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4734 | if (Error Err = importInto(Ivar, D->getPropertyIvarDecl())) |
| 4735 | return std::move(Err); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4736 | |
| 4737 | ObjCPropertyImplDecl *ToImpl |
Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 4738 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 4739 | Property->getQueryKind()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4740 | if (!ToImpl) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4741 | SourceLocation ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc; |
| 4742 | if (auto Imp = importSeq( |
| 4743 | D->getBeginLoc(), D->getLocation(), D->getPropertyIvarDeclLoc())) |
| 4744 | std::tie(ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc) = *Imp; |
| 4745 | else |
| 4746 | return Imp.takeError(); |
| 4747 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4748 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4749 | ToBeginLoc, |
| 4750 | ToLocation, Property, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4751 | D->getPropertyImplementation(), Ivar, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4752 | ToPropertyIvarDeclLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4753 | return ToImpl; |
| 4754 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4755 | ToImpl->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4756 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4757 | } else { |
| 4758 | // Check that we have the same kind of property implementation (@synthesize |
| 4759 | // vs. @dynamic). |
| 4760 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4761 | Importer.ToDiag(ToImpl->getLocation(), |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4762 | diag::warn_odr_objc_property_impl_kind_inconsistent) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4763 | << Property->getDeclName() |
| 4764 | << (ToImpl->getPropertyImplementation() |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4765 | == ObjCPropertyImplDecl::Dynamic); |
| 4766 | Importer.FromDiag(D->getLocation(), |
| 4767 | diag::note_odr_objc_property_impl_kind) |
| 4768 | << D->getPropertyDecl()->getDeclName() |
| 4769 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4770 | |
| 4771 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4772 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4773 | |
| 4774 | // For @synthesize, check that we have the same |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4775 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 4776 | Ivar != ToImpl->getPropertyIvarDecl()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4777 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4778 | diag::warn_odr_objc_synthesize_ivar_inconsistent) |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4779 | << Property->getDeclName() |
| 4780 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 4781 | << Ivar->getDeclName(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4782 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4783 | diag::note_odr_objc_synthesize_ivar_here) |
| 4784 | << D->getPropertyIvarDecl()->getDeclName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4785 | |
| 4786 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4787 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4788 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4789 | // Merge the existing implementation with the new implementation. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4790 | Importer.MapImported(D, ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4791 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4792 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4793 | return ToImpl; |
| 4794 | } |
| 4795 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4796 | ExpectedDecl |
| 4797 | ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4798 | // For template arguments, we adopt the translation unit as our declaration |
| 4799 | // context. This context will be fixed when the actual template declaration |
| 4800 | // is created. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4801 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4802 | // FIXME: Import default argument. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4803 | |
| 4804 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 4805 | if (!BeginLocOrErr) |
| 4806 | return BeginLocOrErr.takeError(); |
| 4807 | |
| 4808 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 4809 | if (!LocationOrErr) |
| 4810 | return LocationOrErr.takeError(); |
| 4811 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4812 | TemplateTypeParmDecl *ToD = nullptr; |
| 4813 | (void)GetImportedOrCreateDecl( |
| 4814 | ToD, D, Importer.getToContext(), |
| 4815 | Importer.getToContext().getTranslationUnitDecl(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4816 | *BeginLocOrErr, *LocationOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4817 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), |
| 4818 | D->wasDeclaredWithTypename(), D->isParameterPack()); |
| 4819 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4820 | } |
| 4821 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4822 | ExpectedDecl |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4823 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4824 | DeclarationName ToDeclName; |
| 4825 | SourceLocation ToLocation, ToInnerLocStart; |
| 4826 | QualType ToType; |
| 4827 | TypeSourceInfo *ToTypeSourceInfo; |
| 4828 | if (auto Imp = importSeq( |
| 4829 | D->getDeclName(), D->getLocation(), D->getType(), D->getTypeSourceInfo(), |
| 4830 | D->getInnerLocStart())) |
| 4831 | std::tie( |
| 4832 | ToDeclName, ToLocation, ToType, ToTypeSourceInfo, |
| 4833 | ToInnerLocStart) = *Imp; |
| 4834 | else |
| 4835 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4836 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4837 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4838 | |
| 4839 | NonTypeTemplateParmDecl *ToD = nullptr; |
| 4840 | (void)GetImportedOrCreateDecl( |
| 4841 | ToD, D, Importer.getToContext(), |
| 4842 | Importer.getToContext().getTranslationUnitDecl(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4843 | ToInnerLocStart, ToLocation, D->getDepth(), |
| 4844 | D->getPosition(), ToDeclName.getAsIdentifierInfo(), ToType, |
| 4845 | D->isParameterPack(), ToTypeSourceInfo); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4846 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4847 | } |
| 4848 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4849 | ExpectedDecl |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4850 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 4851 | // Import the name of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4852 | auto NameOrErr = import(D->getDeclName()); |
| 4853 | if (!NameOrErr) |
| 4854 | return NameOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4855 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4856 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4857 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 4858 | if (!LocationOrErr) |
| 4859 | return LocationOrErr.takeError(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4860 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4861 | // Import template parameters. |
Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 4862 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4863 | if (!TemplateParamsOrErr) |
| 4864 | return TemplateParamsOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4865 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4866 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4867 | |
| 4868 | TemplateTemplateParmDecl *ToD = nullptr; |
| 4869 | (void)GetImportedOrCreateDecl( |
| 4870 | ToD, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4871 | Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr, |
| 4872 | D->getDepth(), D->getPosition(), D->isParameterPack(), |
| 4873 | (*NameOrErr).getAsIdentifierInfo(), |
| 4874 | *TemplateParamsOrErr); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4875 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4876 | } |
| 4877 | |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 4878 | // Returns the definition for a (forward) declaration of a TemplateDecl, if |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4879 | // it has any definition in the redecl chain. |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 4880 | template <typename T> static auto getTemplateDefinition(T *D) -> T * { |
| 4881 | assert(D->getTemplatedDecl() && "Should be called on templates only"); |
| 4882 | auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4883 | if (!ToTemplatedDef) |
| 4884 | return nullptr; |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 4885 | auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate(); |
| 4886 | return cast_or_null<T>(TemplateWithDef); |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4887 | } |
| 4888 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4889 | ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4890 | bool IsFriend = D->getFriendObjectKind() != Decl::FOK_None; |
| 4891 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4892 | // Import the major distinguishing characteristics of this class template. |
| 4893 | DeclContext *DC, *LexicalDC; |
| 4894 | DeclarationName Name; |
| 4895 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4896 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4897 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4898 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4899 | if (ToD) |
| 4900 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4901 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4902 | ClassTemplateDecl *FoundByLookup = nullptr; |
| 4903 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4904 | // We may already have a template of the same name; try to find and match it. |
| 4905 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4906 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4907 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4908 | for (auto *FoundDecl : FoundDecls) { |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4909 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary | |
| 4910 | Decl::IDNS_TagFriend)) |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4911 | continue; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4912 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4913 | Decl *Found = FoundDecl; |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4914 | auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found); |
| 4915 | if (FoundTemplate) { |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4916 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4917 | if (IsStructuralMatch(D, FoundTemplate)) { |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 4918 | ClassTemplateDecl *TemplateWithDef = |
| 4919 | getTemplateDefinition(FoundTemplate); |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4920 | if (D->isThisDeclarationADefinition() && TemplateWithDef) { |
| 4921 | return Importer.MapImported(D, TemplateWithDef); |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4922 | } |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4923 | FoundByLookup = FoundTemplate; |
| 4924 | break; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4925 | } |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4926 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4927 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4928 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4929 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4930 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4931 | if (!ConflictingDecls.empty()) { |
| 4932 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4933 | ConflictingDecls.data(), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4934 | ConflictingDecls.size()); |
| 4935 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4936 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4937 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4938 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4939 | } |
| 4940 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4941 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); |
| 4942 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4943 | // Create the declaration that is being templated. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4944 | CXXRecordDecl *ToTemplated; |
| 4945 | if (Error Err = importInto(ToTemplated, FromTemplated)) |
| 4946 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4947 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4948 | // Create the class template declaration itself. |
Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 4949 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4950 | if (!TemplateParamsOrErr) |
| 4951 | return TemplateParamsOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4952 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4953 | ClassTemplateDecl *D2; |
| 4954 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4955 | *TemplateParamsOrErr, ToTemplated)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4956 | return D2; |
| 4957 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4958 | ToTemplated->setDescribedClassTemplate(D2); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4959 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4960 | D2->setAccess(D->getAccess()); |
| 4961 | D2->setLexicalDeclContext(LexicalDC); |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4962 | |
| 4963 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 4964 | DC->addDeclInternal(D2); |
| 4965 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4966 | LexicalDC->addDeclInternal(D2); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4967 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4968 | if (FoundByLookup) { |
| 4969 | auto *Recent = |
| 4970 | const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl()); |
| 4971 | |
| 4972 | // It is possible that during the import of the class template definition |
| 4973 | // we start the import of a fwd friend decl of the very same class template |
| 4974 | // and we add the fwd friend decl to the lookup table. But the ToTemplated |
| 4975 | // had been created earlier and by that time the lookup could not find |
| 4976 | // anything existing, so it has no previous decl. Later, (still during the |
| 4977 | // import of the fwd friend decl) we start to import the definition again |
| 4978 | // and this time the lookup finds the previous fwd friend class template. |
| 4979 | // In this case we must set up the previous decl for the templated decl. |
| 4980 | if (!ToTemplated->getPreviousDecl()) { |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 4981 | assert(FoundByLookup->getTemplatedDecl() && |
| 4982 | "Found decl must have its templated decl set"); |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4983 | CXXRecordDecl *PrevTemplated = |
| 4984 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); |
| 4985 | if (ToTemplated != PrevTemplated) |
| 4986 | ToTemplated->setPreviousDecl(PrevTemplated); |
| 4987 | } |
| 4988 | |
| 4989 | D2->setPreviousDecl(Recent); |
| 4990 | } |
| 4991 | |
| 4992 | if (LexicalDC != DC && IsFriend) |
| 4993 | DC->makeDeclVisibleInContext(D2); |
| 4994 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4995 | if (FromTemplated->isCompleteDefinition() && |
| 4996 | !ToTemplated->isCompleteDefinition()) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4997 | // FIXME: Import definition! |
| 4998 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4999 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5000 | return D2; |
| 5001 | } |
| 5002 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5003 | ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5004 | ClassTemplateSpecializationDecl *D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5005 | ClassTemplateDecl *ClassTemplate; |
| 5006 | if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate())) |
| 5007 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5008 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5009 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5010 | DeclContext *DC, *LexicalDC; |
| 5011 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5012 | return std::move(Err); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5013 | |
| 5014 | // Import template arguments. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5015 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5016 | if (Error Err = ImportTemplateArguments( |
| 5017 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5018 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5019 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5020 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5021 | void *InsertPos = nullptr; |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5022 | ClassTemplateSpecializationDecl *PrevDecl = nullptr; |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5023 | ClassTemplatePartialSpecializationDecl *PartialSpec = |
| 5024 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D); |
| 5025 | if (PartialSpec) |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5026 | PrevDecl = |
| 5027 | ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5028 | else |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5029 | PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5030 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5031 | if (PrevDecl) { |
| 5032 | if (IsStructuralMatch(D, PrevDecl)) { |
| 5033 | if (D->isThisDeclarationADefinition() && PrevDecl->getDefinition()) { |
| 5034 | Importer.MapImported(D, PrevDecl->getDefinition()); |
| 5035 | // Import those default field initializers which have been |
| 5036 | // instantiated in the "From" context, but not in the "To" context. |
| 5037 | for (auto *FromField : D->fields()) |
| 5038 | Importer.Import(FromField); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5039 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5040 | // Import those methods which have been instantiated in the |
| 5041 | // "From" context, but not in the "To" context. |
| 5042 | for (CXXMethodDecl *FromM : D->methods()) |
| 5043 | Importer.Import(FromM); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5044 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5045 | // TODO Import instantiated default arguments. |
| 5046 | // TODO Import instantiated exception specifications. |
| 5047 | // |
| 5048 | // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint |
| 5049 | // what else could be fused during an AST merge. |
| 5050 | return PrevDecl; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5051 | } |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5052 | } else { // ODR violation. |
| 5053 | // FIXME HandleNameConflict |
| 5054 | return nullptr; |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5055 | } |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5056 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5057 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5058 | // Import the location of this declaration. |
| 5059 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5060 | if (!BeginLocOrErr) |
| 5061 | return BeginLocOrErr.takeError(); |
| 5062 | ExpectedSLoc IdLocOrErr = import(D->getLocation()); |
| 5063 | if (!IdLocOrErr) |
| 5064 | return IdLocOrErr.takeError(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5065 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5066 | // Create the specialization. |
| 5067 | ClassTemplateSpecializationDecl *D2 = nullptr; |
| 5068 | if (PartialSpec) { |
| 5069 | // Import TemplateArgumentListInfo. |
| 5070 | TemplateArgumentListInfo ToTAInfo; |
| 5071 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
| 5072 | if (Error Err = ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) |
| 5073 | return std::move(Err); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5074 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5075 | QualType CanonInjType; |
| 5076 | if (Error Err = importInto( |
| 5077 | CanonInjType, PartialSpec->getInjectedSpecializationType())) |
| 5078 | return std::move(Err); |
| 5079 | CanonInjType = CanonInjType.getCanonicalType(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5080 | |
Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5081 | auto ToTPListOrErr = import(PartialSpec->getTemplateParameters()); |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5082 | if (!ToTPListOrErr) |
| 5083 | return ToTPListOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5084 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5085 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( |
| 5086 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| 5087 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, ClassTemplate, |
| 5088 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
| 5089 | ToTAInfo, CanonInjType, |
| 5090 | cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl))) |
| 5091 | return D2; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5092 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5093 | // Update InsertPos, because preceding import calls may have invalidated |
| 5094 | // it by adding new specializations. |
| 5095 | if (!ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos)) |
| 5096 | // Add this partial specialization to the class template. |
| 5097 | ClassTemplate->AddPartialSpecialization( |
| 5098 | cast<ClassTemplatePartialSpecializationDecl>(D2), InsertPos); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5099 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5100 | } else { // Not a partial specialization. |
| 5101 | if (GetImportedOrCreateDecl( |
| 5102 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| 5103 | *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs, |
| 5104 | PrevDecl)) |
| 5105 | return D2; |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5106 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5107 | // Update InsertPos, because preceding import calls may have invalidated |
| 5108 | // it by adding new specializations. |
| 5109 | if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos)) |
| 5110 | // Add this specialization to the class template. |
| 5111 | ClassTemplate->AddSpecialization(D2, InsertPos); |
| 5112 | } |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5113 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5114 | D2->setSpecializationKind(D->getSpecializationKind()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5115 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5116 | // Set the context of this specialization/instantiation. |
| 5117 | D2->setLexicalDeclContext(LexicalDC); |
| 5118 | |
| 5119 | // Add to the DC only if it was an explicit specialization/instantiation. |
| 5120 | if (D2->isExplicitInstantiationOrSpecialization()) { |
| 5121 | LexicalDC->addDeclInternal(D2); |
| 5122 | } |
| 5123 | |
| 5124 | // Import the qualifier, if any. |
| 5125 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5126 | D2->setQualifierInfo(*LocOrErr); |
| 5127 | else |
| 5128 | return LocOrErr.takeError(); |
| 5129 | |
| 5130 | if (auto *TSI = D->getTypeAsWritten()) { |
| 5131 | if (auto TInfoOrErr = import(TSI)) |
| 5132 | D2->setTypeAsWritten(*TInfoOrErr); |
| 5133 | else |
| 5134 | return TInfoOrErr.takeError(); |
| 5135 | |
| 5136 | if (auto LocOrErr = import(D->getTemplateKeywordLoc())) |
| 5137 | D2->setTemplateKeywordLoc(*LocOrErr); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5138 | else |
| 5139 | return LocOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5140 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5141 | if (auto LocOrErr = import(D->getExternLoc())) |
| 5142 | D2->setExternLoc(*LocOrErr); |
| 5143 | else |
| 5144 | return LocOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5145 | } |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5146 | |
| 5147 | if (D->getPointOfInstantiation().isValid()) { |
| 5148 | if (auto POIOrErr = import(D->getPointOfInstantiation())) |
| 5149 | D2->setPointOfInstantiation(*POIOrErr); |
| 5150 | else |
| 5151 | return POIOrErr.takeError(); |
| 5152 | } |
| 5153 | |
| 5154 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 5155 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5156 | if (D->isCompleteDefinition()) |
| 5157 | if (Error Err = ImportDefinition(D, D2)) |
| 5158 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5159 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5160 | return D2; |
| 5161 | } |
| 5162 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5163 | ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5164 | // If this variable has a definition in the translation unit we're coming |
| 5165 | // from, |
| 5166 | // but this particular declaration is not that definition, import the |
| 5167 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5168 | auto *Definition = |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5169 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); |
| 5170 | if (Definition && Definition != D->getTemplatedDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5171 | if (ExpectedDecl ImportedDefOrErr = import( |
| 5172 | Definition->getDescribedVarTemplate())) |
| 5173 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5174 | else |
| 5175 | return ImportedDefOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5176 | } |
| 5177 | |
| 5178 | // Import the major distinguishing characteristics of this variable template. |
| 5179 | DeclContext *DC, *LexicalDC; |
| 5180 | DeclarationName Name; |
| 5181 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5182 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5183 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5184 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5185 | if (ToD) |
| 5186 | return ToD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5187 | |
| 5188 | // We may already have a template of the same name; try to find and match it. |
| 5189 | assert(!DC->isFunctionOrMethod() && |
| 5190 | "Variable templates cannot be declared at function scope"); |
| 5191 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5192 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5193 | for (auto *FoundDecl : FoundDecls) { |
| 5194 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5195 | continue; |
| 5196 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5197 | Decl *Found = FoundDecl; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5198 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5199 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 5200 | // The variable templates structurally match; call it the same template. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5201 | Importer.MapImported(D->getTemplatedDecl(), |
| 5202 | FoundTemplate->getTemplatedDecl()); |
| 5203 | return Importer.MapImported(D, FoundTemplate); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5204 | } |
| 5205 | } |
| 5206 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5207 | ConflictingDecls.push_back(FoundDecl); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5208 | } |
| 5209 | |
| 5210 | if (!ConflictingDecls.empty()) { |
| 5211 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 5212 | ConflictingDecls.data(), |
| 5213 | ConflictingDecls.size()); |
| 5214 | } |
| 5215 | |
| 5216 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5217 | // FIXME: Is it possible to get other error than name conflict? |
| 5218 | // (Put this `if` into the previous `if`?) |
| 5219 | return make_error<ImportError>(ImportError::NameConflict); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5220 | |
| 5221 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 5222 | |
| 5223 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5224 | // FIXME: Value not used? |
| 5225 | ExpectedType TypeOrErr = import(DTemplated->getType()); |
| 5226 | if (!TypeOrErr) |
| 5227 | return TypeOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5228 | |
| 5229 | // Create the declaration that is being templated. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5230 | VarDecl *ToTemplated; |
| 5231 | if (Error Err = importInto(ToTemplated, DTemplated)) |
| 5232 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5233 | |
| 5234 | // Create the variable template declaration itself. |
Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5235 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5236 | if (!TemplateParamsOrErr) |
| 5237 | return TemplateParamsOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5238 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5239 | VarTemplateDecl *ToVarTD; |
| 5240 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5241 | Name, *TemplateParamsOrErr, ToTemplated)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5242 | return ToVarTD; |
| 5243 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5244 | ToTemplated->setDescribedVarTemplate(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5245 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5246 | ToVarTD->setAccess(D->getAccess()); |
| 5247 | ToVarTD->setLexicalDeclContext(LexicalDC); |
| 5248 | LexicalDC->addDeclInternal(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5249 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5250 | if (DTemplated->isThisDeclarationADefinition() && |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5251 | !ToTemplated->isThisDeclarationADefinition()) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5252 | // FIXME: Import definition! |
| 5253 | } |
| 5254 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5255 | return ToVarTD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5256 | } |
| 5257 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5258 | ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5259 | VarTemplateSpecializationDecl *D) { |
| 5260 | // If this record has a definition in the translation unit we're coming from, |
| 5261 | // but this particular declaration is not that definition, import the |
| 5262 | // definition and map to that. |
| 5263 | VarDecl *Definition = D->getDefinition(); |
| 5264 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5265 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 5266 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5267 | else |
| 5268 | return ImportedDefOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5269 | } |
| 5270 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5271 | VarTemplateDecl *VarTemplate; |
| 5272 | if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate())) |
| 5273 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5274 | |
| 5275 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5276 | DeclContext *DC, *LexicalDC; |
| 5277 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5278 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5279 | |
| 5280 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5281 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5282 | if (!BeginLocOrErr) |
| 5283 | return BeginLocOrErr.takeError(); |
| 5284 | |
| 5285 | auto IdLocOrErr = import(D->getLocation()); |
| 5286 | if (!IdLocOrErr) |
| 5287 | return IdLocOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5288 | |
| 5289 | // Import template arguments. |
| 5290 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5291 | if (Error Err = ImportTemplateArguments( |
| 5292 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5293 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5294 | |
| 5295 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5296 | void *InsertPos = nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5297 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 5298 | TemplateArgs, InsertPos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5299 | if (D2) { |
| 5300 | // We already have a variable template specialization with these template |
| 5301 | // arguments. |
| 5302 | |
| 5303 | // FIXME: Check for specialization vs. instantiation errors. |
| 5304 | |
| 5305 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 5306 | if (!D->isThisDeclarationADefinition() || |
| 5307 | IsStructuralMatch(D, FoundDef)) { |
| 5308 | // The record types structurally match, or the "from" translation |
| 5309 | // unit only had a forward declaration anyway; call it the same |
| 5310 | // variable. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5311 | return Importer.MapImported(D, FoundDef); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5312 | } |
| 5313 | } |
| 5314 | } else { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5315 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5316 | QualType T; |
| 5317 | if (Error Err = importInto(T, D->getType())) |
| 5318 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5319 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5320 | auto TInfoOrErr = import(D->getTypeSourceInfo()); |
| 5321 | if (!TInfoOrErr) |
| 5322 | return TInfoOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5323 | |
| 5324 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5325 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5326 | D->getTemplateArgsInfo(), ToTAInfo)) |
| 5327 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5328 | |
| 5329 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5330 | // Create a new specialization. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5331 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { |
| 5332 | // Import TemplateArgumentListInfo |
| 5333 | TemplateArgumentListInfo ArgInfos; |
| 5334 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); |
| 5335 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5336 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5337 | *FromTAArgsAsWritten, ArgInfos)) |
| 5338 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5339 | |
Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5340 | auto ToTPListOrErr = import(FromPartial->getTemplateParameters()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5341 | if (!ToTPListOrErr) |
| 5342 | return ToTPListOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5343 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5344 | PartVarSpecDecl *ToPartial; |
| 5345 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5346 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, |
| 5347 | VarTemplate, T, *TInfoOrErr, |
| 5348 | D->getStorageClass(), TemplateArgs, ArgInfos)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5349 | return ToPartial; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5350 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5351 | if (Expected<PartVarSpecDecl *> ToInstOrErr = import( |
| 5352 | FromPartial->getInstantiatedFromMember())) |
| 5353 | ToPartial->setInstantiatedFromMember(*ToInstOrErr); |
| 5354 | else |
| 5355 | return ToInstOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5356 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5357 | if (FromPartial->isMemberSpecialization()) |
| 5358 | ToPartial->setMemberSpecialization(); |
| 5359 | |
| 5360 | D2 = ToPartial; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5361 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5362 | } else { // Full specialization |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5363 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, |
| 5364 | *BeginLocOrErr, *IdLocOrErr, VarTemplate, |
| 5365 | T, *TInfoOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5366 | D->getStorageClass(), TemplateArgs)) |
| 5367 | return D2; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5368 | } |
| 5369 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5370 | if (D->getPointOfInstantiation().isValid()) { |
| 5371 | if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation())) |
| 5372 | D2->setPointOfInstantiation(*POIOrErr); |
| 5373 | else |
| 5374 | return POIOrErr.takeError(); |
| 5375 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5376 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5377 | D2->setSpecializationKind(D->getSpecializationKind()); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5378 | D2->setTemplateArgsInfo(ToTAInfo); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5379 | |
| 5380 | // Add this specialization to the class template. |
| 5381 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 5382 | |
| 5383 | // Import the qualifier, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5384 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5385 | D2->setQualifierInfo(*LocOrErr); |
| 5386 | else |
| 5387 | return LocOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5388 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5389 | if (D->isConstexpr()) |
| 5390 | D2->setConstexpr(true); |
| 5391 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5392 | // Add the specialization to this context. |
| 5393 | D2->setLexicalDeclContext(LexicalDC); |
| 5394 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5395 | |
| 5396 | D2->setAccess(D->getAccess()); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5397 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5398 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5399 | if (Error Err = ImportInitializer(D, D2)) |
| 5400 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5401 | |
| 5402 | return D2; |
| 5403 | } |
| 5404 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5405 | ExpectedDecl |
| 5406 | ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5407 | DeclContext *DC, *LexicalDC; |
| 5408 | DeclarationName Name; |
| 5409 | SourceLocation Loc; |
| 5410 | NamedDecl *ToD; |
| 5411 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5412 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5413 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5414 | |
| 5415 | if (ToD) |
| 5416 | return ToD; |
| 5417 | |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5418 | const FunctionTemplateDecl *FoundByLookup = nullptr; |
| 5419 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5420 | // Try to find a function in our own ("to") context with the same name, same |
| 5421 | // type, and in the same context as the function we're importing. |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5422 | // FIXME Split this into a separate function. |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5423 | if (!LexicalDC->isFunctionOrMethod()) { |
Gabor Marton | e331e63 | 2019-02-18 13:09:27 +0000 | [diff] [blame] | 5424 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5425 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5426 | for (auto *FoundDecl : FoundDecls) { |
| 5427 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5428 | continue; |
| 5429 | |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5430 | if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) { |
| 5431 | if (FoundTemplate->hasExternalFormalLinkage() && |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5432 | D->hasExternalFormalLinkage()) { |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5433 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 5434 | FunctionTemplateDecl *TemplateWithDef = |
| 5435 | getTemplateDefinition(FoundTemplate); |
| 5436 | if (D->isThisDeclarationADefinition() && TemplateWithDef) { |
| 5437 | return Importer.MapImported(D, TemplateWithDef); |
| 5438 | } |
| 5439 | FoundByLookup = FoundTemplate; |
| 5440 | break; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5441 | } |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5442 | // TODO: handle conflicting names |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5443 | } |
| 5444 | } |
| 5445 | } |
| 5446 | } |
| 5447 | |
Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5448 | auto ParamsOrErr = import(D->getTemplateParameters()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5449 | if (!ParamsOrErr) |
| 5450 | return ParamsOrErr.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5451 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5452 | FunctionDecl *TemplatedFD; |
| 5453 | if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl())) |
| 5454 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5455 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5456 | FunctionTemplateDecl *ToFunc; |
| 5457 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5458 | *ParamsOrErr, TemplatedFD)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5459 | return ToFunc; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5460 | |
| 5461 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5462 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5463 | ToFunc->setAccess(D->getAccess()); |
| 5464 | ToFunc->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5465 | LexicalDC->addDeclInternal(ToFunc); |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5466 | |
| 5467 | if (FoundByLookup) { |
| 5468 | auto *Recent = |
| 5469 | const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl()); |
| 5470 | if (!TemplatedFD->getPreviousDecl()) { |
| 5471 | assert(FoundByLookup->getTemplatedDecl() && |
| 5472 | "Found decl must have its templated decl set"); |
| 5473 | auto *PrevTemplated = |
| 5474 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); |
| 5475 | if (TemplatedFD != PrevTemplated) |
| 5476 | TemplatedFD->setPreviousDecl(PrevTemplated); |
| 5477 | } |
| 5478 | ToFunc->setPreviousDecl(Recent); |
| 5479 | } |
| 5480 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5481 | return ToFunc; |
| 5482 | } |
| 5483 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5484 | //---------------------------------------------------------------------------- |
| 5485 | // Import Statements |
| 5486 | //---------------------------------------------------------------------------- |
| 5487 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5488 | ExpectedStmt ASTNodeImporter::VisitStmt(Stmt *S) { |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5489 | Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node) |
| 5490 | << S->getStmtClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5491 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5492 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5493 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5494 | |
| 5495 | ExpectedStmt ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5496 | SmallVector<IdentifierInfo *, 4> Names; |
| 5497 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 5498 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5499 | // ToII is nullptr when no symbolic name is given for output operand |
| 5500 | // see ParseStmtAsm::ParseAsmOperandsOpt |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5501 | Names.push_back(ToII); |
| 5502 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5503 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5504 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 5505 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5506 | // ToII is nullptr when no symbolic name is given for input operand |
| 5507 | // see ParseStmtAsm::ParseAsmOperandsOpt |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5508 | Names.push_back(ToII); |
| 5509 | } |
| 5510 | |
| 5511 | SmallVector<StringLiteral *, 4> Clobbers; |
| 5512 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5513 | if (auto ClobberOrErr = import(S->getClobberStringLiteral(I))) |
| 5514 | Clobbers.push_back(*ClobberOrErr); |
| 5515 | else |
| 5516 | return ClobberOrErr.takeError(); |
| 5517 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5518 | } |
| 5519 | |
| 5520 | SmallVector<StringLiteral *, 4> Constraints; |
| 5521 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5522 | if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I))) |
| 5523 | Constraints.push_back(*OutputOrErr); |
| 5524 | else |
| 5525 | return OutputOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5526 | } |
| 5527 | |
| 5528 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5529 | if (auto InputOrErr = import(S->getInputConstraintLiteral(I))) |
| 5530 | Constraints.push_back(*InputOrErr); |
| 5531 | else |
| 5532 | return InputOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5533 | } |
| 5534 | |
| 5535 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5536 | if (Error Err = ImportContainerChecked(S->outputs(), Exprs)) |
| 5537 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5538 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5539 | if (Error Err = ImportArrayChecked( |
| 5540 | S->inputs(), Exprs.begin() + S->getNumOutputs())) |
| 5541 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5542 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5543 | ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc()); |
| 5544 | if (!AsmLocOrErr) |
| 5545 | return AsmLocOrErr.takeError(); |
| 5546 | auto AsmStrOrErr = import(S->getAsmString()); |
| 5547 | if (!AsmStrOrErr) |
| 5548 | return AsmStrOrErr.takeError(); |
| 5549 | ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc()); |
| 5550 | if (!RParenLocOrErr) |
| 5551 | return RParenLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5552 | |
| 5553 | return new (Importer.getToContext()) GCCAsmStmt( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5554 | Importer.getToContext(), |
| 5555 | *AsmLocOrErr, |
| 5556 | S->isSimple(), |
| 5557 | S->isVolatile(), |
| 5558 | S->getNumOutputs(), |
| 5559 | S->getNumInputs(), |
| 5560 | Names.data(), |
| 5561 | Constraints.data(), |
| 5562 | Exprs.data(), |
| 5563 | *AsmStrOrErr, |
| 5564 | S->getNumClobbers(), |
| 5565 | Clobbers.data(), |
| 5566 | *RParenLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5567 | } |
| 5568 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5569 | ExpectedStmt ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| 5570 | auto Imp = importSeq(S->getDeclGroup(), S->getBeginLoc(), S->getEndLoc()); |
| 5571 | if (!Imp) |
| 5572 | return Imp.takeError(); |
| 5573 | |
| 5574 | DeclGroupRef ToDG; |
| 5575 | SourceLocation ToBeginLoc, ToEndLoc; |
| 5576 | std::tie(ToDG, ToBeginLoc, ToEndLoc) = *Imp; |
| 5577 | |
| 5578 | return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5579 | } |
| 5580 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5581 | ExpectedStmt ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 5582 | ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc()); |
| 5583 | if (!ToSemiLocOrErr) |
| 5584 | return ToSemiLocOrErr.takeError(); |
| 5585 | return new (Importer.getToContext()) NullStmt( |
| 5586 | *ToSemiLocOrErr, S->hasLeadingEmptyMacro()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5587 | } |
| 5588 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5589 | ExpectedStmt ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5590 | SmallVector<Stmt *, 8> ToStmts(S->size()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5591 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5592 | if (Error Err = ImportContainerChecked(S->body(), ToStmts)) |
| 5593 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5594 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5595 | ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc()); |
| 5596 | if (!ToLBracLocOrErr) |
| 5597 | return ToLBracLocOrErr.takeError(); |
| 5598 | |
| 5599 | ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc()); |
| 5600 | if (!ToRBracLocOrErr) |
| 5601 | return ToRBracLocOrErr.takeError(); |
| 5602 | |
| 5603 | return CompoundStmt::Create( |
| 5604 | Importer.getToContext(), ToStmts, |
| 5605 | *ToLBracLocOrErr, *ToRBracLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5606 | } |
| 5607 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5608 | ExpectedStmt ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| 5609 | auto Imp = importSeq( |
| 5610 | S->getLHS(), S->getRHS(), S->getSubStmt(), S->getCaseLoc(), |
| 5611 | S->getEllipsisLoc(), S->getColonLoc()); |
| 5612 | if (!Imp) |
| 5613 | return Imp.takeError(); |
| 5614 | |
| 5615 | Expr *ToLHS, *ToRHS; |
| 5616 | Stmt *ToSubStmt; |
| 5617 | SourceLocation ToCaseLoc, ToEllipsisLoc, ToColonLoc; |
| 5618 | std::tie(ToLHS, ToRHS, ToSubStmt, ToCaseLoc, ToEllipsisLoc, ToColonLoc) = |
| 5619 | *Imp; |
| 5620 | |
Bruno Ricci | 5b3057175 | 2018-10-28 12:30:53 +0000 | [diff] [blame] | 5621 | auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS, |
| 5622 | ToCaseLoc, ToEllipsisLoc, ToColonLoc); |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5623 | ToStmt->setSubStmt(ToSubStmt); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5624 | |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5625 | return ToStmt; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5626 | } |
| 5627 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5628 | ExpectedStmt ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| 5629 | auto Imp = importSeq(S->getDefaultLoc(), S->getColonLoc(), S->getSubStmt()); |
| 5630 | if (!Imp) |
| 5631 | return Imp.takeError(); |
| 5632 | |
| 5633 | SourceLocation ToDefaultLoc, ToColonLoc; |
| 5634 | Stmt *ToSubStmt; |
| 5635 | std::tie(ToDefaultLoc, ToColonLoc, ToSubStmt) = *Imp; |
| 5636 | |
| 5637 | return new (Importer.getToContext()) DefaultStmt( |
| 5638 | ToDefaultLoc, ToColonLoc, ToSubStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5639 | } |
| 5640 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5641 | ExpectedStmt ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| 5642 | auto Imp = importSeq(S->getIdentLoc(), S->getDecl(), S->getSubStmt()); |
| 5643 | if (!Imp) |
| 5644 | return Imp.takeError(); |
| 5645 | |
| 5646 | SourceLocation ToIdentLoc; |
| 5647 | LabelDecl *ToLabelDecl; |
| 5648 | Stmt *ToSubStmt; |
| 5649 | std::tie(ToIdentLoc, ToLabelDecl, ToSubStmt) = *Imp; |
| 5650 | |
| 5651 | return new (Importer.getToContext()) LabelStmt( |
| 5652 | ToIdentLoc, ToLabelDecl, ToSubStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5653 | } |
| 5654 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5655 | ExpectedStmt ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { |
| 5656 | ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc()); |
| 5657 | if (!ToAttrLocOrErr) |
| 5658 | return ToAttrLocOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5659 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 5660 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5661 | if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs)) |
| 5662 | return std::move(Err); |
| 5663 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 5664 | if (!ToSubStmtOrErr) |
| 5665 | return ToSubStmtOrErr.takeError(); |
| 5666 | |
| 5667 | return AttributedStmt::Create( |
| 5668 | Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5669 | } |
| 5670 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5671 | ExpectedStmt ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| 5672 | auto Imp = importSeq( |
| 5673 | S->getIfLoc(), S->getInit(), S->getConditionVariable(), S->getCond(), |
| 5674 | S->getThen(), S->getElseLoc(), S->getElse()); |
| 5675 | if (!Imp) |
| 5676 | return Imp.takeError(); |
| 5677 | |
| 5678 | SourceLocation ToIfLoc, ToElseLoc; |
| 5679 | Stmt *ToInit, *ToThen, *ToElse; |
| 5680 | VarDecl *ToConditionVariable; |
| 5681 | Expr *ToCond; |
| 5682 | std::tie( |
| 5683 | ToIfLoc, ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, ToElse) = |
| 5684 | *Imp; |
| 5685 | |
Bruno Ricci | b1cc94b | 2018-10-27 21:12:20 +0000 | [diff] [blame] | 5686 | return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->isConstexpr(), |
| 5687 | ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, |
| 5688 | ToElse); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5689 | } |
| 5690 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5691 | ExpectedStmt ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
| 5692 | auto Imp = importSeq( |
| 5693 | S->getInit(), S->getConditionVariable(), S->getCond(), |
| 5694 | S->getBody(), S->getSwitchLoc()); |
| 5695 | if (!Imp) |
| 5696 | return Imp.takeError(); |
| 5697 | |
| 5698 | Stmt *ToInit, *ToBody; |
| 5699 | VarDecl *ToConditionVariable; |
| 5700 | Expr *ToCond; |
| 5701 | SourceLocation ToSwitchLoc; |
| 5702 | std::tie(ToInit, ToConditionVariable, ToCond, ToBody, ToSwitchLoc) = *Imp; |
| 5703 | |
Bruno Ricci | e2806f8 | 2018-10-29 16:12:37 +0000 | [diff] [blame] | 5704 | auto *ToStmt = SwitchStmt::Create(Importer.getToContext(), ToInit, |
| 5705 | ToConditionVariable, ToCond); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5706 | ToStmt->setBody(ToBody); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5707 | ToStmt->setSwitchLoc(ToSwitchLoc); |
| 5708 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5709 | // Now we have to re-chain the cases. |
| 5710 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 5711 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 5712 | SC = SC->getNextSwitchCase()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5713 | Expected<SwitchCase *> ToSCOrErr = import(SC); |
| 5714 | if (!ToSCOrErr) |
| 5715 | return ToSCOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5716 | if (LastChainedSwitchCase) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5717 | LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5718 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5719 | ToStmt->setSwitchCaseList(*ToSCOrErr); |
| 5720 | LastChainedSwitchCase = *ToSCOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5721 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5722 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5723 | return ToStmt; |
| 5724 | } |
| 5725 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5726 | ExpectedStmt ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| 5727 | auto Imp = importSeq( |
| 5728 | S->getConditionVariable(), S->getCond(), S->getBody(), S->getWhileLoc()); |
| 5729 | if (!Imp) |
| 5730 | return Imp.takeError(); |
| 5731 | |
| 5732 | VarDecl *ToConditionVariable; |
| 5733 | Expr *ToCond; |
| 5734 | Stmt *ToBody; |
| 5735 | SourceLocation ToWhileLoc; |
| 5736 | std::tie(ToConditionVariable, ToCond, ToBody, ToWhileLoc) = *Imp; |
| 5737 | |
Bruno Ricci | bacf751 | 2018-10-30 13:42:41 +0000 | [diff] [blame] | 5738 | return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond, |
| 5739 | ToBody, ToWhileLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5740 | } |
| 5741 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5742 | ExpectedStmt ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| 5743 | auto Imp = importSeq( |
| 5744 | S->getBody(), S->getCond(), S->getDoLoc(), S->getWhileLoc(), |
| 5745 | S->getRParenLoc()); |
| 5746 | if (!Imp) |
| 5747 | return Imp.takeError(); |
| 5748 | |
| 5749 | Stmt *ToBody; |
| 5750 | Expr *ToCond; |
| 5751 | SourceLocation ToDoLoc, ToWhileLoc, ToRParenLoc; |
| 5752 | std::tie(ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc) = *Imp; |
| 5753 | |
| 5754 | return new (Importer.getToContext()) DoStmt( |
| 5755 | ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5756 | } |
| 5757 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5758 | ExpectedStmt ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| 5759 | auto Imp = importSeq( |
| 5760 | S->getInit(), S->getCond(), S->getConditionVariable(), S->getInc(), |
| 5761 | S->getBody(), S->getForLoc(), S->getLParenLoc(), S->getRParenLoc()); |
| 5762 | if (!Imp) |
| 5763 | return Imp.takeError(); |
| 5764 | |
| 5765 | Stmt *ToInit; |
| 5766 | Expr *ToCond, *ToInc; |
| 5767 | VarDecl *ToConditionVariable; |
| 5768 | Stmt *ToBody; |
| 5769 | SourceLocation ToForLoc, ToLParenLoc, ToRParenLoc; |
| 5770 | std::tie( |
| 5771 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, |
| 5772 | ToLParenLoc, ToRParenLoc) = *Imp; |
| 5773 | |
| 5774 | return new (Importer.getToContext()) ForStmt( |
| 5775 | Importer.getToContext(), |
| 5776 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc, |
| 5777 | ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5778 | } |
| 5779 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5780 | ExpectedStmt ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| 5781 | auto Imp = importSeq(S->getLabel(), S->getGotoLoc(), S->getLabelLoc()); |
| 5782 | if (!Imp) |
| 5783 | return Imp.takeError(); |
| 5784 | |
| 5785 | LabelDecl *ToLabel; |
| 5786 | SourceLocation ToGotoLoc, ToLabelLoc; |
| 5787 | std::tie(ToLabel, ToGotoLoc, ToLabelLoc) = *Imp; |
| 5788 | |
| 5789 | return new (Importer.getToContext()) GotoStmt( |
| 5790 | ToLabel, ToGotoLoc, ToLabelLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5791 | } |
| 5792 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5793 | ExpectedStmt ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 5794 | auto Imp = importSeq(S->getGotoLoc(), S->getStarLoc(), S->getTarget()); |
| 5795 | if (!Imp) |
| 5796 | return Imp.takeError(); |
| 5797 | |
| 5798 | SourceLocation ToGotoLoc, ToStarLoc; |
| 5799 | Expr *ToTarget; |
| 5800 | std::tie(ToGotoLoc, ToStarLoc, ToTarget) = *Imp; |
| 5801 | |
| 5802 | return new (Importer.getToContext()) IndirectGotoStmt( |
| 5803 | ToGotoLoc, ToStarLoc, ToTarget); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5804 | } |
| 5805 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5806 | ExpectedStmt ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 5807 | ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc()); |
| 5808 | if (!ToContinueLocOrErr) |
| 5809 | return ToContinueLocOrErr.takeError(); |
| 5810 | return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5811 | } |
| 5812 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5813 | ExpectedStmt ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 5814 | auto ToBreakLocOrErr = import(S->getBreakLoc()); |
| 5815 | if (!ToBreakLocOrErr) |
| 5816 | return ToBreakLocOrErr.takeError(); |
| 5817 | return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5818 | } |
| 5819 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5820 | ExpectedStmt ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| 5821 | auto Imp = importSeq( |
| 5822 | S->getReturnLoc(), S->getRetValue(), S->getNRVOCandidate()); |
| 5823 | if (!Imp) |
| 5824 | return Imp.takeError(); |
| 5825 | |
| 5826 | SourceLocation ToReturnLoc; |
| 5827 | Expr *ToRetValue; |
| 5828 | const VarDecl *ToNRVOCandidate; |
| 5829 | std::tie(ToReturnLoc, ToRetValue, ToNRVOCandidate) = *Imp; |
| 5830 | |
Bruno Ricci | 023b1d1 | 2018-10-30 14:40:49 +0000 | [diff] [blame] | 5831 | return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue, |
| 5832 | ToNRVOCandidate); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5833 | } |
| 5834 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5835 | ExpectedStmt ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| 5836 | auto Imp = importSeq( |
| 5837 | S->getCatchLoc(), S->getExceptionDecl(), S->getHandlerBlock()); |
| 5838 | if (!Imp) |
| 5839 | return Imp.takeError(); |
| 5840 | |
| 5841 | SourceLocation ToCatchLoc; |
| 5842 | VarDecl *ToExceptionDecl; |
| 5843 | Stmt *ToHandlerBlock; |
| 5844 | std::tie(ToCatchLoc, ToExceptionDecl, ToHandlerBlock) = *Imp; |
| 5845 | |
| 5846 | return new (Importer.getToContext()) CXXCatchStmt ( |
| 5847 | ToCatchLoc, ToExceptionDecl, ToHandlerBlock); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5848 | } |
| 5849 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5850 | ExpectedStmt ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 5851 | ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc()); |
| 5852 | if (!ToTryLocOrErr) |
| 5853 | return ToTryLocOrErr.takeError(); |
| 5854 | |
| 5855 | ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock()); |
| 5856 | if (!ToTryBlockOrErr) |
| 5857 | return ToTryBlockOrErr.takeError(); |
| 5858 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5859 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 5860 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 5861 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5862 | if (auto ToHandlerOrErr = import(FromHandler)) |
| 5863 | ToHandlers[HI] = *ToHandlerOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5864 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5865 | return ToHandlerOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5866 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5867 | |
| 5868 | return CXXTryStmt::Create( |
| 5869 | Importer.getToContext(), *ToTryLocOrErr,*ToTryBlockOrErr, ToHandlers); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5870 | } |
| 5871 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5872 | ExpectedStmt ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
| 5873 | auto Imp1 = importSeq( |
| 5874 | S->getInit(), S->getRangeStmt(), S->getBeginStmt(), S->getEndStmt(), |
| 5875 | S->getCond(), S->getInc(), S->getLoopVarStmt(), S->getBody()); |
| 5876 | if (!Imp1) |
| 5877 | return Imp1.takeError(); |
| 5878 | auto Imp2 = importSeq( |
| 5879 | S->getForLoc(), S->getCoawaitLoc(), S->getColonLoc(), S->getRParenLoc()); |
| 5880 | if (!Imp2) |
| 5881 | return Imp2.takeError(); |
| 5882 | |
| 5883 | DeclStmt *ToRangeStmt, *ToBeginStmt, *ToEndStmt, *ToLoopVarStmt; |
| 5884 | Expr *ToCond, *ToInc; |
| 5885 | Stmt *ToInit, *ToBody; |
| 5886 | std::tie( |
| 5887 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 5888 | ToBody) = *Imp1; |
| 5889 | SourceLocation ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc; |
| 5890 | std::tie(ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc) = *Imp2; |
| 5891 | |
| 5892 | return new (Importer.getToContext()) CXXForRangeStmt( |
| 5893 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 5894 | ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5895 | } |
| 5896 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5897 | ExpectedStmt |
| 5898 | ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 5899 | auto Imp = importSeq( |
| 5900 | S->getElement(), S->getCollection(), S->getBody(), |
| 5901 | S->getForLoc(), S->getRParenLoc()); |
| 5902 | if (!Imp) |
| 5903 | return Imp.takeError(); |
| 5904 | |
| 5905 | Stmt *ToElement, *ToBody; |
| 5906 | Expr *ToCollection; |
| 5907 | SourceLocation ToForLoc, ToRParenLoc; |
| 5908 | std::tie(ToElement, ToCollection, ToBody, ToForLoc, ToRParenLoc) = *Imp; |
| 5909 | |
| 5910 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement, |
| 5911 | ToCollection, |
| 5912 | ToBody, |
| 5913 | ToForLoc, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5914 | ToRParenLoc); |
| 5915 | } |
| 5916 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5917 | ExpectedStmt ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 5918 | auto Imp = importSeq( |
| 5919 | S->getAtCatchLoc(), S->getRParenLoc(), S->getCatchParamDecl(), |
| 5920 | S->getCatchBody()); |
| 5921 | if (!Imp) |
| 5922 | return Imp.takeError(); |
| 5923 | |
| 5924 | SourceLocation ToAtCatchLoc, ToRParenLoc; |
| 5925 | VarDecl *ToCatchParamDecl; |
| 5926 | Stmt *ToCatchBody; |
| 5927 | std::tie(ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody) = *Imp; |
| 5928 | |
| 5929 | return new (Importer.getToContext()) ObjCAtCatchStmt ( |
| 5930 | ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5931 | } |
| 5932 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5933 | ExpectedStmt ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 5934 | ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc()); |
| 5935 | if (!ToAtFinallyLocOrErr) |
| 5936 | return ToAtFinallyLocOrErr.takeError(); |
| 5937 | ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody()); |
| 5938 | if (!ToAtFinallyStmtOrErr) |
| 5939 | return ToAtFinallyStmtOrErr.takeError(); |
| 5940 | return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr, |
| 5941 | *ToAtFinallyStmtOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5942 | } |
| 5943 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5944 | ExpectedStmt ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 5945 | auto Imp = importSeq( |
| 5946 | S->getAtTryLoc(), S->getTryBody(), S->getFinallyStmt()); |
| 5947 | if (!Imp) |
| 5948 | return Imp.takeError(); |
| 5949 | |
| 5950 | SourceLocation ToAtTryLoc; |
| 5951 | Stmt *ToTryBody, *ToFinallyStmt; |
| 5952 | std::tie(ToAtTryLoc, ToTryBody, ToFinallyStmt) = *Imp; |
| 5953 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5954 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 5955 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 5956 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5957 | if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt)) |
| 5958 | ToCatchStmts[CI] = *ToCatchStmtOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5959 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5960 | return ToCatchStmtOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5961 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5962 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5963 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5964 | ToAtTryLoc, ToTryBody, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5965 | ToCatchStmts.begin(), ToCatchStmts.size(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5966 | ToFinallyStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5967 | } |
| 5968 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5969 | ExpectedStmt ASTNodeImporter::VisitObjCAtSynchronizedStmt |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5970 | (ObjCAtSynchronizedStmt *S) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5971 | auto Imp = importSeq( |
| 5972 | S->getAtSynchronizedLoc(), S->getSynchExpr(), S->getSynchBody()); |
| 5973 | if (!Imp) |
| 5974 | return Imp.takeError(); |
| 5975 | |
| 5976 | SourceLocation ToAtSynchronizedLoc; |
| 5977 | Expr *ToSynchExpr; |
| 5978 | Stmt *ToSynchBody; |
| 5979 | std::tie(ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody) = *Imp; |
| 5980 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5981 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 5982 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 5983 | } |
| 5984 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5985 | ExpectedStmt ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 5986 | ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc()); |
| 5987 | if (!ToThrowLocOrErr) |
| 5988 | return ToThrowLocOrErr.takeError(); |
| 5989 | ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr()); |
| 5990 | if (!ToThrowExprOrErr) |
| 5991 | return ToThrowExprOrErr.takeError(); |
| 5992 | return new (Importer.getToContext()) ObjCAtThrowStmt( |
| 5993 | *ToThrowLocOrErr, *ToThrowExprOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5994 | } |
| 5995 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5996 | ExpectedStmt ASTNodeImporter::VisitObjCAutoreleasePoolStmt( |
| 5997 | ObjCAutoreleasePoolStmt *S) { |
| 5998 | ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc()); |
| 5999 | if (!ToAtLocOrErr) |
| 6000 | return ToAtLocOrErr.takeError(); |
| 6001 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 6002 | if (!ToSubStmtOrErr) |
| 6003 | return ToSubStmtOrErr.takeError(); |
| 6004 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr, |
| 6005 | *ToSubStmtOrErr); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6006 | } |
| 6007 | |
| 6008 | //---------------------------------------------------------------------------- |
| 6009 | // Import Expressions |
| 6010 | //---------------------------------------------------------------------------- |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6011 | ExpectedStmt ASTNodeImporter::VisitExpr(Expr *E) { |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6012 | Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node) |
| 6013 | << E->getStmtClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6014 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6015 | } |
| 6016 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6017 | ExpectedStmt ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| 6018 | auto Imp = importSeq( |
| 6019 | E->getBuiltinLoc(), E->getSubExpr(), E->getWrittenTypeInfo(), |
| 6020 | E->getRParenLoc(), E->getType()); |
| 6021 | if (!Imp) |
| 6022 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6023 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6024 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6025 | Expr *ToSubExpr; |
| 6026 | TypeSourceInfo *ToWrittenTypeInfo; |
| 6027 | QualType ToType; |
| 6028 | std::tie(ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType) = |
| 6029 | *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6030 | |
| 6031 | return new (Importer.getToContext()) VAArgExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6032 | ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType, |
| 6033 | E->isMicrosoftABI()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6034 | } |
| 6035 | |
Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 6036 | ExpectedStmt ASTNodeImporter::VisitChooseExpr(ChooseExpr *E) { |
| 6037 | auto Imp = importSeq(E->getCond(), E->getLHS(), E->getRHS(), |
| 6038 | E->getBuiltinLoc(), E->getRParenLoc(), E->getType()); |
| 6039 | if (!Imp) |
| 6040 | return Imp.takeError(); |
| 6041 | |
| 6042 | Expr *ToCond; |
| 6043 | Expr *ToLHS; |
| 6044 | Expr *ToRHS; |
| 6045 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6046 | QualType ToType; |
| 6047 | std::tie(ToCond, ToLHS, ToRHS, ToBuiltinLoc, ToRParenLoc, ToType) = *Imp; |
| 6048 | |
| 6049 | ExprValueKind VK = E->getValueKind(); |
| 6050 | ExprObjectKind OK = E->getObjectKind(); |
| 6051 | |
| 6052 | bool TypeDependent = ToCond->isTypeDependent(); |
| 6053 | bool ValueDependent = ToCond->isValueDependent(); |
| 6054 | |
| 6055 | // The value of CondIsTrue only matters if the value is not |
| 6056 | // condition-dependent. |
| 6057 | bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue(); |
| 6058 | |
| 6059 | return new (Importer.getToContext()) |
| 6060 | ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK, |
| 6061 | ToRParenLoc, CondIsTrue, TypeDependent, ValueDependent); |
| 6062 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6063 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6064 | ExpectedStmt ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 6065 | ExpectedType TypeOrErr = import(E->getType()); |
| 6066 | if (!TypeOrErr) |
| 6067 | return TypeOrErr.takeError(); |
| 6068 | |
| 6069 | ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc()); |
| 6070 | if (!BeginLocOrErr) |
| 6071 | return BeginLocOrErr.takeError(); |
| 6072 | |
| 6073 | return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6074 | } |
| 6075 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6076 | ExpectedStmt ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { |
| 6077 | auto Imp = importSeq( |
| 6078 | E->getBeginLoc(), E->getType(), E->getFunctionName()); |
| 6079 | if (!Imp) |
| 6080 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6081 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6082 | SourceLocation ToBeginLoc; |
| 6083 | QualType ToType; |
| 6084 | StringLiteral *ToFunctionName; |
| 6085 | std::tie(ToBeginLoc, ToType, ToFunctionName) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6086 | |
Bruno Ricci | 17ff026 | 2018-10-27 19:21:19 +0000 | [diff] [blame] | 6087 | return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType, |
| 6088 | E->getIdentKind(), ToFunctionName); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6089 | } |
| 6090 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6091 | ExpectedStmt ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
| 6092 | auto Imp = importSeq( |
| 6093 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDecl(), |
| 6094 | E->getLocation(), E->getType()); |
| 6095 | if (!Imp) |
| 6096 | return Imp.takeError(); |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6097 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6098 | NestedNameSpecifierLoc ToQualifierLoc; |
| 6099 | SourceLocation ToTemplateKeywordLoc, ToLocation; |
| 6100 | ValueDecl *ToDecl; |
| 6101 | QualType ToType; |
| 6102 | std::tie(ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, ToLocation, ToType) = |
| 6103 | *Imp; |
| 6104 | |
| 6105 | NamedDecl *ToFoundD = nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6106 | if (E->getDecl() != E->getFoundDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6107 | auto FoundDOrErr = import(E->getFoundDecl()); |
| 6108 | if (!FoundDOrErr) |
| 6109 | return FoundDOrErr.takeError(); |
| 6110 | ToFoundD = *FoundDOrErr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6111 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6112 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6113 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6114 | TemplateArgumentListInfo *ToResInfo = nullptr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6115 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6116 | if (Error Err = |
| 6117 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 6118 | return std::move(Err); |
| 6119 | ToResInfo = &ToTAInfo; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6120 | } |
| 6121 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6122 | auto *ToE = DeclRefExpr::Create( |
| 6123 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, |
| 6124 | E->refersToEnclosingVariableOrCapture(), ToLocation, ToType, |
| 6125 | E->getValueKind(), ToFoundD, ToResInfo); |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 6126 | if (E->hadMultipleCandidates()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6127 | ToE->setHadMultipleCandidates(true); |
| 6128 | return ToE; |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 6129 | } |
| 6130 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6131 | ExpectedStmt ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 6132 | ExpectedType TypeOrErr = import(E->getType()); |
| 6133 | if (!TypeOrErr) |
| 6134 | return TypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6135 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6136 | return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6137 | } |
| 6138 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6139 | ExpectedStmt ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { |
| 6140 | ExpectedExpr ToInitOrErr = import(E->getInit()); |
| 6141 | if (!ToInitOrErr) |
| 6142 | return ToInitOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6143 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6144 | ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc()); |
| 6145 | if (!ToEqualOrColonLocOrErr) |
| 6146 | return ToEqualOrColonLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6147 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6148 | SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6149 | // List elements from the second, the first is Init itself |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6150 | for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) { |
| 6151 | if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I))) |
| 6152 | ToIndexExprs[I - 1] = *ToArgOrErr; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6153 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6154 | return ToArgOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6155 | } |
| 6156 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6157 | SmallVector<Designator, 4> ToDesignators(E->size()); |
| 6158 | if (Error Err = ImportContainerChecked(E->designators(), ToDesignators)) |
| 6159 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6160 | |
| 6161 | return DesignatedInitExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6162 | Importer.getToContext(), ToDesignators, |
| 6163 | ToIndexExprs, *ToEqualOrColonLocOrErr, |
| 6164 | E->usesGNUSyntax(), *ToInitOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6165 | } |
| 6166 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6167 | ExpectedStmt |
| 6168 | ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 6169 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6170 | if (!ToTypeOrErr) |
| 6171 | return ToTypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6172 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6173 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6174 | if (!ToLocationOrErr) |
| 6175 | return ToLocationOrErr.takeError(); |
| 6176 | |
| 6177 | return new (Importer.getToContext()) CXXNullPtrLiteralExpr( |
| 6178 | *ToTypeOrErr, *ToLocationOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6179 | } |
| 6180 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6181 | ExpectedStmt ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 6182 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6183 | if (!ToTypeOrErr) |
| 6184 | return ToTypeOrErr.takeError(); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6185 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6186 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6187 | if (!ToLocationOrErr) |
| 6188 | return ToLocationOrErr.takeError(); |
| 6189 | |
| 6190 | return IntegerLiteral::Create( |
| 6191 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6192 | } |
| 6193 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6194 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6195 | ExpectedStmt ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 6196 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6197 | if (!ToTypeOrErr) |
| 6198 | return ToTypeOrErr.takeError(); |
| 6199 | |
| 6200 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6201 | if (!ToLocationOrErr) |
| 6202 | return ToLocationOrErr.takeError(); |
| 6203 | |
| 6204 | return FloatingLiteral::Create( |
| 6205 | Importer.getToContext(), E->getValue(), E->isExact(), |
| 6206 | *ToTypeOrErr, *ToLocationOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6207 | } |
| 6208 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6209 | ExpectedStmt ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) { |
| 6210 | auto ToTypeOrErr = import(E->getType()); |
| 6211 | if (!ToTypeOrErr) |
| 6212 | return ToTypeOrErr.takeError(); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6213 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6214 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6215 | if (!ToSubExprOrErr) |
| 6216 | return ToSubExprOrErr.takeError(); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6217 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6218 | return new (Importer.getToContext()) ImaginaryLiteral( |
| 6219 | *ToSubExprOrErr, *ToTypeOrErr); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6220 | } |
| 6221 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6222 | ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 6223 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6224 | if (!ToTypeOrErr) |
| 6225 | return ToTypeOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6226 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6227 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6228 | if (!ToLocationOrErr) |
| 6229 | return ToLocationOrErr.takeError(); |
| 6230 | |
| 6231 | return new (Importer.getToContext()) CharacterLiteral( |
| 6232 | E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr); |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 6233 | } |
| 6234 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6235 | ExpectedStmt ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 6236 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6237 | if (!ToTypeOrErr) |
| 6238 | return ToTypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6239 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6240 | SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated()); |
| 6241 | if (Error Err = ImportArrayChecked( |
| 6242 | E->tokloc_begin(), E->tokloc_end(), ToLocations.begin())) |
| 6243 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6244 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6245 | return StringLiteral::Create( |
| 6246 | Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(), |
| 6247 | *ToTypeOrErr, ToLocations.data(), ToLocations.size()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6248 | } |
| 6249 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6250 | ExpectedStmt ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 6251 | auto Imp = importSeq( |
| 6252 | E->getLParenLoc(), E->getTypeSourceInfo(), E->getType(), |
| 6253 | E->getInitializer()); |
| 6254 | if (!Imp) |
| 6255 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6256 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6257 | SourceLocation ToLParenLoc; |
| 6258 | TypeSourceInfo *ToTypeSourceInfo; |
| 6259 | QualType ToType; |
| 6260 | Expr *ToInitializer; |
| 6261 | std::tie(ToLParenLoc, ToTypeSourceInfo, ToType, ToInitializer) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6262 | |
| 6263 | return new (Importer.getToContext()) CompoundLiteralExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6264 | ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(), |
| 6265 | ToInitializer, E->isFileScope()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6266 | } |
| 6267 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6268 | ExpectedStmt ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { |
| 6269 | auto Imp = importSeq( |
| 6270 | E->getBuiltinLoc(), E->getType(), E->getRParenLoc()); |
| 6271 | if (!Imp) |
| 6272 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6273 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6274 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6275 | QualType ToType; |
| 6276 | std::tie(ToBuiltinLoc, ToType, ToRParenLoc) = *Imp; |
| 6277 | |
| 6278 | SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs()); |
| 6279 | if (Error Err = ImportArrayChecked( |
| 6280 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 6281 | ToExprs.begin())) |
| 6282 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6283 | |
| 6284 | return new (Importer.getToContext()) AtomicExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6285 | ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6286 | } |
| 6287 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6288 | ExpectedStmt ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 6289 | auto Imp = importSeq( |
| 6290 | E->getAmpAmpLoc(), E->getLabelLoc(), E->getLabel(), E->getType()); |
| 6291 | if (!Imp) |
| 6292 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6293 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6294 | SourceLocation ToAmpAmpLoc, ToLabelLoc; |
| 6295 | LabelDecl *ToLabel; |
| 6296 | QualType ToType; |
| 6297 | std::tie(ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6298 | |
| 6299 | return new (Importer.getToContext()) AddrLabelExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6300 | ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6301 | } |
| 6302 | |
Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6303 | ExpectedStmt ASTNodeImporter::VisitConstantExpr(ConstantExpr *E) { |
| 6304 | auto Imp = importSeq(E->getSubExpr()); |
| 6305 | if (!Imp) |
| 6306 | return Imp.takeError(); |
| 6307 | |
| 6308 | Expr *ToSubExpr; |
| 6309 | std::tie(ToSubExpr) = *Imp; |
| 6310 | |
Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 6311 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr); |
Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6312 | } |
| 6313 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6314 | ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| 6315 | auto Imp = importSeq(E->getLParen(), E->getRParen(), E->getSubExpr()); |
| 6316 | if (!Imp) |
| 6317 | return Imp.takeError(); |
| 6318 | |
| 6319 | SourceLocation ToLParen, ToRParen; |
| 6320 | Expr *ToSubExpr; |
| 6321 | std::tie(ToLParen, ToRParen, ToSubExpr) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6322 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6323 | return new (Importer.getToContext()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6324 | ParenExpr(ToLParen, ToRParen, ToSubExpr); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6325 | } |
| 6326 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6327 | ExpectedStmt ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 6328 | SmallVector<Expr *, 4> ToExprs(E->getNumExprs()); |
| 6329 | if (Error Err = ImportContainerChecked(E->exprs(), ToExprs)) |
| 6330 | return std::move(Err); |
| 6331 | |
| 6332 | ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc()); |
| 6333 | if (!ToLParenLocOrErr) |
| 6334 | return ToLParenLocOrErr.takeError(); |
| 6335 | |
| 6336 | ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc()); |
| 6337 | if (!ToRParenLocOrErr) |
| 6338 | return ToRParenLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6339 | |
Bruno Ricci | f49e1ca | 2018-11-20 16:20:40 +0000 | [diff] [blame] | 6340 | return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr, |
| 6341 | ToExprs, *ToRParenLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6342 | } |
| 6343 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6344 | ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| 6345 | auto Imp = importSeq( |
| 6346 | E->getSubStmt(), E->getType(), E->getLParenLoc(), E->getRParenLoc()); |
| 6347 | if (!Imp) |
| 6348 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6349 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6350 | CompoundStmt *ToSubStmt; |
| 6351 | QualType ToType; |
| 6352 | SourceLocation ToLParenLoc, ToRParenLoc; |
| 6353 | std::tie(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6354 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6355 | return new (Importer.getToContext()) StmtExpr( |
| 6356 | ToSubStmt, ToType, ToLParenLoc, ToRParenLoc); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6357 | } |
| 6358 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6359 | ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| 6360 | auto Imp = importSeq( |
| 6361 | E->getSubExpr(), E->getType(), E->getOperatorLoc()); |
| 6362 | if (!Imp) |
| 6363 | return Imp.takeError(); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6364 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6365 | Expr *ToSubExpr; |
| 6366 | QualType ToType; |
| 6367 | SourceLocation ToOperatorLoc; |
| 6368 | std::tie(ToSubExpr, ToType, ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6369 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6370 | return new (Importer.getToContext()) UnaryOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6371 | ToSubExpr, E->getOpcode(), ToType, E->getValueKind(), E->getObjectKind(), |
| 6372 | ToOperatorLoc, E->canOverflow()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6373 | } |
| 6374 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6375 | ExpectedStmt |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6376 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6377 | auto Imp = importSeq(E->getType(), E->getOperatorLoc(), E->getRParenLoc()); |
| 6378 | if (!Imp) |
| 6379 | return Imp.takeError(); |
| 6380 | |
| 6381 | QualType ToType; |
| 6382 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 6383 | std::tie(ToType, ToOperatorLoc, ToRParenLoc) = *Imp; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6384 | |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6385 | if (E->isArgumentType()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6386 | Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr = |
| 6387 | import(E->getArgumentTypeInfo()); |
| 6388 | if (!ToArgumentTypeInfoOrErr) |
| 6389 | return ToArgumentTypeInfoOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6390 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6391 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6392 | E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc, |
| 6393 | ToRParenLoc); |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6394 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6395 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6396 | ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr()); |
| 6397 | if (!ToArgumentExprOrErr) |
| 6398 | return ToArgumentExprOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6399 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6400 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6401 | E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc); |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6402 | } |
| 6403 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6404 | ExpectedStmt ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| 6405 | auto Imp = importSeq( |
| 6406 | E->getLHS(), E->getRHS(), E->getType(), E->getOperatorLoc()); |
| 6407 | if (!Imp) |
| 6408 | return Imp.takeError(); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6409 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6410 | Expr *ToLHS, *ToRHS; |
| 6411 | QualType ToType; |
| 6412 | SourceLocation ToOperatorLoc; |
| 6413 | std::tie(ToLHS, ToRHS, ToType, ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6414 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6415 | return new (Importer.getToContext()) BinaryOperator( |
| 6416 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6417 | E->getObjectKind(), ToOperatorLoc, E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6418 | } |
| 6419 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6420 | ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| 6421 | auto Imp = importSeq( |
| 6422 | E->getCond(), E->getQuestionLoc(), E->getLHS(), E->getColonLoc(), |
| 6423 | E->getRHS(), E->getType()); |
| 6424 | if (!Imp) |
| 6425 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6426 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6427 | Expr *ToCond, *ToLHS, *ToRHS; |
| 6428 | SourceLocation ToQuestionLoc, ToColonLoc; |
| 6429 | QualType ToType; |
| 6430 | std::tie(ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6431 | |
| 6432 | return new (Importer.getToContext()) ConditionalOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6433 | ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType, |
| 6434 | E->getValueKind(), E->getObjectKind()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6435 | } |
| 6436 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6437 | ExpectedStmt ASTNodeImporter::VisitBinaryConditionalOperator( |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6438 | BinaryConditionalOperator *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6439 | auto Imp = importSeq( |
| 6440 | E->getCommon(), E->getOpaqueValue(), E->getCond(), E->getTrueExpr(), |
| 6441 | E->getFalseExpr(), E->getQuestionLoc(), E->getColonLoc(), E->getType()); |
| 6442 | if (!Imp) |
| 6443 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6444 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6445 | Expr *ToCommon, *ToCond, *ToTrueExpr, *ToFalseExpr; |
| 6446 | OpaqueValueExpr *ToOpaqueValue; |
| 6447 | SourceLocation ToQuestionLoc, ToColonLoc; |
| 6448 | QualType ToType; |
| 6449 | std::tie( |
| 6450 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, ToQuestionLoc, |
| 6451 | ToColonLoc, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6452 | |
| 6453 | return new (Importer.getToContext()) BinaryConditionalOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6454 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, |
| 6455 | ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(), |
| 6456 | E->getObjectKind()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6457 | } |
| 6458 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6459 | ExpectedStmt ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 6460 | auto Imp = importSeq( |
| 6461 | E->getBeginLoc(), E->getQueriedTypeSourceInfo(), |
| 6462 | E->getDimensionExpression(), E->getEndLoc(), E->getType()); |
| 6463 | if (!Imp) |
| 6464 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6465 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6466 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6467 | TypeSourceInfo *ToQueriedTypeSourceInfo; |
| 6468 | Expr *ToDimensionExpression; |
| 6469 | QualType ToType; |
| 6470 | std::tie( |
| 6471 | ToBeginLoc, ToQueriedTypeSourceInfo, ToDimensionExpression, ToEndLoc, |
| 6472 | ToType) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6473 | |
| 6474 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6475 | ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(), |
| 6476 | ToDimensionExpression, ToEndLoc, ToType); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6477 | } |
| 6478 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6479 | ExpectedStmt ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 6480 | auto Imp = importSeq( |
| 6481 | E->getBeginLoc(), E->getQueriedExpression(), E->getEndLoc(), E->getType()); |
| 6482 | if (!Imp) |
| 6483 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6484 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6485 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6486 | Expr *ToQueriedExpression; |
| 6487 | QualType ToType; |
| 6488 | std::tie(ToBeginLoc, ToQueriedExpression, ToEndLoc, ToType) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6489 | |
| 6490 | return new (Importer.getToContext()) ExpressionTraitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6491 | ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(), |
| 6492 | ToEndLoc, ToType); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6493 | } |
| 6494 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6495 | ExpectedStmt ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| 6496 | auto Imp = importSeq( |
| 6497 | E->getLocation(), E->getType(), E->getSourceExpr()); |
| 6498 | if (!Imp) |
| 6499 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6500 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6501 | SourceLocation ToLocation; |
| 6502 | QualType ToType; |
| 6503 | Expr *ToSourceExpr; |
| 6504 | std::tie(ToLocation, ToType, ToSourceExpr) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6505 | |
| 6506 | return new (Importer.getToContext()) OpaqueValueExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6507 | ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr); |
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::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 6511 | auto Imp = importSeq( |
| 6512 | E->getLHS(), E->getRHS(), E->getType(), E->getRBracketLoc()); |
| 6513 | if (!Imp) |
| 6514 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6515 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6516 | Expr *ToLHS, *ToRHS; |
| 6517 | SourceLocation ToRBracketLoc; |
| 6518 | QualType ToType; |
| 6519 | std::tie(ToLHS, ToRHS, ToType, ToRBracketLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6520 | |
| 6521 | return new (Importer.getToContext()) ArraySubscriptExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6522 | ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(), |
| 6523 | ToRBracketLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6524 | } |
| 6525 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6526 | ExpectedStmt |
| 6527 | ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 6528 | auto Imp = importSeq( |
| 6529 | E->getLHS(), E->getRHS(), E->getType(), E->getComputationLHSType(), |
| 6530 | E->getComputationResultType(), E->getOperatorLoc()); |
| 6531 | if (!Imp) |
| 6532 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6533 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6534 | Expr *ToLHS, *ToRHS; |
| 6535 | QualType ToType, ToComputationLHSType, ToComputationResultType; |
| 6536 | SourceLocation ToOperatorLoc; |
| 6537 | std::tie(ToLHS, ToRHS, ToType, ToComputationLHSType, ToComputationResultType, |
| 6538 | ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6539 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6540 | return new (Importer.getToContext()) CompoundAssignOperator( |
| 6541 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6542 | E->getObjectKind(), ToComputationLHSType, ToComputationResultType, |
| 6543 | ToOperatorLoc, E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6544 | } |
| 6545 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6546 | Expected<CXXCastPath> |
| 6547 | ASTNodeImporter::ImportCastPath(CastExpr *CE) { |
| 6548 | CXXCastPath Path; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6549 | 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] | 6550 | if (auto SpecOrErr = import(*I)) |
| 6551 | Path.push_back(*SpecOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6552 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6553 | return SpecOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6554 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6555 | return Path; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6556 | } |
| 6557 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6558 | ExpectedStmt ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 6559 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6560 | if (!ToTypeOrErr) |
| 6561 | return ToTypeOrErr.takeError(); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6562 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6563 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6564 | if (!ToSubExprOrErr) |
| 6565 | return ToSubExprOrErr.takeError(); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6566 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6567 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6568 | if (!ToBasePathOrErr) |
| 6569 | return ToBasePathOrErr.takeError(); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6570 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6571 | return ImplicitCastExpr::Create( |
| 6572 | Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr, |
| 6573 | &(*ToBasePathOrErr), E->getValueKind()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6574 | } |
| 6575 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6576 | ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
| 6577 | auto Imp1 = importSeq( |
| 6578 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten()); |
| 6579 | if (!Imp1) |
| 6580 | return Imp1.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6581 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6582 | QualType ToType; |
| 6583 | Expr *ToSubExpr; |
| 6584 | TypeSourceInfo *ToTypeInfoAsWritten; |
| 6585 | std::tie(ToType, ToSubExpr, ToTypeInfoAsWritten) = *Imp1; |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6586 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6587 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6588 | if (!ToBasePathOrErr) |
| 6589 | return ToBasePathOrErr.takeError(); |
| 6590 | CXXCastPath *ToBasePath = &(*ToBasePathOrErr); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6591 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6592 | switch (E->getStmtClass()) { |
| 6593 | case Stmt::CStyleCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6594 | auto *CCE = cast<CStyleCastExpr>(E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6595 | ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc()); |
| 6596 | if (!ToLParenLocOrErr) |
| 6597 | return ToLParenLocOrErr.takeError(); |
| 6598 | ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc()); |
| 6599 | if (!ToRParenLocOrErr) |
| 6600 | return ToRParenLocOrErr.takeError(); |
| 6601 | return CStyleCastExpr::Create( |
| 6602 | Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(), |
| 6603 | ToSubExpr, ToBasePath, ToTypeInfoAsWritten, *ToLParenLocOrErr, |
| 6604 | *ToRParenLocOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6605 | } |
| 6606 | |
| 6607 | case Stmt::CXXFunctionalCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6608 | auto *FCE = cast<CXXFunctionalCastExpr>(E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6609 | ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc()); |
| 6610 | if (!ToLParenLocOrErr) |
| 6611 | return ToLParenLocOrErr.takeError(); |
| 6612 | ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc()); |
| 6613 | if (!ToRParenLocOrErr) |
| 6614 | return ToRParenLocOrErr.takeError(); |
| 6615 | return CXXFunctionalCastExpr::Create( |
| 6616 | Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten, |
| 6617 | E->getCastKind(), ToSubExpr, ToBasePath, *ToLParenLocOrErr, |
| 6618 | *ToRParenLocOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6619 | } |
| 6620 | |
| 6621 | case Stmt::ObjCBridgedCastExprClass: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6622 | auto *OCE = cast<ObjCBridgedCastExpr>(E); |
| 6623 | ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc()); |
| 6624 | if (!ToLParenLocOrErr) |
| 6625 | return ToLParenLocOrErr.takeError(); |
| 6626 | ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc()); |
| 6627 | if (!ToBridgeKeywordLocOrErr) |
| 6628 | return ToBridgeKeywordLocOrErr.takeError(); |
| 6629 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 6630 | *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), |
| 6631 | *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6632 | } |
| 6633 | default: |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6634 | llvm_unreachable("Cast expression of unsupported type!"); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6635 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6636 | } |
| 6637 | } |
| 6638 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6639 | ExpectedStmt ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *E) { |
| 6640 | SmallVector<OffsetOfNode, 4> ToNodes; |
| 6641 | for (int I = 0, N = E->getNumComponents(); I < N; ++I) { |
| 6642 | const OffsetOfNode &FromNode = E->getComponent(I); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6643 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6644 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6645 | if (FromNode.getKind() != OffsetOfNode::Base) { |
| 6646 | auto Imp = importSeq(FromNode.getBeginLoc(), FromNode.getEndLoc()); |
| 6647 | if (!Imp) |
| 6648 | return Imp.takeError(); |
| 6649 | std::tie(ToBeginLoc, ToEndLoc) = *Imp; |
| 6650 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6651 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6652 | switch (FromNode.getKind()) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6653 | case OffsetOfNode::Array: |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6654 | ToNodes.push_back( |
| 6655 | OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6656 | break; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6657 | case OffsetOfNode::Base: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6658 | auto ToBSOrErr = import(FromNode.getBase()); |
| 6659 | if (!ToBSOrErr) |
| 6660 | return ToBSOrErr.takeError(); |
| 6661 | ToNodes.push_back(OffsetOfNode(*ToBSOrErr)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6662 | break; |
| 6663 | } |
| 6664 | case OffsetOfNode::Field: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6665 | auto ToFieldOrErr = import(FromNode.getField()); |
| 6666 | if (!ToFieldOrErr) |
| 6667 | return ToFieldOrErr.takeError(); |
| 6668 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6669 | break; |
| 6670 | } |
| 6671 | case OffsetOfNode::Identifier: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6672 | IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName()); |
| 6673 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6674 | break; |
| 6675 | } |
| 6676 | } |
| 6677 | } |
| 6678 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6679 | SmallVector<Expr *, 4> ToExprs(E->getNumExpressions()); |
| 6680 | for (int I = 0, N = E->getNumExpressions(); I < N; ++I) { |
| 6681 | ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I)); |
| 6682 | if (!ToIndexExprOrErr) |
| 6683 | return ToIndexExprOrErr.takeError(); |
| 6684 | ToExprs[I] = *ToIndexExprOrErr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6685 | } |
| 6686 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6687 | auto Imp = importSeq( |
| 6688 | E->getType(), E->getTypeSourceInfo(), E->getOperatorLoc(), |
| 6689 | E->getRParenLoc()); |
| 6690 | if (!Imp) |
| 6691 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6692 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6693 | QualType ToType; |
| 6694 | TypeSourceInfo *ToTypeSourceInfo; |
| 6695 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 6696 | std::tie(ToType, ToTypeSourceInfo, ToOperatorLoc, ToRParenLoc) = *Imp; |
| 6697 | |
| 6698 | return OffsetOfExpr::Create( |
| 6699 | Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes, |
| 6700 | ToExprs, ToRParenLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6701 | } |
| 6702 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6703 | ExpectedStmt ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 6704 | auto Imp = importSeq( |
| 6705 | E->getType(), E->getOperand(), E->getBeginLoc(), E->getEndLoc()); |
| 6706 | if (!Imp) |
| 6707 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6708 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6709 | QualType ToType; |
| 6710 | Expr *ToOperand; |
| 6711 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6712 | std::tie(ToType, ToOperand, ToBeginLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6713 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6714 | CanThrowResult ToCanThrow; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6715 | if (E->isValueDependent()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6716 | ToCanThrow = CT_Dependent; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6717 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6718 | ToCanThrow = E->getValue() ? CT_Can : CT_Cannot; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6719 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6720 | return new (Importer.getToContext()) CXXNoexceptExpr( |
| 6721 | ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6722 | } |
| 6723 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6724 | ExpectedStmt ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| 6725 | auto Imp = importSeq(E->getSubExpr(), E->getType(), E->getThrowLoc()); |
| 6726 | if (!Imp) |
| 6727 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6728 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6729 | Expr *ToSubExpr; |
| 6730 | QualType ToType; |
| 6731 | SourceLocation ToThrowLoc; |
| 6732 | std::tie(ToSubExpr, ToType, ToThrowLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6733 | |
| 6734 | return new (Importer.getToContext()) CXXThrowExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6735 | ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6736 | } |
| 6737 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6738 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| 6739 | ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation()); |
| 6740 | if (!ToUsedLocOrErr) |
| 6741 | return ToUsedLocOrErr.takeError(); |
| 6742 | |
| 6743 | auto ToParamOrErr = import(E->getParam()); |
| 6744 | if (!ToParamOrErr) |
| 6745 | return ToParamOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6746 | |
| 6747 | return CXXDefaultArgExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6748 | Importer.getToContext(), *ToUsedLocOrErr, *ToParamOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6749 | } |
| 6750 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6751 | ExpectedStmt |
| 6752 | ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| 6753 | auto Imp = importSeq( |
| 6754 | E->getType(), E->getTypeSourceInfo(), E->getRParenLoc()); |
| 6755 | if (!Imp) |
| 6756 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6757 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6758 | QualType ToType; |
| 6759 | TypeSourceInfo *ToTypeSourceInfo; |
| 6760 | SourceLocation ToRParenLoc; |
| 6761 | std::tie(ToType, ToTypeSourceInfo, ToRParenLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6762 | |
| 6763 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6764 | ToType, ToTypeSourceInfo, ToRParenLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6765 | } |
| 6766 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6767 | ExpectedStmt |
| 6768 | ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 6769 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6770 | if (!ToSubExprOrErr) |
| 6771 | return ToSubExprOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6772 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6773 | auto ToDtorOrErr = import(E->getTemporary()->getDestructor()); |
| 6774 | if (!ToDtorOrErr) |
| 6775 | return ToDtorOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6776 | |
| 6777 | ASTContext &ToCtx = Importer.getToContext(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6778 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr); |
| 6779 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6780 | } |
| 6781 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6782 | ExpectedStmt |
| 6783 | ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { |
| 6784 | auto Imp = importSeq( |
| 6785 | E->getConstructor(), E->getType(), E->getTypeSourceInfo(), |
| 6786 | E->getParenOrBraceRange()); |
| 6787 | if (!Imp) |
| 6788 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6789 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6790 | CXXConstructorDecl *ToConstructor; |
| 6791 | QualType ToType; |
| 6792 | TypeSourceInfo *ToTypeSourceInfo; |
| 6793 | SourceRange ToParenOrBraceRange; |
| 6794 | std::tie(ToConstructor, ToType, ToTypeSourceInfo, ToParenOrBraceRange) = *Imp; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6795 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6796 | SmallVector<Expr *, 8> ToArgs(E->getNumArgs()); |
| 6797 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 6798 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6799 | |
Bruno Ricci | ddb8f6b | 2018-12-22 14:39:30 +0000 | [diff] [blame] | 6800 | return CXXTemporaryObjectExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6801 | Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs, |
| 6802 | ToParenOrBraceRange, E->hadMultipleCandidates(), |
| 6803 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 6804 | E->requiresZeroInitialization()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6805 | } |
| 6806 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6807 | ExpectedStmt |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6808 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6809 | auto Imp = importSeq( |
| 6810 | E->getType(), E->GetTemporaryExpr(), E->getExtendingDecl()); |
| 6811 | if (!Imp) |
| 6812 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6813 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6814 | QualType ToType; |
| 6815 | Expr *ToTemporaryExpr; |
| 6816 | const ValueDecl *ToExtendingDecl; |
| 6817 | std::tie(ToType, ToTemporaryExpr, ToExtendingDecl) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6818 | |
| 6819 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6820 | ToType, ToTemporaryExpr, E->isBoundToLvalueReference()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6821 | |
| 6822 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6823 | ToMTE->setExtendingDecl(ToExtendingDecl, E->getManglingNumber()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6824 | return ToMTE; |
| 6825 | } |
| 6826 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6827 | ExpectedStmt ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { |
| 6828 | auto Imp = importSeq( |
| 6829 | E->getType(), E->getPattern(), E->getEllipsisLoc()); |
| 6830 | if (!Imp) |
| 6831 | return Imp.takeError(); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6832 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6833 | QualType ToType; |
| 6834 | Expr *ToPattern; |
| 6835 | SourceLocation ToEllipsisLoc; |
| 6836 | std::tie(ToType, ToPattern, ToEllipsisLoc) = *Imp; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6837 | |
| 6838 | return new (Importer.getToContext()) PackExpansionExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6839 | ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions()); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6840 | } |
| 6841 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6842 | ExpectedStmt ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { |
| 6843 | auto Imp = importSeq( |
| 6844 | E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc()); |
| 6845 | if (!Imp) |
| 6846 | return Imp.takeError(); |
| 6847 | |
| 6848 | SourceLocation ToOperatorLoc, ToPackLoc, ToRParenLoc; |
| 6849 | NamedDecl *ToPack; |
| 6850 | std::tie(ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc) = *Imp; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6851 | |
| 6852 | Optional<unsigned> Length; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6853 | if (!E->isValueDependent()) |
| 6854 | Length = E->getPackLength(); |
| 6855 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6856 | SmallVector<TemplateArgument, 8> ToPartialArguments; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6857 | if (E->isPartiallySubstituted()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6858 | if (Error Err = ImportTemplateArguments( |
| 6859 | E->getPartialArguments().data(), |
| 6860 | E->getPartialArguments().size(), |
| 6861 | ToPartialArguments)) |
| 6862 | return std::move(Err); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6863 | } |
| 6864 | |
| 6865 | return SizeOfPackExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6866 | Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc, |
| 6867 | Length, ToPartialArguments); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6868 | } |
| 6869 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6870 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6871 | ExpectedStmt ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) { |
| 6872 | auto Imp = importSeq( |
| 6873 | E->getOperatorNew(), E->getOperatorDelete(), E->getTypeIdParens(), |
| 6874 | E->getArraySize(), E->getInitializer(), E->getType(), |
| 6875 | E->getAllocatedTypeSourceInfo(), E->getSourceRange(), |
| 6876 | E->getDirectInitRange()); |
| 6877 | if (!Imp) |
| 6878 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6879 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6880 | FunctionDecl *ToOperatorNew, *ToOperatorDelete; |
| 6881 | SourceRange ToTypeIdParens, ToSourceRange, ToDirectInitRange; |
| 6882 | Expr *ToArraySize, *ToInitializer; |
| 6883 | QualType ToType; |
| 6884 | TypeSourceInfo *ToAllocatedTypeSourceInfo; |
| 6885 | std::tie( |
| 6886 | ToOperatorNew, ToOperatorDelete, ToTypeIdParens, ToArraySize, ToInitializer, |
| 6887 | ToType, ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6888 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6889 | SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs()); |
| 6890 | if (Error Err = |
| 6891 | ImportContainerChecked(E->placement_arguments(), ToPlacementArgs)) |
| 6892 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6893 | |
Bruno Ricci | 9b6dfac | 2019-01-07 15:04:45 +0000 | [diff] [blame] | 6894 | return CXXNewExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6895 | Importer.getToContext(), E->isGlobalNew(), ToOperatorNew, |
| 6896 | ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(), |
| 6897 | ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(), |
| 6898 | ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange, |
| 6899 | ToDirectInitRange); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6900 | } |
| 6901 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6902 | ExpectedStmt ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 6903 | auto Imp = importSeq( |
| 6904 | E->getType(), E->getOperatorDelete(), E->getArgument(), E->getBeginLoc()); |
| 6905 | if (!Imp) |
| 6906 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6907 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6908 | QualType ToType; |
| 6909 | FunctionDecl *ToOperatorDelete; |
| 6910 | Expr *ToArgument; |
| 6911 | SourceLocation ToBeginLoc; |
| 6912 | std::tie(ToType, ToOperatorDelete, ToArgument, ToBeginLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6913 | |
| 6914 | return new (Importer.getToContext()) CXXDeleteExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6915 | ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(), |
| 6916 | E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument, |
| 6917 | ToBeginLoc); |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6918 | } |
| 6919 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6920 | ExpectedStmt ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| 6921 | auto Imp = importSeq( |
| 6922 | E->getType(), E->getLocation(), E->getConstructor(), |
| 6923 | E->getParenOrBraceRange()); |
| 6924 | if (!Imp) |
| 6925 | return Imp.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6926 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6927 | QualType ToType; |
| 6928 | SourceLocation ToLocation; |
| 6929 | CXXConstructorDecl *ToConstructor; |
| 6930 | SourceRange ToParenOrBraceRange; |
| 6931 | std::tie(ToType, ToLocation, ToConstructor, ToParenOrBraceRange) = *Imp; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6932 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6933 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6934 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 6935 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6936 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6937 | return CXXConstructExpr::Create( |
| 6938 | Importer.getToContext(), ToType, ToLocation, ToConstructor, |
| 6939 | E->isElidable(), ToArgs, E->hadMultipleCandidates(), |
| 6940 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 6941 | E->requiresZeroInitialization(), E->getConstructionKind(), |
| 6942 | ToParenOrBraceRange); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6943 | } |
| 6944 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6945 | ExpectedStmt ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *E) { |
| 6946 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6947 | if (!ToSubExprOrErr) |
| 6948 | return ToSubExprOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6949 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6950 | SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects()); |
| 6951 | if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects)) |
| 6952 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6953 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6954 | return ExprWithCleanups::Create( |
| 6955 | Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(), |
| 6956 | ToObjects); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6957 | } |
| 6958 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6959 | ExpectedStmt ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 6960 | auto Imp = importSeq( |
| 6961 | E->getCallee(), E->getType(), E->getRParenLoc()); |
| 6962 | if (!Imp) |
| 6963 | return Imp.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6964 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6965 | Expr *ToCallee; |
| 6966 | QualType ToType; |
| 6967 | SourceLocation ToRParenLoc; |
| 6968 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6969 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6970 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6971 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 6972 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6973 | |
Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 6974 | return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, |
| 6975 | ToType, E->getValueKind(), ToRParenLoc); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6976 | } |
| 6977 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6978 | ExpectedStmt ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 6979 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6980 | if (!ToTypeOrErr) |
| 6981 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6982 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6983 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6984 | if (!ToLocationOrErr) |
| 6985 | return ToLocationOrErr.takeError(); |
| 6986 | |
| 6987 | return new (Importer.getToContext()) CXXThisExpr( |
| 6988 | *ToLocationOrErr, *ToTypeOrErr, E->isImplicit()); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6989 | } |
| 6990 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6991 | ExpectedStmt ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 6992 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6993 | if (!ToTypeOrErr) |
| 6994 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6995 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6996 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6997 | if (!ToLocationOrErr) |
| 6998 | return ToLocationOrErr.takeError(); |
| 6999 | |
| 7000 | return new (Importer.getToContext()) CXXBoolLiteralExpr( |
| 7001 | E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7002 | } |
| 7003 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7004 | ExpectedStmt ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| 7005 | auto Imp1 = importSeq( |
| 7006 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7007 | E->getTemplateKeywordLoc(), E->getMemberDecl(), E->getType()); |
| 7008 | if (!Imp1) |
| 7009 | return Imp1.takeError(); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7010 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7011 | Expr *ToBase; |
| 7012 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7013 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7014 | ValueDecl *ToMemberDecl; |
| 7015 | QualType ToType; |
| 7016 | std::tie( |
| 7017 | ToBase, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, |
| 7018 | ToType) = *Imp1; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7019 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7020 | auto Imp2 = importSeq( |
| 7021 | E->getFoundDecl().getDecl(), E->getMemberNameInfo().getName(), |
| 7022 | E->getMemberNameInfo().getLoc(), E->getLAngleLoc(), E->getRAngleLoc()); |
| 7023 | if (!Imp2) |
| 7024 | return Imp2.takeError(); |
| 7025 | NamedDecl *ToDecl; |
| 7026 | DeclarationName ToName; |
| 7027 | SourceLocation ToLoc, ToLAngleLoc, ToRAngleLoc; |
| 7028 | std::tie(ToDecl, ToName, ToLoc, ToLAngleLoc, ToRAngleLoc) = *Imp2; |
Peter Szecsi | ef97252 | 2018-05-02 11:52:54 +0000 | [diff] [blame] | 7029 | |
| 7030 | DeclAccessPair ToFoundDecl = |
| 7031 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7032 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7033 | DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7034 | |
Gabor Marton | 5caba30 | 2019-03-07 13:38:20 +0000 | [diff] [blame] | 7035 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7036 | if (E->hasExplicitTemplateArgs()) { |
Gabor Marton | 5caba30 | 2019-03-07 13:38:20 +0000 | [diff] [blame] | 7037 | if (Error Err = |
| 7038 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 7039 | E->template_arguments(), ToTAInfo)) |
| 7040 | return std::move(Err); |
| 7041 | ResInfo = &ToTAInfo; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7042 | } |
| 7043 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7044 | return MemberExpr::Create( |
| 7045 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, |
| 7046 | ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, ToFoundDecl, |
Gabor Marton | 5caba30 | 2019-03-07 13:38:20 +0000 | [diff] [blame] | 7047 | ToMemberNameInfo, ResInfo, ToType, E->getValueKind(), E->getObjectKind()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7048 | } |
| 7049 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7050 | ExpectedStmt |
| 7051 | ASTNodeImporter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { |
| 7052 | auto Imp = importSeq( |
| 7053 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7054 | E->getScopeTypeInfo(), E->getColonColonLoc(), E->getTildeLoc()); |
| 7055 | if (!Imp) |
| 7056 | return Imp.takeError(); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7057 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7058 | Expr *ToBase; |
| 7059 | SourceLocation ToOperatorLoc, ToColonColonLoc, ToTildeLoc; |
| 7060 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7061 | TypeSourceInfo *ToScopeTypeInfo; |
| 7062 | std::tie( |
| 7063 | ToBase, ToOperatorLoc, ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, |
| 7064 | ToTildeLoc) = *Imp; |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7065 | |
| 7066 | PseudoDestructorTypeStorage Storage; |
| 7067 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { |
| 7068 | IdentifierInfo *ToII = Importer.Import(FromII); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7069 | ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc()); |
| 7070 | if (!ToDestroyedTypeLocOrErr) |
| 7071 | return ToDestroyedTypeLocOrErr.takeError(); |
| 7072 | Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7073 | } else { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7074 | if (auto ToTIOrErr = import(E->getDestroyedTypeInfo())) |
| 7075 | Storage = PseudoDestructorTypeStorage(*ToTIOrErr); |
| 7076 | else |
| 7077 | return ToTIOrErr.takeError(); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7078 | } |
| 7079 | |
| 7080 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7081 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, |
| 7082 | ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7083 | } |
| 7084 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7085 | ExpectedStmt ASTNodeImporter::VisitCXXDependentScopeMemberExpr( |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7086 | CXXDependentScopeMemberExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7087 | auto Imp = importSeq( |
| 7088 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7089 | E->getTemplateKeywordLoc(), E->getFirstQualifierFoundInScope()); |
| 7090 | if (!Imp) |
| 7091 | return Imp.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7092 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7093 | QualType ToType; |
| 7094 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7095 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7096 | NamedDecl *ToFirstQualifierFoundInScope; |
| 7097 | std::tie( |
| 7098 | ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7099 | ToFirstQualifierFoundInScope) = *Imp; |
| 7100 | |
| 7101 | Expr *ToBase = nullptr; |
| 7102 | if (!E->isImplicitAccess()) { |
| 7103 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7104 | ToBase = *ToBaseOrErr; |
| 7105 | else |
| 7106 | return ToBaseOrErr.takeError(); |
| 7107 | } |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7108 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7109 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7110 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7111 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7112 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7113 | ToTAInfo)) |
| 7114 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7115 | ResInfo = &ToTAInfo; |
| 7116 | } |
| 7117 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7118 | auto ToMemberNameInfoOrErr = importSeq(E->getMember(), E->getMemberLoc()); |
| 7119 | if (!ToMemberNameInfoOrErr) |
| 7120 | return ToMemberNameInfoOrErr.takeError(); |
| 7121 | DeclarationNameInfo ToMemberNameInfo( |
| 7122 | std::get<0>(*ToMemberNameInfoOrErr), std::get<1>(*ToMemberNameInfoOrErr)); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7123 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7124 | if (Error Err = ImportDeclarationNameLoc( |
| 7125 | E->getMemberNameInfo(), ToMemberNameInfo)) |
| 7126 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7127 | |
| 7128 | return CXXDependentScopeMemberExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7129 | Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc, |
| 7130 | ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope, |
| 7131 | ToMemberNameInfo, ResInfo); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7132 | } |
| 7133 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7134 | ExpectedStmt |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7135 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7136 | auto Imp = importSeq( |
| 7137 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDeclName(), |
| 7138 | E->getExprLoc(), E->getLAngleLoc(), E->getRAngleLoc()); |
| 7139 | if (!Imp) |
| 7140 | return Imp.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7141 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7142 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7143 | SourceLocation ToTemplateKeywordLoc, ToExprLoc, ToLAngleLoc, ToRAngleLoc; |
| 7144 | DeclarationName ToDeclName; |
| 7145 | std::tie( |
| 7146 | ToQualifierLoc, ToTemplateKeywordLoc, ToDeclName, ToExprLoc, |
| 7147 | ToLAngleLoc, ToRAngleLoc) = *Imp; |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7148 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7149 | DeclarationNameInfo ToNameInfo(ToDeclName, ToExprLoc); |
| 7150 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7151 | return std::move(Err); |
| 7152 | |
| 7153 | TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7154 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7155 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7156 | if (Error Err = |
| 7157 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 7158 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7159 | ResInfo = &ToTAInfo; |
| 7160 | } |
| 7161 | |
| 7162 | return DependentScopeDeclRefExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7163 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, |
| 7164 | ToNameInfo, ResInfo); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7165 | } |
| 7166 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7167 | ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr( |
| 7168 | CXXUnresolvedConstructExpr *E) { |
| 7169 | auto Imp = importSeq( |
| 7170 | E->getLParenLoc(), E->getRParenLoc(), E->getTypeSourceInfo()); |
| 7171 | if (!Imp) |
| 7172 | return Imp.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7173 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7174 | SourceLocation ToLParenLoc, ToRParenLoc; |
| 7175 | TypeSourceInfo *ToTypeSourceInfo; |
| 7176 | std::tie(ToLParenLoc, ToRParenLoc, ToTypeSourceInfo) = *Imp; |
| 7177 | |
| 7178 | SmallVector<Expr *, 8> ToArgs(E->arg_size()); |
| 7179 | if (Error Err = |
| 7180 | ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin())) |
| 7181 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7182 | |
| 7183 | return CXXUnresolvedConstructExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7184 | Importer.getToContext(), ToTypeSourceInfo, ToLParenLoc, |
| 7185 | llvm::makeArrayRef(ToArgs), ToRParenLoc); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7186 | } |
| 7187 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7188 | ExpectedStmt |
| 7189 | ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { |
| 7190 | Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass()); |
| 7191 | if (!ToNamingClassOrErr) |
| 7192 | return ToNamingClassOrErr.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7193 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7194 | auto ToQualifierLocOrErr = import(E->getQualifierLoc()); |
| 7195 | if (!ToQualifierLocOrErr) |
| 7196 | return ToQualifierLocOrErr.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7197 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7198 | auto ToNameInfoOrErr = importSeq(E->getName(), E->getNameLoc()); |
| 7199 | if (!ToNameInfoOrErr) |
| 7200 | return ToNameInfoOrErr.takeError(); |
| 7201 | DeclarationNameInfo ToNameInfo( |
| 7202 | std::get<0>(*ToNameInfoOrErr), std::get<1>(*ToNameInfoOrErr)); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7203 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7204 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7205 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7206 | |
| 7207 | UnresolvedSet<8> ToDecls; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7208 | for (auto *D : E->decls()) |
| 7209 | if (auto ToDOrErr = import(D)) |
| 7210 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7211 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7212 | return ToDOrErr.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7213 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7214 | if (E->hasExplicitTemplateArgs() && E->getTemplateKeywordLoc().isValid()) { |
| 7215 | TemplateArgumentListInfo ToTAInfo; |
| 7216 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7217 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7218 | ToTAInfo)) |
| 7219 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7220 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7221 | ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc()); |
| 7222 | if (!ToTemplateKeywordLocOrErr) |
| 7223 | return ToTemplateKeywordLocOrErr.takeError(); |
| 7224 | |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7225 | return UnresolvedLookupExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7226 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7227 | *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo, |
| 7228 | ToDecls.begin(), ToDecls.end()); |
| 7229 | } |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7230 | |
| 7231 | return UnresolvedLookupExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7232 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7233 | ToNameInfo, E->requiresADL(), E->isOverloaded(), ToDecls.begin(), |
| 7234 | ToDecls.end()); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7235 | } |
| 7236 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7237 | ExpectedStmt |
| 7238 | ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { |
| 7239 | auto Imp1 = importSeq( |
| 7240 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7241 | E->getTemplateKeywordLoc()); |
| 7242 | if (!Imp1) |
| 7243 | return Imp1.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7244 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7245 | QualType ToType; |
| 7246 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7247 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7248 | std::tie(ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc) = *Imp1; |
| 7249 | |
| 7250 | auto Imp2 = importSeq(E->getName(), E->getNameLoc()); |
| 7251 | if (!Imp2) |
| 7252 | return Imp2.takeError(); |
| 7253 | DeclarationNameInfo ToNameInfo(std::get<0>(*Imp2), std::get<1>(*Imp2)); |
| 7254 | // Import additional name location/type info. |
| 7255 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7256 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7257 | |
| 7258 | UnresolvedSet<8> ToDecls; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7259 | for (Decl *D : E->decls()) |
| 7260 | if (auto ToDOrErr = import(D)) |
| 7261 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7262 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7263 | return ToDOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7264 | |
| 7265 | TemplateArgumentListInfo ToTAInfo; |
| 7266 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7267 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7268 | if (Error Err = |
| 7269 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 7270 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7271 | ResInfo = &ToTAInfo; |
| 7272 | } |
| 7273 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7274 | Expr *ToBase = nullptr; |
| 7275 | if (!E->isImplicitAccess()) { |
| 7276 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7277 | ToBase = *ToBaseOrErr; |
| 7278 | else |
| 7279 | return ToBaseOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7280 | } |
| 7281 | |
| 7282 | return UnresolvedMemberExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7283 | Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType, |
| 7284 | E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7285 | ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end()); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7286 | } |
| 7287 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7288 | ExpectedStmt ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| 7289 | auto Imp = importSeq(E->getCallee(), E->getType(), E->getRParenLoc()); |
| 7290 | if (!Imp) |
| 7291 | return Imp.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7292 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7293 | Expr *ToCallee; |
| 7294 | QualType ToType; |
| 7295 | SourceLocation ToRParenLoc; |
| 7296 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7297 | |
| 7298 | unsigned NumArgs = E->getNumArgs(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7299 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); |
| 7300 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7301 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7302 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7303 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { |
Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7304 | return CXXOperatorCallExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7305 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType, |
Eric Fiselier | 5cdc2cd | 2018-12-12 21:50:55 +0000 | [diff] [blame] | 7306 | OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(), |
| 7307 | OCE->getADLCallKind()); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7308 | } |
| 7309 | |
Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7310 | return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType, |
| 7311 | E->getValueKind(), ToRParenLoc, /*MinNumArgs=*/0, |
| 7312 | E->getADLCallKind()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7313 | } |
| 7314 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7315 | ExpectedStmt ASTNodeImporter::VisitLambdaExpr(LambdaExpr *E) { |
| 7316 | CXXRecordDecl *FromClass = E->getLambdaClass(); |
| 7317 | auto ToClassOrErr = import(FromClass); |
| 7318 | if (!ToClassOrErr) |
| 7319 | return ToClassOrErr.takeError(); |
| 7320 | CXXRecordDecl *ToClass = *ToClassOrErr; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7321 | |
| 7322 | // NOTE: lambda classes are created with BeingDefined flag set up. |
| 7323 | // It means that ImportDefinition doesn't work for them and we should fill it |
| 7324 | // manually. |
Gabor Marton | 302f300 | 2019-02-15 12:04:05 +0000 | [diff] [blame] | 7325 | if (ToClass->isBeingDefined()) |
| 7326 | if (Error Err = ImportDeclContext(FromClass, /*ForceImport = */ true)) |
| 7327 | return std::move(Err); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7328 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7329 | auto ToCallOpOrErr = import(E->getCallOperator()); |
| 7330 | if (!ToCallOpOrErr) |
| 7331 | return ToCallOpOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7332 | |
| 7333 | ToClass->completeDefinition(); |
| 7334 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7335 | SmallVector<LambdaCapture, 8> ToCaptures; |
| 7336 | ToCaptures.reserve(E->capture_size()); |
| 7337 | for (const auto &FromCapture : E->captures()) { |
| 7338 | if (auto ToCaptureOrErr = import(FromCapture)) |
| 7339 | ToCaptures.push_back(*ToCaptureOrErr); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7340 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7341 | return ToCaptureOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7342 | } |
| 7343 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7344 | SmallVector<Expr *, 8> ToCaptureInits(E->capture_size()); |
| 7345 | if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits)) |
| 7346 | return std::move(Err); |
| 7347 | |
| 7348 | auto Imp = importSeq( |
| 7349 | E->getIntroducerRange(), E->getCaptureDefaultLoc(), E->getEndLoc()); |
| 7350 | if (!Imp) |
| 7351 | return Imp.takeError(); |
| 7352 | |
| 7353 | SourceRange ToIntroducerRange; |
| 7354 | SourceLocation ToCaptureDefaultLoc, ToEndLoc; |
| 7355 | std::tie(ToIntroducerRange, ToCaptureDefaultLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7356 | |
Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 7357 | return LambdaExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7358 | Importer.getToContext(), ToClass, ToIntroducerRange, |
| 7359 | E->getCaptureDefault(), ToCaptureDefaultLoc, ToCaptures, |
| 7360 | E->hasExplicitParameters(), E->hasExplicitResultType(), ToCaptureInits, |
| 7361 | ToEndLoc, E->containsUnexpandedParameterPack()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7362 | } |
| 7363 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7364 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7365 | ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) { |
| 7366 | auto Imp = importSeq(E->getLBraceLoc(), E->getRBraceLoc(), E->getType()); |
| 7367 | if (!Imp) |
| 7368 | return Imp.takeError(); |
| 7369 | |
| 7370 | SourceLocation ToLBraceLoc, ToRBraceLoc; |
| 7371 | QualType ToType; |
| 7372 | std::tie(ToLBraceLoc, ToRBraceLoc, ToType) = *Imp; |
| 7373 | |
| 7374 | SmallVector<Expr *, 4> ToExprs(E->getNumInits()); |
| 7375 | if (Error Err = ImportContainerChecked(E->inits(), ToExprs)) |
| 7376 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7377 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7378 | ASTContext &ToCtx = Importer.getToContext(); |
| 7379 | InitListExpr *To = new (ToCtx) InitListExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7380 | ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc); |
| 7381 | To->setType(ToType); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7382 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7383 | if (E->hasArrayFiller()) { |
| 7384 | if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller())) |
| 7385 | To->setArrayFiller(*ToFillerOrErr); |
| 7386 | else |
| 7387 | return ToFillerOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7388 | } |
| 7389 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7390 | if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) { |
| 7391 | if (auto ToFDOrErr = import(FromFD)) |
| 7392 | To->setInitializedFieldInUnion(*ToFDOrErr); |
| 7393 | else |
| 7394 | return ToFDOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7395 | } |
| 7396 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7397 | if (InitListExpr *SyntForm = E->getSyntacticForm()) { |
| 7398 | if (auto ToSyntFormOrErr = import(SyntForm)) |
| 7399 | To->setSyntacticForm(*ToSyntFormOrErr); |
| 7400 | else |
| 7401 | return ToSyntFormOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7402 | } |
| 7403 | |
Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7404 | // Copy InitListExprBitfields, which are not handled in the ctor of |
| 7405 | // InitListExpr. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7406 | To->sawArrayRangeDesignator(E->hadArrayRangeDesignator()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7407 | |
| 7408 | return To; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7409 | } |
| 7410 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7411 | ExpectedStmt ASTNodeImporter::VisitCXXStdInitializerListExpr( |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7412 | CXXStdInitializerListExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7413 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7414 | if (!ToTypeOrErr) |
| 7415 | return ToTypeOrErr.takeError(); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7416 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7417 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7418 | if (!ToSubExprOrErr) |
| 7419 | return ToSubExprOrErr.takeError(); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7420 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7421 | return new (Importer.getToContext()) CXXStdInitializerListExpr( |
| 7422 | *ToTypeOrErr, *ToSubExprOrErr); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7423 | } |
| 7424 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7425 | ExpectedStmt ASTNodeImporter::VisitCXXInheritedCtorInitExpr( |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7426 | CXXInheritedCtorInitExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7427 | auto Imp = importSeq(E->getLocation(), E->getType(), E->getConstructor()); |
| 7428 | if (!Imp) |
| 7429 | return Imp.takeError(); |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7430 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7431 | SourceLocation ToLocation; |
| 7432 | QualType ToType; |
| 7433 | CXXConstructorDecl *ToConstructor; |
| 7434 | std::tie(ToLocation, ToType, ToConstructor) = *Imp; |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7435 | |
| 7436 | return new (Importer.getToContext()) CXXInheritedCtorInitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7437 | ToLocation, ToType, ToConstructor, E->constructsVBase(), |
| 7438 | E->inheritedFromVBase()); |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7439 | } |
| 7440 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7441 | ExpectedStmt ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 7442 | auto Imp = importSeq(E->getType(), E->getCommonExpr(), E->getSubExpr()); |
| 7443 | if (!Imp) |
| 7444 | return Imp.takeError(); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7445 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7446 | QualType ToType; |
| 7447 | Expr *ToCommonExpr, *ToSubExpr; |
| 7448 | std::tie(ToType, ToCommonExpr, ToSubExpr) = *Imp; |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7449 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7450 | return new (Importer.getToContext()) ArrayInitLoopExpr( |
| 7451 | ToType, ToCommonExpr, ToSubExpr); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7452 | } |
| 7453 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7454 | ExpectedStmt ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 7455 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7456 | if (!ToTypeOrErr) |
| 7457 | return ToTypeOrErr.takeError(); |
| 7458 | return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7459 | } |
| 7460 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7461 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 7462 | ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc()); |
| 7463 | if (!ToBeginLocOrErr) |
| 7464 | return ToBeginLocOrErr.takeError(); |
| 7465 | |
| 7466 | auto ToFieldOrErr = import(E->getField()); |
| 7467 | if (!ToFieldOrErr) |
| 7468 | return ToFieldOrErr.takeError(); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7469 | |
| 7470 | return CXXDefaultInitExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7471 | Importer.getToContext(), *ToBeginLocOrErr, *ToFieldOrErr); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7472 | } |
| 7473 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7474 | ExpectedStmt ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 7475 | auto Imp = importSeq( |
| 7476 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten(), |
| 7477 | E->getOperatorLoc(), E->getRParenLoc(), E->getAngleBrackets()); |
| 7478 | if (!Imp) |
| 7479 | return Imp.takeError(); |
| 7480 | |
| 7481 | QualType ToType; |
| 7482 | Expr *ToSubExpr; |
| 7483 | TypeSourceInfo *ToTypeInfoAsWritten; |
| 7484 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 7485 | SourceRange ToAngleBrackets; |
| 7486 | std::tie( |
| 7487 | ToType, ToSubExpr, ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, |
| 7488 | ToAngleBrackets) = *Imp; |
| 7489 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7490 | ExprValueKind VK = E->getValueKind(); |
| 7491 | CastKind CK = E->getCastKind(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7492 | auto ToBasePathOrErr = ImportCastPath(E); |
| 7493 | if (!ToBasePathOrErr) |
| 7494 | return ToBasePathOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7495 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7496 | if (isa<CXXStaticCastExpr>(E)) { |
| 7497 | return CXXStaticCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7498 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7499 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7500 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 7501 | return CXXDynamicCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7502 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7503 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7504 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 7505 | return CXXReinterpretCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7506 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7507 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Raphael Isemann | c705bb8 | 2018-08-20 16:20:01 +0000 | [diff] [blame] | 7508 | } else if (isa<CXXConstCastExpr>(E)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7509 | return CXXConstCastExpr::Create( |
| 7510 | Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten, |
| 7511 | ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7512 | } else { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7513 | llvm_unreachable("Unknown cast type"); |
| 7514 | return make_error<ImportError>(); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7515 | } |
| 7516 | } |
| 7517 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7518 | ExpectedStmt ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7519 | SubstNonTypeTemplateParmExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7520 | auto Imp = importSeq( |
| 7521 | E->getType(), E->getExprLoc(), E->getParameter(), E->getReplacement()); |
| 7522 | if (!Imp) |
| 7523 | return Imp.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7524 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7525 | QualType ToType; |
| 7526 | SourceLocation ToExprLoc; |
| 7527 | NonTypeTemplateParmDecl *ToParameter; |
| 7528 | Expr *ToReplacement; |
| 7529 | std::tie(ToType, ToExprLoc, ToParameter, ToReplacement) = *Imp; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7530 | |
| 7531 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7532 | ToType, E->getValueKind(), ToExprLoc, ToParameter, ToReplacement); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7533 | } |
| 7534 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7535 | ExpectedStmt ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { |
| 7536 | auto Imp = importSeq( |
| 7537 | E->getType(), E->getBeginLoc(), E->getEndLoc()); |
| 7538 | if (!Imp) |
| 7539 | return Imp.takeError(); |
| 7540 | |
| 7541 | QualType ToType; |
| 7542 | SourceLocation ToBeginLoc, ToEndLoc; |
| 7543 | std::tie(ToType, ToBeginLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7544 | |
| 7545 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7546 | if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs)) |
| 7547 | return std::move(Err); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7548 | |
| 7549 | // According to Sema::BuildTypeTrait(), if E is value-dependent, |
| 7550 | // Value is always false. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7551 | bool ToValue = (E->isValueDependent() ? false : E->getValue()); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7552 | |
| 7553 | return TypeTraitExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7554 | Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs, |
| 7555 | ToEndLoc, ToValue); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7556 | } |
| 7557 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7558 | ExpectedStmt ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { |
| 7559 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7560 | if (!ToTypeOrErr) |
| 7561 | return ToTypeOrErr.takeError(); |
| 7562 | |
| 7563 | auto ToSourceRangeOrErr = import(E->getSourceRange()); |
| 7564 | if (!ToSourceRangeOrErr) |
| 7565 | return ToSourceRangeOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7566 | |
| 7567 | if (E->isTypeOperand()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7568 | if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo())) |
| 7569 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7570 | *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr); |
| 7571 | else |
| 7572 | return ToTSIOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7573 | } |
| 7574 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7575 | ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand()); |
| 7576 | if (!ToExprOperandOrErr) |
| 7577 | return ToExprOperandOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7578 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7579 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7580 | *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7581 | } |
| 7582 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7583 | void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod, |
| 7584 | CXXMethodDecl *FromMethod) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7585 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) { |
| 7586 | if (auto ImportedOrErr = import(FromOverriddenMethod)) |
| 7587 | ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>( |
| 7588 | (*ImportedOrErr)->getCanonicalDecl())); |
| 7589 | else |
| 7590 | consumeError(ImportedOrErr.takeError()); |
| 7591 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7592 | } |
| 7593 | |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7594 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7595 | ASTContext &FromContext, FileManager &FromFileManager, |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7596 | bool MinimalImport, |
| 7597 | ASTImporterLookupTable *LookupTable) |
| 7598 | : LookupTable(LookupTable), ToContext(ToContext), FromContext(FromContext), |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7599 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
| 7600 | Minimal(MinimalImport) { |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7601 | |
| 7602 | ImportedDecls[FromContext.getTranslationUnitDecl()] = |
| 7603 | ToContext.getTranslationUnitDecl(); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7604 | } |
| 7605 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7606 | ASTImporter::~ASTImporter() = default; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7607 | |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7608 | Optional<unsigned> ASTImporter::getFieldIndex(Decl *F) { |
| 7609 | assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) && |
| 7610 | "Try to get field index for non-field."); |
| 7611 | |
| 7612 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); |
| 7613 | if (!Owner) |
| 7614 | return None; |
| 7615 | |
| 7616 | unsigned Index = 0; |
| 7617 | for (const auto *D : Owner->decls()) { |
| 7618 | if (D == F) |
| 7619 | return Index; |
| 7620 | |
| 7621 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) |
| 7622 | ++Index; |
| 7623 | } |
| 7624 | |
| 7625 | llvm_unreachable("Field was not found in its parent context."); |
| 7626 | |
| 7627 | return None; |
| 7628 | } |
| 7629 | |
| 7630 | ASTImporter::FoundDeclsTy |
| 7631 | ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) { |
| 7632 | // We search in the redecl context because of transparent contexts. |
| 7633 | // E.g. a simple C language enum is a transparent context: |
| 7634 | // enum E { A, B }; |
| 7635 | // Now if we had a global variable in the TU |
| 7636 | // int A; |
| 7637 | // then the enum constant 'A' and the variable 'A' violates ODR. |
| 7638 | // We can diagnose this only if we search in the redecl context. |
| 7639 | DeclContext *ReDC = DC->getRedeclContext(); |
| 7640 | if (LookupTable) { |
| 7641 | ASTImporterLookupTable::LookupResult LookupResult = |
| 7642 | LookupTable->lookup(ReDC, Name); |
| 7643 | return FoundDeclsTy(LookupResult.begin(), LookupResult.end()); |
| 7644 | } else { |
| 7645 | // FIXME Can we remove this kind of lookup? |
| 7646 | // Or lldb really needs this C/C++ lookup? |
| 7647 | FoundDeclsTy Result; |
| 7648 | ReDC->localUncachedLookup(Name, Result); |
| 7649 | return Result; |
| 7650 | } |
| 7651 | } |
| 7652 | |
| 7653 | void ASTImporter::AddToLookupTable(Decl *ToD) { |
| 7654 | if (LookupTable) |
| 7655 | if (auto *ToND = dyn_cast<NamedDecl>(ToD)) |
| 7656 | LookupTable->add(ToND); |
| 7657 | } |
| 7658 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7659 | Expected<QualType> ASTImporter::Import_New(QualType FromT) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7660 | if (FromT.isNull()) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7661 | return QualType{}; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7662 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7663 | const Type *FromTy = FromT.getTypePtr(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7664 | |
| 7665 | // Check whether we've already imported this type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7666 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7667 | = ImportedTypes.find(FromTy); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7668 | if (Pos != ImportedTypes.end()) |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7669 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7670 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7671 | // Import the type |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7672 | ASTNodeImporter Importer(*this); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7673 | ExpectedType ToTOrErr = Importer.Visit(FromTy); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7674 | if (!ToTOrErr) |
| 7675 | return ToTOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7676 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7677 | // Record the imported type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7678 | ImportedTypes[FromTy] = (*ToTOrErr).getTypePtr(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7679 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7680 | return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7681 | } |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7682 | QualType ASTImporter::Import(QualType From) { |
| 7683 | llvm::Expected<QualType> To = Import_New(From); |
| 7684 | if (To) |
| 7685 | return *To; |
| 7686 | else |
| 7687 | llvm::consumeError(To.takeError()); |
| 7688 | return {}; |
| 7689 | } |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7690 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7691 | Expected<TypeSourceInfo *> ASTImporter::Import_New(TypeSourceInfo *FromTSI) { |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7692 | if (!FromTSI) |
| 7693 | return FromTSI; |
| 7694 | |
| 7695 | // FIXME: For now we just create a "trivial" type source info based |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 7696 | // on the type and a single location. Implement a real version of this. |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7697 | ExpectedType TOrErr = Import_New(FromTSI->getType()); |
| 7698 | if (!TOrErr) |
| 7699 | return TOrErr.takeError(); |
| 7700 | ExpectedSLoc BeginLocOrErr = Import_New(FromTSI->getTypeLoc().getBeginLoc()); |
| 7701 | if (!BeginLocOrErr) |
| 7702 | return BeginLocOrErr.takeError(); |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7703 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7704 | return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr); |
| 7705 | } |
| 7706 | TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *From) { |
| 7707 | llvm::Expected<TypeSourceInfo *> To = Import_New(From); |
| 7708 | if (To) |
| 7709 | return *To; |
| 7710 | else |
| 7711 | llvm::consumeError(To.takeError()); |
| 7712 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7713 | } |
| 7714 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7715 | Expected<Attr *> ASTImporter::Import_New(const Attr *FromAttr) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7716 | Attr *ToAttr = FromAttr->clone(ToContext); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7717 | if (auto ToRangeOrErr = Import_New(FromAttr->getRange())) |
| 7718 | ToAttr->setRange(*ToRangeOrErr); |
| 7719 | else |
| 7720 | return ToRangeOrErr.takeError(); |
| 7721 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7722 | return ToAttr; |
Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 7723 | } |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7724 | Attr *ASTImporter::Import(const Attr *From) { |
| 7725 | llvm::Expected<Attr *> To = Import_New(From); |
| 7726 | if (To) |
| 7727 | return *To; |
| 7728 | else |
| 7729 | llvm::consumeError(To.takeError()); |
| 7730 | return nullptr; |
| 7731 | } |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 7732 | |
Gabor Marton | be77a98 | 2018-12-12 11:22:55 +0000 | [diff] [blame] | 7733 | Decl *ASTImporter::GetAlreadyImportedOrNull(const Decl *FromD) const { |
| 7734 | auto Pos = ImportedDecls.find(FromD); |
| 7735 | if (Pos != ImportedDecls.end()) |
| 7736 | return Pos->second; |
| 7737 | else |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7738 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7739 | } |
| 7740 | |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 7741 | TranslationUnitDecl *ASTImporter::GetFromTU(Decl *ToD) { |
| 7742 | auto FromDPos = ImportedFromDecls.find(ToD); |
| 7743 | if (FromDPos == ImportedFromDecls.end()) |
| 7744 | return nullptr; |
| 7745 | return FromDPos->second->getTranslationUnitDecl(); |
| 7746 | } |
| 7747 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7748 | Expected<Decl *> ASTImporter::Import_New(Decl *FromD) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7749 | if (!FromD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7750 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7751 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7752 | ASTNodeImporter Importer(*this); |
| 7753 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7754 | // Check whether we've already imported this declaration. |
| 7755 | Decl *ToD = GetAlreadyImportedOrNull(FromD); |
| 7756 | if (ToD) { |
| 7757 | // If FromD has some updated flags after last import, apply it |
| 7758 | updateFlags(FromD, ToD); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7759 | return ToD; |
| 7760 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7761 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7762 | // Import the declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7763 | ExpectedDecl ToDOrErr = Importer.Visit(FromD); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7764 | if (!ToDOrErr) |
| 7765 | return ToDOrErr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7766 | ToD = *ToDOrErr; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7767 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 7768 | // FIXME Use getImportDeclErrorIfAny() here (and return with the error) once |
| 7769 | // the error handling is finished in GetImportedOrCreateSpecialDecl(). |
| 7770 | if (!ToD) { |
| 7771 | return nullptr; |
| 7772 | } |
| 7773 | |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7774 | // Once the decl is connected to the existing declarations, i.e. when the |
| 7775 | // redecl chain is properly set then we populate the lookup again. |
| 7776 | // This way the primary context will be able to find all decls. |
| 7777 | AddToLookupTable(ToD); |
| 7778 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7779 | // Notify subclasses. |
| 7780 | Imported(FromD, ToD); |
| 7781 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 7782 | updateFlags(FromD, ToD); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7783 | return ToDOrErr; |
| 7784 | } |
| 7785 | Decl *ASTImporter::Import(Decl *From) { |
| 7786 | llvm::Expected<Decl *> To = Import_New(From); |
| 7787 | if (To) |
| 7788 | return *To; |
| 7789 | else |
| 7790 | llvm::consumeError(To.takeError()); |
| 7791 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7792 | } |
| 7793 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7794 | Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7795 | if (!FromDC) |
| 7796 | return FromDC; |
| 7797 | |
Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 7798 | ExpectedDecl ToDCOrErr = Import_New(cast<Decl>(FromDC)); |
| 7799 | if (!ToDCOrErr) |
| 7800 | return ToDCOrErr.takeError(); |
| 7801 | auto *ToDC = cast<DeclContext>(*ToDCOrErr); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7802 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7803 | // 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] | 7804 | // need it to have a definition. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7805 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
| 7806 | auto *FromRecord = cast<RecordDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7807 | if (ToRecord->isCompleteDefinition()) { |
| 7808 | // Do nothing. |
| 7809 | } else if (FromRecord->isCompleteDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7810 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7811 | FromRecord, ToRecord, ASTNodeImporter::IDK_Basic)) |
| 7812 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7813 | } else { |
| 7814 | CompleteDecl(ToRecord); |
| 7815 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7816 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 7817 | auto *FromEnum = cast<EnumDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7818 | if (ToEnum->isCompleteDefinition()) { |
| 7819 | // Do nothing. |
| 7820 | } else if (FromEnum->isCompleteDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7821 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7822 | FromEnum, ToEnum, ASTNodeImporter::IDK_Basic)) |
| 7823 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7824 | } else { |
| 7825 | CompleteDecl(ToEnum); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7826 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7827 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 7828 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7829 | if (ToClass->getDefinition()) { |
| 7830 | // Do nothing. |
| 7831 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7832 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7833 | FromDef, ToClass, ASTNodeImporter::IDK_Basic)) |
| 7834 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7835 | } else { |
| 7836 | CompleteDecl(ToClass); |
| 7837 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7838 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 7839 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7840 | if (ToProto->getDefinition()) { |
| 7841 | // Do nothing. |
| 7842 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7843 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7844 | FromDef, ToProto, ASTNodeImporter::IDK_Basic)) |
| 7845 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7846 | } else { |
| 7847 | CompleteDecl(ToProto); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7848 | } |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7849 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7850 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7851 | return ToDC; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7852 | } |
| 7853 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7854 | Expected<Expr *> ASTImporter::Import_New(Expr *FromE) { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7855 | if (ExpectedStmt ToSOrErr = Import_New(cast_or_null<Stmt>(FromE))) |
| 7856 | return cast_or_null<Expr>(*ToSOrErr); |
| 7857 | else |
| 7858 | return ToSOrErr.takeError(); |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7859 | } |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7860 | Expr *ASTImporter::Import(Expr *From) { |
| 7861 | llvm::Expected<Expr *> To = Import_New(From); |
| 7862 | if (To) |
| 7863 | return *To; |
| 7864 | else |
| 7865 | llvm::consumeError(To.takeError()); |
| 7866 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7867 | } |
| 7868 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7869 | Expected<Stmt *> ASTImporter::Import_New(Stmt *FromS) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7870 | if (!FromS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7871 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7872 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7873 | // Check whether we've already imported this statement. |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7874 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 7875 | if (Pos != ImportedStmts.end()) |
| 7876 | return Pos->second; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7877 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7878 | // Import the statement. |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7879 | ASTNodeImporter Importer(*this); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7880 | ExpectedStmt ToSOrErr = Importer.Visit(FromS); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7881 | if (!ToSOrErr) |
| 7882 | return ToSOrErr; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7883 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7884 | if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) { |
Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7885 | auto *FromE = cast<Expr>(FromS); |
| 7886 | // Copy ExprBitfields, which may not be handled in Expr subclasses |
| 7887 | // constructors. |
| 7888 | ToE->setValueKind(FromE->getValueKind()); |
| 7889 | ToE->setObjectKind(FromE->getObjectKind()); |
| 7890 | ToE->setTypeDependent(FromE->isTypeDependent()); |
| 7891 | ToE->setValueDependent(FromE->isValueDependent()); |
| 7892 | ToE->setInstantiationDependent(FromE->isInstantiationDependent()); |
| 7893 | ToE->setContainsUnexpandedParameterPack( |
| 7894 | FromE->containsUnexpandedParameterPack()); |
| 7895 | } |
| 7896 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7897 | // Record the imported statement object. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7898 | ImportedStmts[FromS] = *ToSOrErr; |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7899 | return ToSOrErr; |
| 7900 | } |
| 7901 | Stmt *ASTImporter::Import(Stmt *From) { |
| 7902 | llvm::Expected<Stmt *> To = Import_New(From); |
| 7903 | if (To) |
| 7904 | return *To; |
| 7905 | else |
| 7906 | llvm::consumeError(To.takeError()); |
| 7907 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7908 | } |
| 7909 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7910 | Expected<NestedNameSpecifier *> |
| 7911 | ASTImporter::Import_New(NestedNameSpecifier *FromNNS) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7912 | if (!FromNNS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7913 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7914 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7915 | NestedNameSpecifier *Prefix; |
| 7916 | if (Error Err = importInto(Prefix, FromNNS->getPrefix())) |
| 7917 | return std::move(Err); |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7918 | |
| 7919 | switch (FromNNS->getKind()) { |
| 7920 | case NestedNameSpecifier::Identifier: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7921 | assert(FromNNS->getAsIdentifier() && "NNS should contain identifier."); |
| 7922 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 7923 | Import(FromNNS->getAsIdentifier())); |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7924 | |
| 7925 | case NestedNameSpecifier::Namespace: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7926 | if (ExpectedDecl NSOrErr = Import_New(FromNNS->getAsNamespace())) { |
| 7927 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 7928 | cast<NamespaceDecl>(*NSOrErr)); |
| 7929 | } else |
| 7930 | return NSOrErr.takeError(); |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7931 | |
| 7932 | case NestedNameSpecifier::NamespaceAlias: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7933 | if (ExpectedDecl NSADOrErr = Import_New(FromNNS->getAsNamespaceAlias())) |
| 7934 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 7935 | cast<NamespaceAliasDecl>(*NSADOrErr)); |
| 7936 | else |
| 7937 | return NSADOrErr.takeError(); |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7938 | |
| 7939 | case NestedNameSpecifier::Global: |
| 7940 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 7941 | |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7942 | case NestedNameSpecifier::Super: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7943 | if (ExpectedDecl RDOrErr = Import_New(FromNNS->getAsRecordDecl())) |
| 7944 | return NestedNameSpecifier::SuperSpecifier(ToContext, |
| 7945 | cast<CXXRecordDecl>(*RDOrErr)); |
| 7946 | else |
| 7947 | return RDOrErr.takeError(); |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7948 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7949 | case NestedNameSpecifier::TypeSpec: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7950 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 7951 | if (Expected<QualType> TyOrErr = |
| 7952 | Import_New(QualType(FromNNS->getAsType(), 0u))) { |
| 7953 | bool TSTemplate = |
| 7954 | FromNNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate; |
| 7955 | return NestedNameSpecifier::Create(ToContext, Prefix, TSTemplate, |
| 7956 | TyOrErr->getTypePtr()); |
| 7957 | } else { |
| 7958 | return TyOrErr.takeError(); |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7959 | } |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7960 | } |
| 7961 | |
| 7962 | llvm_unreachable("Invalid nested name specifier kind"); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7963 | } |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7964 | NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *From) { |
| 7965 | llvm::Expected<NestedNameSpecifier *> To = Import_New(From); |
| 7966 | if (To) |
| 7967 | return *To; |
| 7968 | else |
| 7969 | llvm::consumeError(To.takeError()); |
| 7970 | return nullptr; |
| 7971 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7972 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7973 | Expected<NestedNameSpecifierLoc> |
| 7974 | ASTImporter::Import_New(NestedNameSpecifierLoc FromNNS) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7975 | // Copied from NestedNameSpecifier mostly. |
| 7976 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 7977 | NestedNameSpecifierLoc NNS = FromNNS; |
| 7978 | |
| 7979 | // Push each of the nested-name-specifiers's onto a stack for |
| 7980 | // serialization in reverse order. |
| 7981 | while (NNS) { |
| 7982 | NestedNames.push_back(NNS); |
| 7983 | NNS = NNS.getPrefix(); |
| 7984 | } |
| 7985 | |
| 7986 | NestedNameSpecifierLocBuilder Builder; |
| 7987 | |
| 7988 | while (!NestedNames.empty()) { |
| 7989 | NNS = NestedNames.pop_back_val(); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7990 | NestedNameSpecifier *Spec; |
| 7991 | if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier())) |
| 7992 | return std::move(Err); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7993 | |
| 7994 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7995 | |
| 7996 | SourceLocation ToLocalBeginLoc, ToLocalEndLoc; |
| 7997 | if (Kind != NestedNameSpecifier::Super) { |
| 7998 | if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc())) |
| 7999 | return std::move(Err); |
| 8000 | |
| 8001 | if (Kind != NestedNameSpecifier::Global) |
| 8002 | if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc())) |
| 8003 | return std::move(Err); |
| 8004 | } |
| 8005 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8006 | switch (Kind) { |
| 8007 | case NestedNameSpecifier::Identifier: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8008 | Builder.Extend(getToContext(), Spec->getAsIdentifier(), ToLocalBeginLoc, |
| 8009 | ToLocalEndLoc); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8010 | break; |
| 8011 | |
| 8012 | case NestedNameSpecifier::Namespace: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8013 | Builder.Extend(getToContext(), Spec->getAsNamespace(), ToLocalBeginLoc, |
| 8014 | ToLocalEndLoc); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8015 | break; |
| 8016 | |
| 8017 | case NestedNameSpecifier::NamespaceAlias: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8018 | Builder.Extend(getToContext(), Spec->getAsNamespaceAlias(), |
| 8019 | ToLocalBeginLoc, ToLocalEndLoc); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8020 | break; |
| 8021 | |
| 8022 | case NestedNameSpecifier::TypeSpec: |
| 8023 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Balazs Keri | 5f4fd8b | 2019-03-14 14:20:23 +0000 | [diff] [blame] | 8024 | SourceLocation ToTLoc; |
| 8025 | if (Error Err = importInto(ToTLoc, NNS.getTypeLoc().getBeginLoc())) |
| 8026 | return std::move(Err); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8027 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
Balazs Keri | 5f4fd8b | 2019-03-14 14:20:23 +0000 | [diff] [blame] | 8028 | QualType(Spec->getAsType(), 0), ToTLoc); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8029 | Builder.Extend(getToContext(), ToLocalBeginLoc, TSI->getTypeLoc(), |
| 8030 | ToLocalEndLoc); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8031 | break; |
| 8032 | } |
| 8033 | |
| 8034 | case NestedNameSpecifier::Global: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8035 | Builder.MakeGlobal(getToContext(), ToLocalBeginLoc); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8036 | break; |
| 8037 | |
| 8038 | case NestedNameSpecifier::Super: { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8039 | auto ToSourceRangeOrErr = Import_New(NNS.getSourceRange()); |
| 8040 | if (!ToSourceRangeOrErr) |
| 8041 | return ToSourceRangeOrErr.takeError(); |
| 8042 | |
| 8043 | Builder.MakeSuper(getToContext(), Spec->getAsRecordDecl(), |
| 8044 | ToSourceRangeOrErr->getBegin(), |
| 8045 | ToSourceRangeOrErr->getEnd()); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8046 | } |
| 8047 | } |
| 8048 | } |
| 8049 | |
| 8050 | return Builder.getWithLocInContext(getToContext()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 8051 | } |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8052 | NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc From) { |
| 8053 | llvm::Expected<NestedNameSpecifierLoc> To = Import_New(From); |
| 8054 | if (To) |
| 8055 | return *To; |
| 8056 | else |
| 8057 | llvm::consumeError(To.takeError()); |
| 8058 | return {}; |
| 8059 | } |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 8060 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8061 | Expected<TemplateName> ASTImporter::Import_New(TemplateName From) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8062 | switch (From.getKind()) { |
| 8063 | case TemplateName::Template: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8064 | if (ExpectedDecl ToTemplateOrErr = Import_New(From.getAsTemplateDecl())) |
| 8065 | return TemplateName(cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8066 | else |
| 8067 | return ToTemplateOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8068 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8069 | case TemplateName::OverloadedTemplate: { |
| 8070 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 8071 | UnresolvedSet<2> ToTemplates; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8072 | for (auto *I : *FromStorage) { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8073 | if (auto ToOrErr = Import_New(I)) |
| 8074 | ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr)); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8075 | else |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8076 | return ToOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8077 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8078 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8079 | ToTemplates.end()); |
| 8080 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8081 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8082 | case TemplateName::QualifiedTemplate: { |
| 8083 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8084 | auto QualifierOrErr = Import_New(QTN->getQualifier()); |
| 8085 | if (!QualifierOrErr) |
| 8086 | return QualifierOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8087 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8088 | if (ExpectedDecl ToTemplateOrErr = Import_New(From.getAsTemplateDecl())) |
| 8089 | return ToContext.getQualifiedTemplateName( |
| 8090 | *QualifierOrErr, QTN->hasTemplateKeyword(), |
| 8091 | cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8092 | else |
| 8093 | return ToTemplateOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8094 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8095 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8096 | case TemplateName::DependentTemplate: { |
| 8097 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8098 | auto QualifierOrErr = Import_New(DTN->getQualifier()); |
| 8099 | if (!QualifierOrErr) |
| 8100 | return QualifierOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8101 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8102 | if (DTN->isIdentifier()) { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8103 | return ToContext.getDependentTemplateName(*QualifierOrErr, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8104 | Import(DTN->getIdentifier())); |
| 8105 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8106 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8107 | return ToContext.getDependentTemplateName(*QualifierOrErr, |
| 8108 | DTN->getOperator()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8109 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8110 | |
| 8111 | case TemplateName::SubstTemplateTemplateParm: { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8112 | SubstTemplateTemplateParmStorage *Subst = |
| 8113 | From.getAsSubstTemplateTemplateParm(); |
| 8114 | ExpectedDecl ParamOrErr = Import_New(Subst->getParameter()); |
| 8115 | if (!ParamOrErr) |
| 8116 | return ParamOrErr.takeError(); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8117 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8118 | auto ReplacementOrErr = Import_New(Subst->getReplacement()); |
| 8119 | if (!ReplacementOrErr) |
| 8120 | return ReplacementOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8121 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8122 | return ToContext.getSubstTemplateTemplateParm( |
| 8123 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ReplacementOrErr); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8124 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8125 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8126 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 8127 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 8128 | = From.getAsSubstTemplateTemplateParmPack(); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8129 | ExpectedDecl ParamOrErr = Import_New(SubstPack->getParameterPack()); |
| 8130 | if (!ParamOrErr) |
| 8131 | return ParamOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8132 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8133 | ASTNodeImporter Importer(*this); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8134 | auto ArgPackOrErr = |
| 8135 | Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
| 8136 | if (!ArgPackOrErr) |
| 8137 | return ArgPackOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8138 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8139 | return ToContext.getSubstTemplateTemplateParmPack( |
| 8140 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ArgPackOrErr); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8141 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8142 | } |
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 | llvm_unreachable("Invalid template name kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8145 | } |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8146 | TemplateName ASTImporter::Import(TemplateName From) { |
| 8147 | llvm::Expected<TemplateName> To = Import_New(From); |
| 8148 | if (To) |
| 8149 | return *To; |
| 8150 | else |
| 8151 | llvm::consumeError(To.takeError()); |
| 8152 | return {}; |
| 8153 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8154 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8155 | Expected<SourceLocation> ASTImporter::Import_New(SourceLocation FromLoc) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8156 | if (FromLoc.isInvalid()) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8157 | return SourceLocation{}; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8158 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8159 | SourceManager &FromSM = FromContext.getSourceManager(); |
Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8160 | bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8161 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8162 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8163 | Expected<FileID> ToFileIDOrErr = Import_New(Decomposed.first, IsBuiltin); |
| 8164 | if (!ToFileIDOrErr) |
| 8165 | return ToFileIDOrErr.takeError(); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8166 | SourceManager &ToSM = ToContext.getSourceManager(); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8167 | return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second); |
| 8168 | } |
| 8169 | SourceLocation ASTImporter::Import(SourceLocation From) { |
| 8170 | llvm::Expected<SourceLocation> To = Import_New(From); |
| 8171 | if (To) |
| 8172 | return *To; |
| 8173 | else |
| 8174 | llvm::consumeError(To.takeError()); |
| 8175 | return {}; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8176 | } |
| 8177 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8178 | Expected<SourceRange> ASTImporter::Import_New(SourceRange FromRange) { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8179 | SourceLocation ToBegin, ToEnd; |
| 8180 | if (Error Err = importInto(ToBegin, FromRange.getBegin())) |
| 8181 | return std::move(Err); |
| 8182 | if (Error Err = importInto(ToEnd, FromRange.getEnd())) |
| 8183 | return std::move(Err); |
| 8184 | |
| 8185 | return SourceRange(ToBegin, ToEnd); |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8186 | } |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8187 | SourceRange ASTImporter::Import(SourceRange From) { |
| 8188 | llvm::Expected<SourceRange> To = Import_New(From); |
| 8189 | if (To) |
| 8190 | return *To; |
| 8191 | else |
| 8192 | llvm::consumeError(To.takeError()); |
| 8193 | return {}; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8194 | } |
| 8195 | |
Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8196 | Expected<FileID> ASTImporter::Import_New(FileID FromID, bool IsBuiltin) { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8197 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8198 | if (Pos != ImportedFileIDs.end()) |
| 8199 | return Pos->second; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8200 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8201 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 8202 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 8203 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8204 | |
| 8205 | // Map the FromID to the "to" source manager. |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8206 | FileID ToID; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8207 | if (FromSLoc.isExpansion()) { |
| 8208 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8209 | ExpectedSLoc ToSpLoc = Import_New(FromEx.getSpellingLoc()); |
| 8210 | if (!ToSpLoc) |
| 8211 | return ToSpLoc.takeError(); |
| 8212 | ExpectedSLoc ToExLocS = Import_New(FromEx.getExpansionLocStart()); |
| 8213 | if (!ToExLocS) |
| 8214 | return ToExLocS.takeError(); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8215 | unsigned TokenLen = FromSM.getFileIDSize(FromID); |
| 8216 | SourceLocation MLoc; |
| 8217 | if (FromEx.isMacroArgExpansion()) { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8218 | MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, TokenLen); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8219 | } else { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8220 | if (ExpectedSLoc ToExLocE = Import_New(FromEx.getExpansionLocEnd())) |
| 8221 | MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, TokenLen, |
| 8222 | FromEx.isExpansionTokenRange()); |
| 8223 | else |
| 8224 | return ToExLocE.takeError(); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8225 | } |
| 8226 | ToID = ToSM.getFileID(MLoc); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8227 | } else { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8228 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8229 | |
| 8230 | if (!IsBuiltin) { |
| 8231 | // Include location of this file. |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8232 | ExpectedSLoc ToIncludeLoc = |
| 8233 | Import_New(FromSLoc.getFile().getIncludeLoc()); |
| 8234 | if (!ToIncludeLoc) |
| 8235 | return ToIncludeLoc.takeError(); |
Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8236 | |
| 8237 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
| 8238 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 8239 | // disk again |
| 8240 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 8241 | // than mmap the files several times. |
| 8242 | const FileEntry *Entry = |
| 8243 | ToFileManager.getFile(Cache->OrigEntry->getName()); |
| 8244 | // FIXME: The filename may be a virtual name that does probably not |
| 8245 | // point to a valid file and we get no Entry here. In this case try with |
| 8246 | // the memory buffer below. |
| 8247 | if (Entry) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8248 | ToID = ToSM.createFileID(Entry, *ToIncludeLoc, |
Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8249 | FromSLoc.getFile().getFileCharacteristic()); |
| 8250 | } |
Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8251 | } |
Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8252 | |
| 8253 | if (ToID.isInvalid() || IsBuiltin) { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8254 | // FIXME: We want to re-use the existing MemoryBuffer! |
Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8255 | bool Invalid = true; |
| 8256 | const llvm::MemoryBuffer *FromBuf = Cache->getBuffer( |
| 8257 | FromContext.getDiagnostics(), FromSM, SourceLocation{}, &Invalid); |
| 8258 | if (!FromBuf || Invalid) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8259 | // FIXME: Use a new error kind? |
| 8260 | return llvm::make_error<ImportError>(ImportError::Unknown); |
Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8261 | |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8262 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = |
| 8263 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
| 8264 | FromBuf->getBufferIdentifier()); |
| 8265 | ToID = ToSM.createFileID(std::move(ToBuf), |
| 8266 | FromSLoc.getFile().getFileCharacteristic()); |
| 8267 | } |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8268 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8269 | |
Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8270 | assert(ToID.isValid() && "Unexpected invalid fileID was created."); |
| 8271 | |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 8272 | ImportedFileIDs[FromID] = ToID; |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8273 | return ToID; |
| 8274 | } |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8275 | FileID ASTImporter::Import(FileID From, bool IsBuiltin) { |
| 8276 | llvm::Expected<FileID> To = Import_New(From, IsBuiltin); |
| 8277 | if (To) |
| 8278 | return *To; |
| 8279 | else |
| 8280 | llvm::consumeError(To.takeError()); |
| 8281 | return {}; |
| 8282 | } |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8283 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8284 | Expected<CXXCtorInitializer *> |
| 8285 | ASTImporter::Import_New(CXXCtorInitializer *From) { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8286 | ExpectedExpr ToExprOrErr = Import_New(From->getInit()); |
| 8287 | if (!ToExprOrErr) |
| 8288 | return ToExprOrErr.takeError(); |
| 8289 | |
| 8290 | auto LParenLocOrErr = Import_New(From->getLParenLoc()); |
| 8291 | if (!LParenLocOrErr) |
| 8292 | return LParenLocOrErr.takeError(); |
| 8293 | |
| 8294 | auto RParenLocOrErr = Import_New(From->getRParenLoc()); |
| 8295 | if (!RParenLocOrErr) |
| 8296 | return RParenLocOrErr.takeError(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8297 | |
| 8298 | if (From->isBaseInitializer()) { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8299 | auto ToTInfoOrErr = Import_New(From->getTypeSourceInfo()); |
| 8300 | if (!ToTInfoOrErr) |
| 8301 | return ToTInfoOrErr.takeError(); |
| 8302 | |
| 8303 | SourceLocation EllipsisLoc; |
| 8304 | if (From->isPackExpansion()) |
| 8305 | if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc())) |
| 8306 | return std::move(Err); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8307 | |
| 8308 | return new (ToContext) CXXCtorInitializer( |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8309 | ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr, |
| 8310 | *ToExprOrErr, *RParenLocOrErr, EllipsisLoc); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8311 | } else if (From->isMemberInitializer()) { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8312 | ExpectedDecl ToFieldOrErr = Import_New(From->getMember()); |
| 8313 | if (!ToFieldOrErr) |
| 8314 | return ToFieldOrErr.takeError(); |
| 8315 | |
| 8316 | auto MemberLocOrErr = Import_New(From->getMemberLocation()); |
| 8317 | if (!MemberLocOrErr) |
| 8318 | return MemberLocOrErr.takeError(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8319 | |
| 8320 | return new (ToContext) CXXCtorInitializer( |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8321 | ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr, |
| 8322 | *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8323 | } else if (From->isIndirectMemberInitializer()) { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8324 | ExpectedDecl ToIFieldOrErr = Import_New(From->getIndirectMember()); |
| 8325 | if (!ToIFieldOrErr) |
| 8326 | return ToIFieldOrErr.takeError(); |
| 8327 | |
| 8328 | auto MemberLocOrErr = Import_New(From->getMemberLocation()); |
| 8329 | if (!MemberLocOrErr) |
| 8330 | return MemberLocOrErr.takeError(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8331 | |
| 8332 | return new (ToContext) CXXCtorInitializer( |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8333 | ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr), |
| 8334 | *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8335 | } else if (From->isDelegatingInitializer()) { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8336 | auto ToTInfoOrErr = Import_New(From->getTypeSourceInfo()); |
| 8337 | if (!ToTInfoOrErr) |
| 8338 | return ToTInfoOrErr.takeError(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8339 | |
| 8340 | return new (ToContext) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8341 | CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr, |
| 8342 | *ToExprOrErr, *RParenLocOrErr); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8343 | } else { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8344 | // FIXME: assert? |
| 8345 | return make_error<ImportError>(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8346 | } |
Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 8347 | } |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8348 | CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) { |
| 8349 | llvm::Expected<CXXCtorInitializer *> To = Import_New(From); |
| 8350 | if (To) |
| 8351 | return *To; |
| 8352 | else |
| 8353 | llvm::consumeError(To.takeError()); |
| 8354 | return nullptr; |
| 8355 | } |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8356 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8357 | Expected<CXXBaseSpecifier *> |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8358 | ASTImporter::Import_New(const CXXBaseSpecifier *BaseSpec) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8359 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 8360 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 8361 | return Pos->second; |
| 8362 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8363 | Expected<SourceRange> ToSourceRange = Import_New(BaseSpec->getSourceRange()); |
| 8364 | if (!ToSourceRange) |
| 8365 | return ToSourceRange.takeError(); |
| 8366 | Expected<TypeSourceInfo *> ToTSI = Import_New(BaseSpec->getTypeSourceInfo()); |
| 8367 | if (!ToTSI) |
| 8368 | return ToTSI.takeError(); |
| 8369 | ExpectedSLoc ToEllipsisLoc = Import_New(BaseSpec->getEllipsisLoc()); |
| 8370 | if (!ToEllipsisLoc) |
| 8371 | return ToEllipsisLoc.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8372 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8373 | *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 8374 | BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8375 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 8376 | return Imported; |
| 8377 | } |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8378 | CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *From) { |
| 8379 | llvm::Expected<CXXBaseSpecifier *> To = Import_New(From); |
| 8380 | if (To) |
| 8381 | return *To; |
| 8382 | else |
| 8383 | llvm::consumeError(To.takeError()); |
| 8384 | return nullptr; |
| 8385 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8386 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8387 | Error ASTImporter::ImportDefinition_New(Decl *From) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8388 | Decl *To = Import(From); |
| 8389 | if (!To) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8390 | return llvm::make_error<ImportError>(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8391 | |
Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8392 | auto *FromDC = cast<DeclContext>(From); |
| 8393 | ASTNodeImporter Importer(*this); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8394 | |
Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8395 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { |
| 8396 | if (!ToRecord->getDefinition()) { |
| 8397 | return Importer.ImportDefinition( |
| 8398 | cast<RecordDecl>(FromDC), ToRecord, |
| 8399 | ASTNodeImporter::IDK_Everything); |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 8400 | } |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8401 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8402 | |
Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8403 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { |
| 8404 | if (!ToEnum->getDefinition()) { |
| 8405 | return Importer.ImportDefinition( |
| 8406 | cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything); |
| 8407 | } |
| 8408 | } |
| 8409 | |
| 8410 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
| 8411 | if (!ToIFace->getDefinition()) { |
| 8412 | return Importer.ImportDefinition( |
| 8413 | cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
| 8414 | ASTNodeImporter::IDK_Everything); |
| 8415 | } |
| 8416 | } |
| 8417 | |
| 8418 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
| 8419 | if (!ToProto->getDefinition()) { |
| 8420 | return Importer.ImportDefinition( |
| 8421 | cast<ObjCProtocolDecl>(FromDC), ToProto, |
| 8422 | ASTNodeImporter::IDK_Everything); |
| 8423 | } |
| 8424 | } |
| 8425 | |
| 8426 | return Importer.ImportDeclContext(FromDC, true); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8427 | } |
| 8428 | |
| 8429 | void ASTImporter::ImportDefinition(Decl *From) { |
| 8430 | Error Err = ImportDefinition_New(From); |
| 8431 | llvm::consumeError(std::move(Err)); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8432 | } |
| 8433 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8434 | Expected<DeclarationName> ASTImporter::Import_New(DeclarationName FromName) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8435 | if (!FromName) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8436 | return DeclarationName{}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8437 | |
| 8438 | switch (FromName.getNameKind()) { |
| 8439 | case DeclarationName::Identifier: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8440 | return DeclarationName(Import(FromName.getAsIdentifierInfo())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8441 | |
| 8442 | case DeclarationName::ObjCZeroArgSelector: |
| 8443 | case DeclarationName::ObjCOneArgSelector: |
| 8444 | case DeclarationName::ObjCMultiArgSelector: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8445 | if (auto ToSelOrErr = Import_New(FromName.getObjCSelector())) |
| 8446 | return DeclarationName(*ToSelOrErr); |
| 8447 | else |
| 8448 | return ToSelOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8449 | |
| 8450 | case DeclarationName::CXXConstructorName: { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8451 | if (auto ToTyOrErr = Import_New(FromName.getCXXNameType())) |
| 8452 | return ToContext.DeclarationNames.getCXXConstructorName( |
| 8453 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8454 | else |
| 8455 | return ToTyOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8456 | } |
| 8457 | |
| 8458 | case DeclarationName::CXXDestructorName: { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8459 | if (auto ToTyOrErr = Import_New(FromName.getCXXNameType())) |
| 8460 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 8461 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8462 | else |
| 8463 | return ToTyOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8464 | } |
| 8465 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8466 | case DeclarationName::CXXDeductionGuideName: { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8467 | if (auto ToTemplateOrErr = |
| 8468 | Import_New(FromName.getCXXDeductionGuideTemplate())) |
| 8469 | return ToContext.DeclarationNames.getCXXDeductionGuideName( |
| 8470 | cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8471 | else |
| 8472 | return ToTemplateOrErr.takeError(); |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8473 | } |
| 8474 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8475 | case DeclarationName::CXXConversionFunctionName: { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8476 | if (auto ToTyOrErr = Import_New(FromName.getCXXNameType())) |
| 8477 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 8478 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8479 | else |
| 8480 | return ToTyOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8481 | } |
| 8482 | |
| 8483 | case DeclarationName::CXXOperatorName: |
| 8484 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 8485 | FromName.getCXXOverloadedOperator()); |
| 8486 | |
| 8487 | case DeclarationName::CXXLiteralOperatorName: |
| 8488 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8489 | Import(FromName.getCXXLiteralIdentifier())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8490 | |
| 8491 | case DeclarationName::CXXUsingDirective: |
| 8492 | // FIXME: STATICS! |
| 8493 | return DeclarationName::getUsingDirectiveName(); |
| 8494 | } |
| 8495 | |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 8496 | llvm_unreachable("Invalid DeclarationName Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8497 | } |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8498 | DeclarationName ASTImporter::Import(DeclarationName From) { |
| 8499 | llvm::Expected<DeclarationName> To = Import_New(From); |
| 8500 | if (To) |
| 8501 | return *To; |
| 8502 | else |
| 8503 | llvm::consumeError(To.takeError()); |
| 8504 | return {}; |
| 8505 | } |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8506 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8507 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8508 | if (!FromId) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8509 | return nullptr; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8510 | |
Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 8511 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 8512 | |
| 8513 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 8514 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 8515 | |
| 8516 | return ToId; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8517 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8518 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8519 | Expected<Selector> ASTImporter::Import_New(Selector FromSel) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8520 | if (FromSel.isNull()) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8521 | return Selector{}; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8522 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 8523 | SmallVector<IdentifierInfo *, 4> Idents; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8524 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 8525 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 8526 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 8527 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 8528 | } |
| 8529 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8530 | DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, |
| 8531 | DeclContext *DC, |
| 8532 | unsigned IDNS, |
| 8533 | NamedDecl **Decls, |
| 8534 | unsigned NumDecls) { |
| 8535 | return Name; |
| 8536 | } |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8537 | Selector ASTImporter::Import(Selector From) { |
| 8538 | llvm::Expected<Selector> To = Import_New(From); |
| 8539 | if (To) |
| 8540 | return *To; |
| 8541 | else |
| 8542 | llvm::consumeError(To.takeError()); |
| 8543 | return {}; |
| 8544 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8545 | |
| 8546 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8547 | if (LastDiagFromFrom) |
| 8548 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8549 | FromContext.getDiagnostics()); |
| 8550 | LastDiagFromFrom = false; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8551 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8552 | } |
| 8553 | |
| 8554 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8555 | if (!LastDiagFromFrom) |
| 8556 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8557 | ToContext.getDiagnostics()); |
| 8558 | LastDiagFromFrom = true; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8559 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8560 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8561 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8562 | void ASTImporter::CompleteDecl (Decl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8563 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8564 | if (!ID->getDefinition()) |
| 8565 | ID->startDefinition(); |
| 8566 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8567 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8568 | if (!PD->getDefinition()) |
| 8569 | PD->startDefinition(); |
| 8570 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8571 | else if (auto *TD = dyn_cast<TagDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8572 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 8573 | TD->startDefinition(); |
| 8574 | TD->setCompleteDefinition(true); |
| 8575 | } |
| 8576 | } |
| 8577 | else { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8578 | assert(0 && "CompleteDecl called on a Decl that can't be completed"); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8579 | } |
| 8580 | } |
| 8581 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8582 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { |
| 8583 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); |
| 8584 | assert((Pos == ImportedDecls.end() || Pos->second == To) && |
| 8585 | "Try to import an already imported Decl"); |
| 8586 | if (Pos != ImportedDecls.end()) |
| 8587 | return Pos->second; |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8588 | ImportedDecls[From] = To; |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 8589 | // This mapping should be maintained only in this function. Therefore do not |
| 8590 | // check for additional consistency. |
| 8591 | ImportedFromDecls[To] = From; |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8592 | return To; |
Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 8593 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8594 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8595 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 8596 | bool Complain) { |
Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 8597 | llvm::DenseMap<const Type *, const Type *>::iterator Pos = |
| 8598 | ImportedTypes.find(From.getTypePtr()); |
| 8599 | if (Pos != ImportedTypes.end()) { |
| 8600 | if (ExpectedType ToFromOrErr = Import_New(From)) { |
| 8601 | if (ToContext.hasSameType(*ToFromOrErr, To)) |
| 8602 | return true; |
| 8603 | } else { |
| 8604 | llvm::consumeError(ToFromOrErr.takeError()); |
| 8605 | } |
| 8606 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 8607 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8608 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8609 | getStructuralEquivalenceKind(*this), false, |
| 8610 | Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 8611 | return Ctx.IsEquivalent(From, To); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8612 | } |