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) { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 151 | auto ToOrErr = Importer.Import(From); |
Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 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) { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 161 | auto ToOrErr = Importer.Import(From); |
Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 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) { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 175 | return Importer.Import(From); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Richard Smith | b9fb121 | 2019-05-06 03:47:15 +0000 | [diff] [blame] | 178 | // Import an Optional<T> by importing the contained T, if any. |
| 179 | template<typename T> |
| 180 | Expected<Optional<T>> import(Optional<T> From) { |
| 181 | if (!From) |
| 182 | return Optional<T>(); |
| 183 | return import(*From); |
| 184 | } |
| 185 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 186 | template <class T> |
| 187 | Expected<std::tuple<T>> |
| 188 | importSeq(const T &From) { |
| 189 | Expected<T> ToOrErr = import(From); |
| 190 | if (!ToOrErr) |
| 191 | return ToOrErr.takeError(); |
| 192 | return std::make_tuple<T>(std::move(*ToOrErr)); |
| 193 | } |
| 194 | |
| 195 | // Import multiple objects with a single function call. |
| 196 | // This should work for every type for which a variant of `import` exists. |
| 197 | // The arguments are processed from left to right and import is stopped on |
| 198 | // first error. |
| 199 | template <class THead, class... TTail> |
| 200 | Expected<std::tuple<THead, TTail...>> |
| 201 | importSeq(const THead &FromHead, const TTail &...FromTail) { |
| 202 | Expected<std::tuple<THead>> ToHeadOrErr = importSeq(FromHead); |
| 203 | if (!ToHeadOrErr) |
| 204 | return ToHeadOrErr.takeError(); |
| 205 | Expected<std::tuple<TTail...>> ToTailOrErr = importSeq(FromTail...); |
| 206 | if (!ToTailOrErr) |
| 207 | return ToTailOrErr.takeError(); |
| 208 | return std::tuple_cat(*ToHeadOrErr, *ToTailOrErr); |
| 209 | } |
| 210 | |
| 211 | // Wrapper for an overload set. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 212 | template <typename ToDeclT> struct CallOverloadedCreateFun { |
| 213 | template <typename... Args> |
| 214 | auto operator()(Args &&... args) |
| 215 | -> decltype(ToDeclT::Create(std::forward<Args>(args)...)) { |
| 216 | return ToDeclT::Create(std::forward<Args>(args)...); |
| 217 | } |
| 218 | }; |
| 219 | |
| 220 | // Always use these functions to create a Decl during import. There are |
| 221 | // certain tasks which must be done after the Decl was created, e.g. we |
| 222 | // must immediately register that as an imported Decl. The parameter `ToD` |
| 223 | // will be set to the newly created Decl or if had been imported before |
| 224 | // then to the already imported Decl. Returns a bool value set to true if |
| 225 | // the `FromD` had been imported before. |
| 226 | template <typename ToDeclT, typename FromDeclT, typename... Args> |
| 227 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, |
| 228 | Args &&... args) { |
| 229 | // There may be several overloads of ToDeclT::Create. We must make sure |
| 230 | // to call the one which would be chosen by the arguments, thus we use a |
| 231 | // wrapper for the overload set. |
| 232 | CallOverloadedCreateFun<ToDeclT> OC; |
| 233 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, |
| 234 | std::forward<Args>(args)...); |
| 235 | } |
| 236 | // Use this overload if a special Type is needed to be created. E.g if we |
| 237 | // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl` |
| 238 | // then: |
| 239 | // TypedefNameDecl *ToTypedef; |
| 240 | // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...); |
| 241 | template <typename NewDeclT, typename ToDeclT, typename FromDeclT, |
| 242 | typename... Args> |
| 243 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, |
| 244 | Args &&... args) { |
| 245 | CallOverloadedCreateFun<NewDeclT> OC; |
| 246 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, |
| 247 | std::forward<Args>(args)...); |
| 248 | } |
| 249 | // Use this version if a special create function must be |
| 250 | // used, e.g. CXXRecordDecl::CreateLambda . |
| 251 | template <typename ToDeclT, typename CreateFunT, typename FromDeclT, |
| 252 | typename... Args> |
| 253 | LLVM_NODISCARD bool |
| 254 | GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun, |
| 255 | FromDeclT *FromD, Args &&... args) { |
Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame^] | 256 | if (Importer.getImportDeclErrorIfAny(FromD)) { |
| 257 | ToD = nullptr; |
| 258 | return true; // Already imported but with error. |
| 259 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 260 | ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD)); |
| 261 | if (ToD) |
| 262 | return true; // Already imported. |
| 263 | ToD = CreateFun(std::forward<Args>(args)...); |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 264 | // Keep track of imported Decls. |
Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 265 | Importer.RegisterImportedDecl(FromD, ToD); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 266 | InitializeImportedDecl(FromD, ToD); |
| 267 | return false; // A new Decl is created. |
| 268 | } |
| 269 | |
| 270 | void InitializeImportedDecl(Decl *FromD, Decl *ToD) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 271 | ToD->IdentifierNamespace = FromD->IdentifierNamespace; |
| 272 | if (FromD->hasAttrs()) |
Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 273 | for (const Attr *FromAttr : FromD->getAttrs()) { |
| 274 | // FIXME: Return of the error here is not possible until store of |
| 275 | // import errors is implemented. |
| 276 | auto ToAttrOrErr = import(FromAttr); |
| 277 | if (ToAttrOrErr) |
| 278 | ToD->addAttr(*ToAttrOrErr); |
| 279 | else |
| 280 | llvm::consumeError(ToAttrOrErr.takeError()); |
| 281 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 282 | if (FromD->isUsed()) |
| 283 | ToD->setIsUsed(); |
| 284 | if (FromD->isImplicit()) |
| 285 | ToD->setImplicit(); |
| 286 | } |
| 287 | |
Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 288 | // Check if we have found an existing definition. Returns with that |
| 289 | // definition if yes, otherwise returns null. |
| 290 | Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) { |
| 291 | const FunctionDecl *Definition = nullptr; |
| 292 | if (D->doesThisDeclarationHaveABody() && |
| 293 | FoundFunction->hasBody(Definition)) |
| 294 | return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition)); |
| 295 | return nullptr; |
| 296 | } |
| 297 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 298 | public: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 299 | explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {} |
Gabor Marton | 344b099 | 2018-05-16 11:48:11 +0000 | [diff] [blame] | 300 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 301 | using TypeVisitor<ASTNodeImporter, ExpectedType>::Visit; |
| 302 | using DeclVisitor<ASTNodeImporter, ExpectedDecl>::Visit; |
| 303 | using StmtVisitor<ASTNodeImporter, ExpectedStmt>::Visit; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 304 | |
| 305 | // Importing types |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 306 | ExpectedType VisitType(const Type *T); |
| 307 | ExpectedType VisitAtomicType(const AtomicType *T); |
| 308 | ExpectedType VisitBuiltinType(const BuiltinType *T); |
| 309 | ExpectedType VisitDecayedType(const DecayedType *T); |
| 310 | ExpectedType VisitComplexType(const ComplexType *T); |
| 311 | ExpectedType VisitPointerType(const PointerType *T); |
| 312 | ExpectedType VisitBlockPointerType(const BlockPointerType *T); |
| 313 | ExpectedType VisitLValueReferenceType(const LValueReferenceType *T); |
| 314 | ExpectedType VisitRValueReferenceType(const RValueReferenceType *T); |
| 315 | ExpectedType VisitMemberPointerType(const MemberPointerType *T); |
| 316 | ExpectedType VisitConstantArrayType(const ConstantArrayType *T); |
| 317 | ExpectedType VisitIncompleteArrayType(const IncompleteArrayType *T); |
| 318 | ExpectedType VisitVariableArrayType(const VariableArrayType *T); |
| 319 | ExpectedType VisitDependentSizedArrayType(const DependentSizedArrayType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 320 | // FIXME: DependentSizedExtVectorType |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 321 | ExpectedType VisitVectorType(const VectorType *T); |
| 322 | ExpectedType VisitExtVectorType(const ExtVectorType *T); |
| 323 | ExpectedType VisitFunctionNoProtoType(const FunctionNoProtoType *T); |
| 324 | ExpectedType VisitFunctionProtoType(const FunctionProtoType *T); |
| 325 | ExpectedType VisitUnresolvedUsingType(const UnresolvedUsingType *T); |
| 326 | ExpectedType VisitParenType(const ParenType *T); |
| 327 | ExpectedType VisitTypedefType(const TypedefType *T); |
| 328 | ExpectedType VisitTypeOfExprType(const TypeOfExprType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 329 | // FIXME: DependentTypeOfExprType |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 330 | ExpectedType VisitTypeOfType(const TypeOfType *T); |
| 331 | ExpectedType VisitDecltypeType(const DecltypeType *T); |
| 332 | ExpectedType VisitUnaryTransformType(const UnaryTransformType *T); |
| 333 | ExpectedType VisitAutoType(const AutoType *T); |
| 334 | ExpectedType VisitInjectedClassNameType(const InjectedClassNameType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 335 | // FIXME: DependentDecltypeType |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 336 | ExpectedType VisitRecordType(const RecordType *T); |
| 337 | ExpectedType VisitEnumType(const EnumType *T); |
| 338 | ExpectedType VisitAttributedType(const AttributedType *T); |
| 339 | ExpectedType VisitTemplateTypeParmType(const TemplateTypeParmType *T); |
| 340 | ExpectedType VisitSubstTemplateTypeParmType( |
| 341 | const SubstTemplateTypeParmType *T); |
| 342 | ExpectedType VisitTemplateSpecializationType( |
| 343 | const TemplateSpecializationType *T); |
| 344 | ExpectedType VisitElaboratedType(const ElaboratedType *T); |
| 345 | ExpectedType VisitDependentNameType(const DependentNameType *T); |
| 346 | ExpectedType VisitPackExpansionType(const PackExpansionType *T); |
| 347 | ExpectedType VisitDependentTemplateSpecializationType( |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 348 | const DependentTemplateSpecializationType *T); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 349 | ExpectedType VisitObjCInterfaceType(const ObjCInterfaceType *T); |
| 350 | ExpectedType VisitObjCObjectType(const ObjCObjectType *T); |
| 351 | ExpectedType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); |
Rafael Stahl | df55620 | 2018-05-29 08:12:15 +0000 | [diff] [blame] | 352 | |
| 353 | // Importing declarations |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 354 | Error ImportDeclParts( |
| 355 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, |
| 356 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc); |
| 357 | Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr); |
| 358 | Error ImportDeclarationNameLoc( |
| 359 | const DeclarationNameInfo &From, DeclarationNameInfo &To); |
| 360 | Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); |
| 361 | Error ImportDeclContext( |
| 362 | Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC); |
| 363 | Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 364 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 365 | Expected<CXXCastPath> ImportCastPath(CastExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 366 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 367 | using Designator = DesignatedInitExpr::Designator; |
| 368 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 369 | /// What we should import from the definition. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 370 | enum ImportDefinitionKind { |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 371 | /// Import the default subset of the definition, which might be |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 372 | /// nothing (if minimal import is set) or might be everything (if minimal |
| 373 | /// import is not set). |
| 374 | IDK_Default, |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 375 | /// Import everything. |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 376 | IDK_Everything, |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 377 | /// Import only the bare bones needed to establish a valid |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 378 | /// DeclContext. |
| 379 | IDK_Basic |
| 380 | }; |
| 381 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 382 | bool shouldForceImportDeclContext(ImportDefinitionKind IDK) { |
| 383 | return IDK == IDK_Everything || |
| 384 | (IDK == IDK_Default && !Importer.isMinimalImport()); |
| 385 | } |
| 386 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 387 | Error ImportInitializer(VarDecl *From, VarDecl *To); |
| 388 | Error ImportDefinition( |
| 389 | RecordDecl *From, RecordDecl *To, |
| 390 | ImportDefinitionKind Kind = IDK_Default); |
| 391 | Error ImportDefinition( |
| 392 | EnumDecl *From, EnumDecl *To, |
| 393 | ImportDefinitionKind Kind = IDK_Default); |
| 394 | Error ImportDefinition( |
| 395 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, |
| 396 | ImportDefinitionKind Kind = IDK_Default); |
| 397 | Error ImportDefinition( |
| 398 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, |
| 399 | ImportDefinitionKind Kind = IDK_Default); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 400 | Error ImportTemplateArguments( |
| 401 | const TemplateArgument *FromArgs, unsigned NumFromArgs, |
| 402 | SmallVectorImpl<TemplateArgument> &ToArgs); |
| 403 | Expected<TemplateArgument> |
| 404 | ImportTemplateArgument(const TemplateArgument &From); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 405 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 406 | template <typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 407 | Error ImportTemplateArgumentListInfo( |
| 408 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 409 | |
| 410 | template<typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 411 | Error ImportTemplateArgumentListInfo( |
| 412 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 413 | const InContainerTy &Container, TemplateArgumentListInfo &Result); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 414 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 415 | using TemplateArgsTy = SmallVector<TemplateArgument, 8>; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 416 | using FunctionTemplateAndArgsTy = |
| 417 | std::tuple<FunctionTemplateDecl *, TemplateArgsTy>; |
| 418 | Expected<FunctionTemplateAndArgsTy> |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 419 | ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 420 | FunctionDecl *FromFD); |
Balazs Keri | 1efc974 | 2019-05-07 10:55:11 +0000 | [diff] [blame] | 421 | Error ImportTemplateParameterLists(const DeclaratorDecl *FromD, |
| 422 | DeclaratorDecl *ToD); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 423 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 424 | Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 425 | |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 426 | Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD); |
| 427 | |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 428 | template <typename T> |
| 429 | bool hasSameVisibilityContext(T *Found, T *From); |
| 430 | |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 431 | bool IsStructuralMatch(Decl *From, Decl *To, bool Complain); |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 432 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, |
| 433 | bool Complain = true); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 434 | bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 435 | bool Complain = true); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 436 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 437 | bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 438 | bool IsStructuralMatch(FunctionTemplateDecl *From, |
| 439 | FunctionTemplateDecl *To); |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 440 | bool IsStructuralMatch(FunctionDecl *From, FunctionDecl *To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 441 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 442 | bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 443 | ExpectedDecl VisitDecl(Decl *D); |
| 444 | ExpectedDecl VisitImportDecl(ImportDecl *D); |
| 445 | ExpectedDecl VisitEmptyDecl(EmptyDecl *D); |
| 446 | ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D); |
| 447 | ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D); |
| 448 | ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D); |
| 449 | ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D); |
| 450 | ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
| 451 | ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); |
| 452 | ExpectedDecl VisitTypedefDecl(TypedefDecl *D); |
| 453 | ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D); |
| 454 | ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); |
| 455 | ExpectedDecl VisitLabelDecl(LabelDecl *D); |
| 456 | ExpectedDecl VisitEnumDecl(EnumDecl *D); |
| 457 | ExpectedDecl VisitRecordDecl(RecordDecl *D); |
| 458 | ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D); |
| 459 | ExpectedDecl VisitFunctionDecl(FunctionDecl *D); |
| 460 | ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D); |
| 461 | ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 462 | ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 463 | ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D); |
| 464 | ExpectedDecl VisitFieldDecl(FieldDecl *D); |
| 465 | ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D); |
| 466 | ExpectedDecl VisitFriendDecl(FriendDecl *D); |
| 467 | ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D); |
| 468 | ExpectedDecl VisitVarDecl(VarDecl *D); |
| 469 | ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D); |
| 470 | ExpectedDecl VisitParmVarDecl(ParmVarDecl *D); |
| 471 | ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D); |
| 472 | ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
| 473 | ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| 474 | ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| 475 | ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D); |
| 476 | ExpectedDecl VisitUsingDecl(UsingDecl *D); |
| 477 | ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D); |
| 478 | ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 479 | ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
| 480 | ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 481 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 482 | Expected<ObjCTypeParamList *> |
| 483 | ImportObjCTypeParamList(ObjCTypeParamList *list); |
| 484 | |
| 485 | ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
| 486 | ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| 487 | ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| 488 | ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| 489 | ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
| 490 | ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
| 491 | ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 492 | ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
| 493 | ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D); |
| 494 | ExpectedDecl VisitClassTemplateSpecializationDecl( |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 495 | ClassTemplateSpecializationDecl *D); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 496 | ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D); |
| 497 | ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); |
| 498 | ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 499 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 500 | // Importing statements |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 501 | ExpectedStmt VisitStmt(Stmt *S); |
| 502 | ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S); |
| 503 | ExpectedStmt VisitDeclStmt(DeclStmt *S); |
| 504 | ExpectedStmt VisitNullStmt(NullStmt *S); |
| 505 | ExpectedStmt VisitCompoundStmt(CompoundStmt *S); |
| 506 | ExpectedStmt VisitCaseStmt(CaseStmt *S); |
| 507 | ExpectedStmt VisitDefaultStmt(DefaultStmt *S); |
| 508 | ExpectedStmt VisitLabelStmt(LabelStmt *S); |
| 509 | ExpectedStmt VisitAttributedStmt(AttributedStmt *S); |
| 510 | ExpectedStmt VisitIfStmt(IfStmt *S); |
| 511 | ExpectedStmt VisitSwitchStmt(SwitchStmt *S); |
| 512 | ExpectedStmt VisitWhileStmt(WhileStmt *S); |
| 513 | ExpectedStmt VisitDoStmt(DoStmt *S); |
| 514 | ExpectedStmt VisitForStmt(ForStmt *S); |
| 515 | ExpectedStmt VisitGotoStmt(GotoStmt *S); |
| 516 | ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S); |
| 517 | ExpectedStmt VisitContinueStmt(ContinueStmt *S); |
| 518 | ExpectedStmt VisitBreakStmt(BreakStmt *S); |
| 519 | ExpectedStmt VisitReturnStmt(ReturnStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 520 | // FIXME: MSAsmStmt |
| 521 | // FIXME: SEHExceptStmt |
| 522 | // FIXME: SEHFinallyStmt |
| 523 | // FIXME: SEHTryStmt |
| 524 | // FIXME: SEHLeaveStmt |
| 525 | // FIXME: CapturedStmt |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 526 | ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S); |
| 527 | ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S); |
| 528 | ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 529 | // FIXME: MSDependentExistsStmt |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 530 | ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); |
| 531 | ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); |
| 532 | ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); |
| 533 | ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S); |
| 534 | ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); |
| 535 | ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); |
| 536 | ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 537 | |
| 538 | // Importing expressions |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 539 | ExpectedStmt VisitExpr(Expr *E); |
| 540 | ExpectedStmt VisitVAArgExpr(VAArgExpr *E); |
Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 541 | ExpectedStmt VisitChooseExpr(ChooseExpr *E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 542 | ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E); |
| 543 | ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E); |
| 544 | ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E); |
| 545 | ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E); |
| 546 | ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E); |
| 547 | ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); |
| 548 | ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E); |
| 549 | ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E); |
| 550 | ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E); |
| 551 | ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E); |
| 552 | ExpectedStmt VisitStringLiteral(StringLiteral *E); |
| 553 | ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
| 554 | ExpectedStmt VisitAtomicExpr(AtomicExpr *E); |
| 555 | ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E); |
Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 556 | ExpectedStmt VisitConstantExpr(ConstantExpr *E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 557 | ExpectedStmt VisitParenExpr(ParenExpr *E); |
| 558 | ExpectedStmt VisitParenListExpr(ParenListExpr *E); |
| 559 | ExpectedStmt VisitStmtExpr(StmtExpr *E); |
| 560 | ExpectedStmt VisitUnaryOperator(UnaryOperator *E); |
| 561 | ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); |
| 562 | ExpectedStmt VisitBinaryOperator(BinaryOperator *E); |
| 563 | ExpectedStmt VisitConditionalOperator(ConditionalOperator *E); |
| 564 | ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E); |
| 565 | ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E); |
| 566 | ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); |
| 567 | ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E); |
| 568 | ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
| 569 | ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E); |
| 570 | ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E); |
| 571 | ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 572 | ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE); |
| 573 | ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E); |
| 574 | ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E); |
| 575 | ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); |
| 576 | ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); |
| 577 | ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); |
| 578 | ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E); |
| 579 | ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); |
| 580 | ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E); |
| 581 | ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E); |
| 582 | ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E); |
| 583 | ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E); |
| 584 | ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E); |
| 585 | ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E); |
| 586 | ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); |
| 587 | ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E); |
| 588 | ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E); |
| 589 | ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); |
| 590 | ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E); |
| 591 | ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E); |
| 592 | ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E); |
| 593 | ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); |
| 594 | ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); |
| 595 | ExpectedStmt VisitMemberExpr(MemberExpr *E); |
| 596 | ExpectedStmt VisitCallExpr(CallExpr *E); |
| 597 | ExpectedStmt VisitLambdaExpr(LambdaExpr *LE); |
| 598 | ExpectedStmt VisitInitListExpr(InitListExpr *E); |
| 599 | ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E); |
| 600 | ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E); |
| 601 | ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); |
| 602 | ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); |
| 603 | ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); |
| 604 | ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E); |
| 605 | ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); |
| 606 | ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E); |
| 607 | ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 608 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 609 | template<typename IIter, typename OIter> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 610 | Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 611 | using ItemT = typename std::remove_reference<decltype(*Obegin)>::type; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 612 | for (; Ibegin != Iend; ++Ibegin, ++Obegin) { |
| 613 | Expected<ItemT> ToOrErr = import(*Ibegin); |
| 614 | if (!ToOrErr) |
| 615 | return ToOrErr.takeError(); |
| 616 | *Obegin = *ToOrErr; |
| 617 | } |
| 618 | return Error::success(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 619 | } |
| 620 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 621 | // Import every item from a container structure into an output container. |
| 622 | // If error occurs, stops at first error and returns the error. |
| 623 | // The output container should have space for all needed elements (it is not |
| 624 | // expanded, new items are put into from the beginning). |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 625 | template<typename InContainerTy, typename OutContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 626 | Error ImportContainerChecked( |
| 627 | const InContainerTy &InContainer, OutContainerTy &OutContainer) { |
| 628 | return ImportArrayChecked( |
| 629 | InContainer.begin(), InContainer.end(), OutContainer.begin()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | template<typename InContainerTy, typename OIter> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 633 | Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 634 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); |
| 635 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 636 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 637 | void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 638 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 639 | Expected<FunctionDecl *> FindFunctionTemplateSpecialization( |
| 640 | FunctionDecl *FromFD); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 641 | }; |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 642 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 643 | template <typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 644 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 645 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 646 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 647 | auto ToLAngleLocOrErr = import(FromLAngleLoc); |
| 648 | if (!ToLAngleLocOrErr) |
| 649 | return ToLAngleLocOrErr.takeError(); |
| 650 | auto ToRAngleLocOrErr = import(FromRAngleLoc); |
| 651 | if (!ToRAngleLocOrErr) |
| 652 | return ToRAngleLocOrErr.takeError(); |
| 653 | |
| 654 | TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr); |
| 655 | if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo)) |
| 656 | return Err; |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 657 | Result = ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 658 | return Error::success(); |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 659 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 660 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 661 | template <> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 662 | Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 663 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { |
| 664 | return ImportTemplateArgumentListInfo( |
| 665 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); |
| 666 | } |
| 667 | |
| 668 | template <> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 669 | Error ASTNodeImporter::ImportTemplateArgumentListInfo< |
| 670 | ASTTemplateArgumentListInfo>( |
| 671 | const ASTTemplateArgumentListInfo &From, |
| 672 | TemplateArgumentListInfo &Result) { |
| 673 | return ImportTemplateArgumentListInfo( |
| 674 | From.LAngleLoc, From.RAngleLoc, From.arguments(), Result); |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 675 | } |
| 676 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 677 | Expected<ASTNodeImporter::FunctionTemplateAndArgsTy> |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 678 | ASTNodeImporter::ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 679 | FunctionDecl *FromFD) { |
| 680 | assert(FromFD->getTemplatedKind() == |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 681 | FunctionDecl::TK_FunctionTemplateSpecialization); |
| 682 | |
| 683 | FunctionTemplateAndArgsTy Result; |
| 684 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 685 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 686 | if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate())) |
| 687 | return std::move(Err); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 688 | |
| 689 | // Import template arguments. |
| 690 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 691 | if (Error Err = ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), |
| 692 | std::get<1>(Result))) |
| 693 | return std::move(Err); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 694 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 695 | return Result; |
| 696 | } |
| 697 | |
| 698 | template <> |
| 699 | Expected<TemplateParameterList *> |
| 700 | ASTNodeImporter::import(TemplateParameterList *From) { |
| 701 | SmallVector<NamedDecl *, 4> To(From->size()); |
| 702 | if (Error Err = ImportContainerChecked(*From, To)) |
| 703 | return std::move(Err); |
| 704 | |
| 705 | ExpectedExpr ToRequiresClause = import(From->getRequiresClause()); |
| 706 | if (!ToRequiresClause) |
| 707 | return ToRequiresClause.takeError(); |
| 708 | |
| 709 | auto ToTemplateLocOrErr = import(From->getTemplateLoc()); |
| 710 | if (!ToTemplateLocOrErr) |
| 711 | return ToTemplateLocOrErr.takeError(); |
| 712 | auto ToLAngleLocOrErr = import(From->getLAngleLoc()); |
| 713 | if (!ToLAngleLocOrErr) |
| 714 | return ToLAngleLocOrErr.takeError(); |
| 715 | auto ToRAngleLocOrErr = import(From->getRAngleLoc()); |
| 716 | if (!ToRAngleLocOrErr) |
| 717 | return ToRAngleLocOrErr.takeError(); |
| 718 | |
| 719 | return TemplateParameterList::Create( |
| 720 | Importer.getToContext(), |
| 721 | *ToTemplateLocOrErr, |
| 722 | *ToLAngleLocOrErr, |
| 723 | To, |
| 724 | *ToRAngleLocOrErr, |
| 725 | *ToRequiresClause); |
| 726 | } |
| 727 | |
| 728 | template <> |
| 729 | Expected<TemplateArgument> |
| 730 | ASTNodeImporter::import(const TemplateArgument &From) { |
| 731 | switch (From.getKind()) { |
| 732 | case TemplateArgument::Null: |
| 733 | return TemplateArgument(); |
| 734 | |
| 735 | case TemplateArgument::Type: { |
| 736 | ExpectedType ToTypeOrErr = import(From.getAsType()); |
| 737 | if (!ToTypeOrErr) |
| 738 | return ToTypeOrErr.takeError(); |
| 739 | return TemplateArgument(*ToTypeOrErr); |
| 740 | } |
| 741 | |
| 742 | case TemplateArgument::Integral: { |
| 743 | ExpectedType ToTypeOrErr = import(From.getIntegralType()); |
| 744 | if (!ToTypeOrErr) |
| 745 | return ToTypeOrErr.takeError(); |
| 746 | return TemplateArgument(From, *ToTypeOrErr); |
| 747 | } |
| 748 | |
| 749 | case TemplateArgument::Declaration: { |
| 750 | Expected<ValueDecl *> ToOrErr = import(From.getAsDecl()); |
| 751 | if (!ToOrErr) |
| 752 | return ToOrErr.takeError(); |
| 753 | ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl()); |
| 754 | if (!ToTypeOrErr) |
| 755 | return ToTypeOrErr.takeError(); |
| 756 | return TemplateArgument(*ToOrErr, *ToTypeOrErr); |
| 757 | } |
| 758 | |
| 759 | case TemplateArgument::NullPtr: { |
| 760 | ExpectedType ToTypeOrErr = import(From.getNullPtrType()); |
| 761 | if (!ToTypeOrErr) |
| 762 | return ToTypeOrErr.takeError(); |
| 763 | return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true); |
| 764 | } |
| 765 | |
| 766 | case TemplateArgument::Template: { |
| 767 | Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate()); |
| 768 | if (!ToTemplateOrErr) |
| 769 | return ToTemplateOrErr.takeError(); |
| 770 | |
| 771 | return TemplateArgument(*ToTemplateOrErr); |
| 772 | } |
| 773 | |
| 774 | case TemplateArgument::TemplateExpansion: { |
| 775 | Expected<TemplateName> ToTemplateOrErr = |
| 776 | import(From.getAsTemplateOrTemplatePattern()); |
| 777 | if (!ToTemplateOrErr) |
| 778 | return ToTemplateOrErr.takeError(); |
| 779 | |
| 780 | return TemplateArgument( |
| 781 | *ToTemplateOrErr, From.getNumTemplateExpansions()); |
| 782 | } |
| 783 | |
| 784 | case TemplateArgument::Expression: |
| 785 | if (ExpectedExpr ToExpr = import(From.getAsExpr())) |
| 786 | return TemplateArgument(*ToExpr); |
| 787 | else |
| 788 | return ToExpr.takeError(); |
| 789 | |
| 790 | case TemplateArgument::Pack: { |
| 791 | SmallVector<TemplateArgument, 2> ToPack; |
| 792 | ToPack.reserve(From.pack_size()); |
| 793 | if (Error Err = ImportTemplateArguments( |
| 794 | From.pack_begin(), From.pack_size(), ToPack)) |
| 795 | return std::move(Err); |
| 796 | |
| 797 | return TemplateArgument( |
| 798 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | llvm_unreachable("Invalid template argument kind"); |
| 803 | } |
| 804 | |
| 805 | template <> |
| 806 | Expected<TemplateArgumentLoc> |
| 807 | ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) { |
| 808 | Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument()); |
| 809 | if (!ArgOrErr) |
| 810 | return ArgOrErr.takeError(); |
| 811 | TemplateArgument Arg = *ArgOrErr; |
| 812 | |
| 813 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); |
| 814 | |
| 815 | TemplateArgumentLocInfo ToInfo; |
| 816 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 817 | ExpectedExpr E = import(FromInfo.getAsExpr()); |
| 818 | if (!E) |
| 819 | return E.takeError(); |
| 820 | ToInfo = TemplateArgumentLocInfo(*E); |
| 821 | } else if (Arg.getKind() == TemplateArgument::Type) { |
| 822 | if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo())) |
| 823 | ToInfo = TemplateArgumentLocInfo(*TSIOrErr); |
| 824 | else |
| 825 | return TSIOrErr.takeError(); |
| 826 | } else { |
| 827 | auto ToTemplateQualifierLocOrErr = |
| 828 | import(FromInfo.getTemplateQualifierLoc()); |
| 829 | if (!ToTemplateQualifierLocOrErr) |
| 830 | return ToTemplateQualifierLocOrErr.takeError(); |
| 831 | auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc()); |
| 832 | if (!ToTemplateNameLocOrErr) |
| 833 | return ToTemplateNameLocOrErr.takeError(); |
| 834 | auto ToTemplateEllipsisLocOrErr = |
| 835 | import(FromInfo.getTemplateEllipsisLoc()); |
| 836 | if (!ToTemplateEllipsisLocOrErr) |
| 837 | return ToTemplateEllipsisLocOrErr.takeError(); |
| 838 | |
| 839 | ToInfo = TemplateArgumentLocInfo( |
| 840 | *ToTemplateQualifierLocOrErr, |
| 841 | *ToTemplateNameLocOrErr, |
| 842 | *ToTemplateEllipsisLocOrErr); |
| 843 | } |
| 844 | |
| 845 | return TemplateArgumentLoc(Arg, ToInfo); |
| 846 | } |
| 847 | |
| 848 | template <> |
| 849 | Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) { |
| 850 | if (DG.isNull()) |
| 851 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); |
| 852 | size_t NumDecls = DG.end() - DG.begin(); |
| 853 | SmallVector<Decl *, 1> ToDecls; |
| 854 | ToDecls.reserve(NumDecls); |
| 855 | for (Decl *FromD : DG) { |
| 856 | if (auto ToDOrErr = import(FromD)) |
| 857 | ToDecls.push_back(*ToDOrErr); |
| 858 | else |
| 859 | return ToDOrErr.takeError(); |
| 860 | } |
| 861 | return DeclGroupRef::Create(Importer.getToContext(), |
| 862 | ToDecls.begin(), |
| 863 | NumDecls); |
| 864 | } |
| 865 | |
| 866 | template <> |
| 867 | Expected<ASTNodeImporter::Designator> |
| 868 | ASTNodeImporter::import(const Designator &D) { |
| 869 | if (D.isFieldDesignator()) { |
| 870 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); |
| 871 | |
| 872 | ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc()); |
| 873 | if (!ToDotLocOrErr) |
| 874 | return ToDotLocOrErr.takeError(); |
| 875 | |
| 876 | ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc()); |
| 877 | if (!ToFieldLocOrErr) |
| 878 | return ToFieldLocOrErr.takeError(); |
| 879 | |
| 880 | return Designator(ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr); |
| 881 | } |
| 882 | |
| 883 | ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc()); |
| 884 | if (!ToLBracketLocOrErr) |
| 885 | return ToLBracketLocOrErr.takeError(); |
| 886 | |
| 887 | ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc()); |
| 888 | if (!ToRBracketLocOrErr) |
| 889 | return ToRBracketLocOrErr.takeError(); |
| 890 | |
| 891 | if (D.isArrayDesignator()) |
| 892 | return Designator(D.getFirstExprIndex(), |
| 893 | *ToLBracketLocOrErr, *ToRBracketLocOrErr); |
| 894 | |
| 895 | ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc()); |
| 896 | if (!ToEllipsisLocOrErr) |
| 897 | return ToEllipsisLocOrErr.takeError(); |
| 898 | |
| 899 | assert(D.isArrayRangeDesignator()); |
| 900 | return Designator( |
| 901 | D.getFirstExprIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr, |
| 902 | *ToRBracketLocOrErr); |
| 903 | } |
| 904 | |
| 905 | template <> |
| 906 | Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) { |
| 907 | VarDecl *Var = nullptr; |
| 908 | if (From.capturesVariable()) { |
| 909 | if (auto VarOrErr = import(From.getCapturedVar())) |
| 910 | Var = *VarOrErr; |
| 911 | else |
| 912 | return VarOrErr.takeError(); |
| 913 | } |
| 914 | |
| 915 | auto LocationOrErr = import(From.getLocation()); |
| 916 | if (!LocationOrErr) |
| 917 | return LocationOrErr.takeError(); |
| 918 | |
| 919 | SourceLocation EllipsisLoc; |
| 920 | if (From.isPackExpansion()) |
| 921 | if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc())) |
| 922 | return std::move(Err); |
| 923 | |
| 924 | return LambdaCapture( |
| 925 | *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var, |
| 926 | EllipsisLoc); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 927 | } |
| 928 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 929 | } // namespace clang |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 930 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 931 | //---------------------------------------------------------------------------- |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 932 | // Import Types |
| 933 | //---------------------------------------------------------------------------- |
| 934 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 935 | using namespace clang; |
| 936 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 937 | ExpectedType ASTNodeImporter::VisitType(const Type *T) { |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 938 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) |
| 939 | << T->getTypeClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 940 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 941 | } |
| 942 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 943 | ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ |
| 944 | ExpectedType UnderlyingTypeOrErr = import(T->getValueType()); |
| 945 | if (!UnderlyingTypeOrErr) |
| 946 | return UnderlyingTypeOrErr.takeError(); |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 947 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 948 | return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr); |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 949 | } |
| 950 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 951 | ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 952 | switch (T->getKind()) { |
Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 953 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 954 | case BuiltinType::Id: \ |
| 955 | return Importer.getToContext().SingletonId; |
Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 956 | #include "clang/Basic/OpenCLImageTypes.def" |
Andrew Savonichev | 3fee351 | 2018-11-08 11:25:41 +0000 | [diff] [blame] | 957 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ |
| 958 | case BuiltinType::Id: \ |
| 959 | return Importer.getToContext().Id##Ty; |
| 960 | #include "clang/Basic/OpenCLExtensionTypes.def" |
John McCall | e314e27 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 961 | #define SHARED_SINGLETON_TYPE(Expansion) |
| 962 | #define BUILTIN_TYPE(Id, SingletonId) \ |
| 963 | case BuiltinType::Id: return Importer.getToContext().SingletonId; |
| 964 | #include "clang/AST/BuiltinTypes.def" |
| 965 | |
| 966 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" |
| 967 | // context supports C++. |
| 968 | |
| 969 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" |
| 970 | // context supports ObjC. |
| 971 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 972 | case BuiltinType::Char_U: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 973 | // The context we're importing from has an unsigned 'char'. If we're |
| 974 | // importing into a context with a signed 'char', translate to |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 975 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 976 | if (Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 977 | return Importer.getToContext().UnsignedCharTy; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 978 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 979 | return Importer.getToContext().CharTy; |
| 980 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 981 | case BuiltinType::Char_S: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 982 | // The context we're importing from has an unsigned 'char'. If we're |
| 983 | // importing into a context with a signed 'char', translate to |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 984 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 985 | if (!Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 986 | return Importer.getToContext().SignedCharTy; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 987 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 988 | return Importer.getToContext().CharTy; |
| 989 | |
Chris Lattner | ad3467e | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 990 | case BuiltinType::WChar_S: |
| 991 | case BuiltinType::WChar_U: |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 992 | // FIXME: If not in C++, shall we translate to the C equivalent of |
| 993 | // wchar_t? |
| 994 | return Importer.getToContext().WCharTy; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 995 | } |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 996 | |
| 997 | llvm_unreachable("Invalid BuiltinType Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 998 | } |
| 999 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1000 | ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { |
| 1001 | ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType()); |
| 1002 | if (!ToOriginalTypeOrErr) |
| 1003 | return ToOriginalTypeOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1004 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1005 | return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1008 | ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) { |
| 1009 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1010 | if (!ToElementTypeOrErr) |
| 1011 | return ToElementTypeOrErr.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().getComplexType(*ToElementTypeOrErr); |
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::VisitPointerType(const PointerType *T) { |
| 1017 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1018 | if (!ToPointeeTypeOrErr) |
| 1019 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1020 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1021 | return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1022 | } |
| 1023 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1024 | ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1025 | // FIXME: Check for blocks support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1026 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1027 | if (!ToPointeeTypeOrErr) |
| 1028 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1029 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1030 | return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1033 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1034 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1035 | // FIXME: Check for C++ support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1036 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); |
| 1037 | if (!ToPointeeTypeOrErr) |
| 1038 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1039 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1040 | return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1043 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1044 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1045 | // FIXME: Check for C++0x support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1046 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); |
| 1047 | if (!ToPointeeTypeOrErr) |
| 1048 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1049 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1050 | return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1051 | } |
| 1052 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1053 | ExpectedType |
| 1054 | ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1055 | // FIXME: Check for C++ support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1056 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1057 | if (!ToPointeeTypeOrErr) |
| 1058 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1059 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1060 | ExpectedType ClassTypeOrErr = import(QualType(T->getClass(), 0)); |
| 1061 | if (!ClassTypeOrErr) |
| 1062 | return ClassTypeOrErr.takeError(); |
| 1063 | |
| 1064 | return Importer.getToContext().getMemberPointerType( |
| 1065 | *ToPointeeTypeOrErr, (*ClassTypeOrErr).getTypePtr()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1066 | } |
| 1067 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1068 | ExpectedType |
| 1069 | ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { |
| 1070 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1071 | if (!ToElementTypeOrErr) |
| 1072 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1073 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1074 | return Importer.getToContext().getConstantArrayType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1075 | T->getSize(), |
| 1076 | T->getSizeModifier(), |
| 1077 | T->getIndexTypeCVRQualifiers()); |
| 1078 | } |
| 1079 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1080 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1081 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1082 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1083 | if (!ToElementTypeOrErr) |
| 1084 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1085 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1086 | return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1087 | T->getSizeModifier(), |
| 1088 | T->getIndexTypeCVRQualifiers()); |
| 1089 | } |
| 1090 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1091 | ExpectedType |
| 1092 | ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { |
| 1093 | QualType ToElementType; |
| 1094 | Expr *ToSizeExpr; |
| 1095 | SourceRange ToBracketsRange; |
| 1096 | if (auto Imp = importSeq( |
| 1097 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) |
| 1098 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; |
| 1099 | else |
| 1100 | return Imp.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1101 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1102 | return Importer.getToContext().getVariableArrayType( |
| 1103 | ToElementType, ToSizeExpr, T->getSizeModifier(), |
| 1104 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1105 | } |
| 1106 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1107 | ExpectedType ASTNodeImporter::VisitDependentSizedArrayType( |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1108 | const DependentSizedArrayType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1109 | QualType ToElementType; |
| 1110 | Expr *ToSizeExpr; |
| 1111 | SourceRange ToBracketsRange; |
| 1112 | if (auto Imp = importSeq( |
| 1113 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) |
| 1114 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; |
| 1115 | else |
| 1116 | return Imp.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1117 | // SizeExpr may be null if size is not specified directly. |
| 1118 | // For example, 'int a[]'. |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1119 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1120 | return Importer.getToContext().getDependentSizedArrayType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1121 | ToElementType, ToSizeExpr, T->getSizeModifier(), |
| 1122 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1125 | ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) { |
| 1126 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1127 | if (!ToElementTypeOrErr) |
| 1128 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1129 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1130 | return Importer.getToContext().getVectorType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1131 | T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 1132 | T->getVectorKind()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1135 | ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { |
| 1136 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1137 | if (!ToElementTypeOrErr) |
| 1138 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1139 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1140 | return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1141 | T->getNumElements()); |
| 1142 | } |
| 1143 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1144 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1145 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1146 | // FIXME: What happens if we're importing a function without a prototype |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1147 | // into C++? Should we make it variadic? |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1148 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); |
| 1149 | if (!ToReturnTypeOrErr) |
| 1150 | return ToReturnTypeOrErr.takeError(); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1151 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1152 | return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr, |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1153 | T->getExtInfo()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1156 | ExpectedType |
| 1157 | ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { |
| 1158 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); |
| 1159 | if (!ToReturnTypeOrErr) |
| 1160 | return ToReturnTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1161 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1162 | // Import argument types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1163 | SmallVector<QualType, 4> ArgTypes; |
Aaron Ballman | 40bd0aa | 2014-03-17 15:23:01 +0000 | [diff] [blame] | 1164 | for (const auto &A : T->param_types()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1165 | ExpectedType TyOrErr = import(A); |
| 1166 | if (!TyOrErr) |
| 1167 | return TyOrErr.takeError(); |
| 1168 | ArgTypes.push_back(*TyOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1169 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1170 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1171 | // Import exception types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1172 | SmallVector<QualType, 4> ExceptionTypes; |
Aaron Ballman | b088fbe | 2014-03-17 15:38:09 +0000 | [diff] [blame] | 1173 | for (const auto &E : T->exceptions()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1174 | ExpectedType TyOrErr = import(E); |
| 1175 | if (!TyOrErr) |
| 1176 | return TyOrErr.takeError(); |
| 1177 | ExceptionTypes.push_back(*TyOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1178 | } |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 1179 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1180 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); |
| 1181 | FunctionProtoType::ExtProtoInfo ToEPI; |
| 1182 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1183 | auto Imp = importSeq( |
| 1184 | FromEPI.ExceptionSpec.NoexceptExpr, |
| 1185 | FromEPI.ExceptionSpec.SourceDecl, |
| 1186 | FromEPI.ExceptionSpec.SourceTemplate); |
| 1187 | if (!Imp) |
| 1188 | return Imp.takeError(); |
| 1189 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1190 | ToEPI.ExtInfo = FromEPI.ExtInfo; |
| 1191 | ToEPI.Variadic = FromEPI.Variadic; |
| 1192 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; |
| 1193 | ToEPI.TypeQuals = FromEPI.TypeQuals; |
| 1194 | ToEPI.RefQualifier = FromEPI.RefQualifier; |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 1195 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; |
| 1196 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1197 | std::tie( |
| 1198 | ToEPI.ExceptionSpec.NoexceptExpr, |
| 1199 | ToEPI.ExceptionSpec.SourceDecl, |
| 1200 | ToEPI.ExceptionSpec.SourceTemplate) = *Imp; |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1201 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1202 | return Importer.getToContext().getFunctionType( |
| 1203 | *ToReturnTypeOrErr, ArgTypes, ToEPI); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1204 | } |
| 1205 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1206 | ExpectedType ASTNodeImporter::VisitUnresolvedUsingType( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1207 | const UnresolvedUsingType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1208 | UnresolvedUsingTypenameDecl *ToD; |
| 1209 | Decl *ToPrevD; |
| 1210 | if (auto Imp = importSeq(T->getDecl(), T->getDecl()->getPreviousDecl())) |
| 1211 | std::tie(ToD, ToPrevD) = *Imp; |
| 1212 | else |
| 1213 | return Imp.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1214 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1215 | return Importer.getToContext().getTypeDeclType( |
| 1216 | ToD, cast_or_null<TypeDecl>(ToPrevD)); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1219 | ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) { |
| 1220 | ExpectedType ToInnerTypeOrErr = import(T->getInnerType()); |
| 1221 | if (!ToInnerTypeOrErr) |
| 1222 | return ToInnerTypeOrErr.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().getParenType(*ToInnerTypeOrErr); |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 1225 | } |
| 1226 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1227 | ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { |
| 1228 | Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1229 | if (!ToDeclOrErr) |
| 1230 | return ToDeclOrErr.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().getTypeDeclType(*ToDeclOrErr); |
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::VisitTypeOfExprType(const TypeOfExprType *T) { |
| 1236 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); |
| 1237 | if (!ToExprOrErr) |
| 1238 | return ToExprOrErr.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().getTypeOfExprType(*ToExprOrErr); |
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::VisitTypeOfType(const TypeOfType *T) { |
| 1244 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1245 | if (!ToUnderlyingTypeOrErr) |
| 1246 | return ToUnderlyingTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1247 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1248 | return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1249 | } |
| 1250 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1251 | ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1252 | // FIXME: Make sure that the "to" context supports C++0x! |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1253 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); |
| 1254 | if (!ToExprOrErr) |
| 1255 | return ToExprOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1256 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1257 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1258 | if (!ToUnderlyingTypeOrErr) |
| 1259 | return ToUnderlyingTypeOrErr.takeError(); |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 1260 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1261 | return Importer.getToContext().getDecltypeType( |
| 1262 | *ToExprOrErr, *ToUnderlyingTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1263 | } |
| 1264 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1265 | ExpectedType |
| 1266 | ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 1267 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); |
| 1268 | if (!ToBaseTypeOrErr) |
| 1269 | return ToBaseTypeOrErr.takeError(); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1270 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1271 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1272 | if (!ToUnderlyingTypeOrErr) |
| 1273 | return ToUnderlyingTypeOrErr.takeError(); |
| 1274 | |
| 1275 | return Importer.getToContext().getUnaryTransformType( |
| 1276 | *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind()); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1277 | } |
| 1278 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1279 | ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 1280 | // FIXME: Make sure that the "to" context supports C++11! |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1281 | ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType()); |
| 1282 | if (!ToDeducedTypeOrErr) |
| 1283 | return ToDeducedTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1284 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1285 | return Importer.getToContext().getAutoType(*ToDeducedTypeOrErr, |
| 1286 | T->getKeyword(), |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 1287 | /*IsDependent*/false); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1288 | } |
| 1289 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1290 | ExpectedType ASTNodeImporter::VisitInjectedClassNameType( |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1291 | const InjectedClassNameType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1292 | Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1293 | if (!ToDeclOrErr) |
| 1294 | return ToDeclOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1295 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1296 | ExpectedType ToInjTypeOrErr = import(T->getInjectedSpecializationType()); |
| 1297 | if (!ToInjTypeOrErr) |
| 1298 | return ToInjTypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1299 | |
| 1300 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading |
| 1301 | // See comments in InjectedClassNameType definition for details |
| 1302 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); |
| 1303 | enum { |
| 1304 | TypeAlignmentInBits = 4, |
| 1305 | TypeAlignment = 1 << TypeAlignmentInBits |
| 1306 | }; |
| 1307 | |
| 1308 | return QualType(new (Importer.getToContext(), TypeAlignment) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1309 | InjectedClassNameType(*ToDeclOrErr, *ToInjTypeOrErr), 0); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1310 | } |
| 1311 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1312 | ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) { |
| 1313 | Expected<RecordDecl *> 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::VisitEnumType(const EnumType *T) { |
| 1321 | Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1322 | if (!ToDeclOrErr) |
| 1323 | return ToDeclOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1324 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1325 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1326 | } |
| 1327 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1328 | ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { |
| 1329 | ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType()); |
| 1330 | if (!ToModifiedTypeOrErr) |
| 1331 | return ToModifiedTypeOrErr.takeError(); |
| 1332 | ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType()); |
| 1333 | if (!ToEquivalentTypeOrErr) |
| 1334 | return ToEquivalentTypeOrErr.takeError(); |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1335 | |
| 1336 | return Importer.getToContext().getAttributedType(T->getAttrKind(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1337 | *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr); |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1338 | } |
| 1339 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1340 | ExpectedType ASTNodeImporter::VisitTemplateTypeParmType( |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1341 | const TemplateTypeParmType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1342 | Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1343 | if (!ToDeclOrErr) |
| 1344 | return ToDeclOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1345 | |
| 1346 | return Importer.getToContext().getTemplateTypeParmType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1347 | T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1348 | } |
| 1349 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1350 | ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType( |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1351 | const SubstTemplateTypeParmType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1352 | ExpectedType ReplacedOrErr = import(QualType(T->getReplacedParameter(), 0)); |
| 1353 | if (!ReplacedOrErr) |
| 1354 | return ReplacedOrErr.takeError(); |
| 1355 | const TemplateTypeParmType *Replaced = |
| 1356 | cast<TemplateTypeParmType>((*ReplacedOrErr).getTypePtr()); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1357 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1358 | ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType()); |
| 1359 | if (!ToReplacementTypeOrErr) |
| 1360 | return ToReplacementTypeOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1361 | |
| 1362 | return Importer.getToContext().getSubstTemplateTypeParmType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1363 | Replaced, (*ToReplacementTypeOrErr).getCanonicalType()); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1364 | } |
| 1365 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1366 | ExpectedType ASTNodeImporter::VisitTemplateSpecializationType( |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1367 | const TemplateSpecializationType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1368 | auto ToTemplateOrErr = import(T->getTemplateName()); |
| 1369 | if (!ToTemplateOrErr) |
| 1370 | return ToTemplateOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1371 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1372 | SmallVector<TemplateArgument, 2> ToTemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1373 | if (Error Err = ImportTemplateArguments( |
| 1374 | T->getArgs(), T->getNumArgs(), ToTemplateArgs)) |
| 1375 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1376 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1377 | QualType ToCanonType; |
| 1378 | if (!QualType(T, 0).isCanonical()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1379 | QualType FromCanonType |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1380 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1381 | if (ExpectedType TyOrErr = import(FromCanonType)) |
| 1382 | ToCanonType = *TyOrErr; |
| 1383 | else |
| 1384 | return TyOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1385 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1386 | return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr, |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 1387 | ToTemplateArgs, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1388 | ToCanonType); |
| 1389 | } |
| 1390 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1391 | ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1392 | // Note: the qualifier in an ElaboratedType is optional. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1393 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1394 | if (!ToQualifierOrErr) |
| 1395 | return ToQualifierOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1396 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1397 | ExpectedType ToNamedTypeOrErr = import(T->getNamedType()); |
| 1398 | if (!ToNamedTypeOrErr) |
| 1399 | return ToNamedTypeOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1400 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1401 | Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl()); |
| 1402 | if (!ToOwnedTagDeclOrErr) |
| 1403 | return ToOwnedTagDeclOrErr.takeError(); |
Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 1404 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1405 | return Importer.getToContext().getElaboratedType(T->getKeyword(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1406 | *ToQualifierOrErr, |
| 1407 | *ToNamedTypeOrErr, |
| 1408 | *ToOwnedTagDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1409 | } |
| 1410 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1411 | ExpectedType |
| 1412 | ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { |
| 1413 | ExpectedType ToPatternOrErr = import(T->getPattern()); |
| 1414 | if (!ToPatternOrErr) |
| 1415 | return ToPatternOrErr.takeError(); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1416 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1417 | return Importer.getToContext().getPackExpansionType(*ToPatternOrErr, |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1418 | T->getNumExpansions()); |
| 1419 | } |
| 1420 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1421 | ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType( |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1422 | const DependentTemplateSpecializationType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1423 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1424 | if (!ToQualifierOrErr) |
| 1425 | return ToQualifierOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1426 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1427 | IdentifierInfo *ToName = Importer.Import(T->getIdentifier()); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1428 | |
| 1429 | SmallVector<TemplateArgument, 2> ToPack; |
| 1430 | ToPack.reserve(T->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1431 | if (Error Err = ImportTemplateArguments( |
| 1432 | T->getArgs(), T->getNumArgs(), ToPack)) |
| 1433 | return std::move(Err); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1434 | |
| 1435 | return Importer.getToContext().getDependentTemplateSpecializationType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1436 | T->getKeyword(), *ToQualifierOrErr, ToName, ToPack); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1437 | } |
| 1438 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1439 | ExpectedType |
| 1440 | ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) { |
| 1441 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1442 | if (!ToQualifierOrErr) |
| 1443 | return ToQualifierOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1444 | |
| 1445 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); |
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 | QualType Canon; |
| 1448 | if (T != T->getCanonicalTypeInternal().getTypePtr()) { |
| 1449 | if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal())) |
| 1450 | Canon = (*TyOrErr).getCanonicalType(); |
| 1451 | else |
| 1452 | return TyOrErr.takeError(); |
| 1453 | } |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1454 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1455 | return Importer.getToContext().getDependentNameType(T->getKeyword(), |
| 1456 | *ToQualifierOrErr, |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1457 | Name, Canon); |
| 1458 | } |
| 1459 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1460 | ExpectedType |
| 1461 | ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
| 1462 | Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1463 | if (!ToDeclOrErr) |
| 1464 | return ToDeclOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1465 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1466 | return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1467 | } |
| 1468 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1469 | ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { |
| 1470 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); |
| 1471 | if (!ToBaseTypeOrErr) |
| 1472 | return ToBaseTypeOrErr.takeError(); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1473 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1474 | SmallVector<QualType, 4> TypeArgs; |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 1475 | for (auto TypeArg : T->getTypeArgsAsWritten()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1476 | if (ExpectedType TyOrErr = import(TypeArg)) |
| 1477 | TypeArgs.push_back(*TyOrErr); |
| 1478 | else |
| 1479 | return TyOrErr.takeError(); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1480 | } |
| 1481 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1482 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 1483 | for (auto *P : T->quals()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1484 | if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P)) |
| 1485 | Protocols.push_back(*ProtocolOrErr); |
| 1486 | else |
| 1487 | return ProtocolOrErr.takeError(); |
| 1488 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1489 | } |
| 1490 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1491 | return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs, |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 1492 | Protocols, |
| 1493 | T->isKindOfTypeAsWritten()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1494 | } |
| 1495 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1496 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1497 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1498 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1499 | if (!ToPointeeTypeOrErr) |
| 1500 | return ToPointeeTypeOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1501 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1502 | return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 1505 | //---------------------------------------------------------------------------- |
| 1506 | // Import Declarations |
| 1507 | //---------------------------------------------------------------------------- |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1508 | Error ASTNodeImporter::ImportDeclParts( |
| 1509 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, |
| 1510 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) { |
Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1511 | // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop. |
| 1512 | // example: int struct_in_proto(struct data_t{int a;int b;} *d); |
| 1513 | DeclContext *OrigDC = D->getDeclContext(); |
| 1514 | FunctionDecl *FunDecl; |
| 1515 | if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) && |
| 1516 | FunDecl->hasBody()) { |
Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1517 | auto getLeafPointeeType = [](const Type *T) { |
| 1518 | while (T->isPointerType() || T->isArrayType()) { |
| 1519 | T = T->getPointeeOrArrayElementType(); |
| 1520 | } |
| 1521 | return T; |
| 1522 | }; |
| 1523 | for (const ParmVarDecl *P : FunDecl->parameters()) { |
| 1524 | const Type *LeafT = |
| 1525 | getLeafPointeeType(P->getType().getCanonicalType().getTypePtr()); |
| 1526 | auto *RT = dyn_cast<RecordType>(LeafT); |
| 1527 | if (RT && RT->getDecl() == D) { |
| 1528 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 1529 | << D->getDeclKindName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1530 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1531 | } |
Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1532 | } |
| 1533 | } |
| 1534 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1535 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1536 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 1537 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1538 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1539 | // Import the name of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1540 | if (Error Err = importInto(Name, D->getDeclName())) |
| 1541 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1542 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1543 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1544 | if (Error Err = importInto(Loc, D->getLocation())) |
| 1545 | return Err; |
| 1546 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1547 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); |
Gabor Marton | be77a98 | 2018-12-12 11:22:55 +0000 | [diff] [blame] | 1548 | if (ToD) |
| 1549 | if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD)) |
| 1550 | return Err; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1551 | |
| 1552 | return Error::success(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1553 | } |
| 1554 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1555 | Error ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1556 | if (!FromD) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1557 | return Error::success(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1558 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1559 | if (!ToD) |
| 1560 | if (Error Err = importInto(ToD, FromD)) |
| 1561 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1562 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1563 | if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) { |
| 1564 | if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) { |
| 1565 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && |
| 1566 | !ToRecord->getDefinition()) { |
| 1567 | if (Error Err = ImportDefinition(FromRecord, ToRecord)) |
| 1568 | return Err; |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1569 | } |
| 1570 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1571 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1572 | } |
| 1573 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1574 | if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) { |
| 1575 | if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1576 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1577 | if (Error Err = ImportDefinition(FromEnum, ToEnum)) |
| 1578 | return Err; |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1579 | } |
| 1580 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1581 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1582 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1583 | |
| 1584 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1587 | Error |
| 1588 | ASTNodeImporter::ImportDeclarationNameLoc( |
| 1589 | const DeclarationNameInfo &From, DeclarationNameInfo& To) { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1590 | // NOTE: To.Name and To.Loc are already imported. |
| 1591 | // We only have to import To.LocInfo. |
| 1592 | switch (To.getName().getNameKind()) { |
| 1593 | case DeclarationName::Identifier: |
| 1594 | case DeclarationName::ObjCZeroArgSelector: |
| 1595 | case DeclarationName::ObjCOneArgSelector: |
| 1596 | case DeclarationName::ObjCMultiArgSelector: |
| 1597 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1598 | case DeclarationName::CXXDeductionGuideName: |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1599 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1600 | |
| 1601 | case DeclarationName::CXXOperatorName: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1602 | if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange())) |
| 1603 | To.setCXXOperatorNameRange(*ToRangeOrErr); |
| 1604 | else |
| 1605 | return ToRangeOrErr.takeError(); |
| 1606 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1607 | } |
| 1608 | case DeclarationName::CXXLiteralOperatorName: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1609 | if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc())) |
| 1610 | To.setCXXLiteralOperatorNameLoc(*LocOrErr); |
| 1611 | else |
| 1612 | return LocOrErr.takeError(); |
| 1613 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1614 | } |
| 1615 | case DeclarationName::CXXConstructorName: |
| 1616 | case DeclarationName::CXXDestructorName: |
| 1617 | case DeclarationName::CXXConversionFunctionName: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1618 | if (auto ToTInfoOrErr = import(From.getNamedTypeInfo())) |
| 1619 | To.setNamedTypeInfo(*ToTInfoOrErr); |
| 1620 | else |
| 1621 | return ToTInfoOrErr.takeError(); |
| 1622 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1623 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1624 | } |
Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 1625 | llvm_unreachable("Unknown name kind."); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1626 | } |
| 1627 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1628 | Error |
| 1629 | ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1630 | if (Importer.isMinimalImport() && !ForceImport) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1631 | auto ToDCOrErr = Importer.ImportContext(FromDC); |
| 1632 | return ToDCOrErr.takeError(); |
| 1633 | } |
Davide Italiano | 93a64ef | 2018-10-30 20:46:29 +0000 | [diff] [blame] | 1634 | llvm::SmallVector<Decl *, 8> ImportedDecls; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1635 | for (auto *From : FromDC->decls()) { |
| 1636 | ExpectedDecl ImportedOrErr = import(From); |
Davide Italiano | 93a64ef | 2018-10-30 20:46:29 +0000 | [diff] [blame] | 1637 | if (!ImportedOrErr) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1638 | // Ignore the error, continue with next Decl. |
| 1639 | // FIXME: Handle this case somehow better. |
Davide Italiano | 93a64ef | 2018-10-30 20:46:29 +0000 | [diff] [blame] | 1640 | consumeError(ImportedOrErr.takeError()); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1641 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1642 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1643 | return Error::success(); |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 1644 | } |
| 1645 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1646 | Error ASTNodeImporter::ImportDeclContext( |
| 1647 | Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) { |
| 1648 | auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext()); |
| 1649 | if (!ToDCOrErr) |
| 1650 | return ToDCOrErr.takeError(); |
| 1651 | ToDC = *ToDCOrErr; |
| 1652 | |
| 1653 | if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) { |
| 1654 | auto ToLexicalDCOrErr = Importer.ImportContext( |
| 1655 | FromD->getLexicalDeclContext()); |
| 1656 | if (!ToLexicalDCOrErr) |
| 1657 | return ToLexicalDCOrErr.takeError(); |
| 1658 | ToLexicalDC = *ToLexicalDCOrErr; |
| 1659 | } else |
| 1660 | ToLexicalDC = ToDC; |
| 1661 | |
| 1662 | return Error::success(); |
| 1663 | } |
| 1664 | |
| 1665 | Error ASTNodeImporter::ImportImplicitMethods( |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1666 | const CXXRecordDecl *From, CXXRecordDecl *To) { |
| 1667 | assert(From->isCompleteDefinition() && To->getDefinition() == To && |
| 1668 | "Import implicit methods to or from non-definition"); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1669 | |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1670 | for (CXXMethodDecl *FromM : From->methods()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1671 | if (FromM->isImplicit()) { |
| 1672 | Expected<CXXMethodDecl *> ToMOrErr = import(FromM); |
| 1673 | if (!ToMOrErr) |
| 1674 | return ToMOrErr.takeError(); |
| 1675 | } |
| 1676 | |
| 1677 | return Error::success(); |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1678 | } |
| 1679 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1680 | static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, |
| 1681 | ASTImporter &Importer) { |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1682 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 1683 | if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef)) |
Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 1684 | To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr)); |
| 1685 | else |
| 1686 | return ToTypedefOrErr.takeError(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1687 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1688 | return Error::success(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1689 | } |
| 1690 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1691 | Error ASTNodeImporter::ImportDefinition( |
| 1692 | RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1693 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1694 | if (Kind == IDK_Everything) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1695 | return ImportDeclContext(From, /*ForceImport=*/true); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1696 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1697 | return Error::success(); |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1698 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1699 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1700 | To->startDefinition(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1701 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1702 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 1703 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1704 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1705 | // Add base classes. |
Gabor Marton | 17d3967 | 2018-11-26 15:54:08 +0000 | [diff] [blame] | 1706 | auto *ToCXX = dyn_cast<CXXRecordDecl>(To); |
| 1707 | auto *FromCXX = dyn_cast<CXXRecordDecl>(From); |
| 1708 | if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) { |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1709 | |
| 1710 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); |
| 1711 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); |
| 1712 | ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1713 | ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1714 | ToData.Aggregate = FromData.Aggregate; |
| 1715 | ToData.PlainOldData = FromData.PlainOldData; |
| 1716 | ToData.Empty = FromData.Empty; |
| 1717 | ToData.Polymorphic = FromData.Polymorphic; |
| 1718 | ToData.Abstract = FromData.Abstract; |
| 1719 | ToData.IsStandardLayout = FromData.IsStandardLayout; |
Richard Smith | b6070db | 2018-04-05 18:55:37 +0000 | [diff] [blame] | 1720 | ToData.IsCXX11StandardLayout = FromData.IsCXX11StandardLayout; |
| 1721 | ToData.HasBasesWithFields = FromData.HasBasesWithFields; |
| 1722 | ToData.HasBasesWithNonStaticDataMembers = |
| 1723 | FromData.HasBasesWithNonStaticDataMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1724 | ToData.HasPrivateFields = FromData.HasPrivateFields; |
| 1725 | ToData.HasProtectedFields = FromData.HasProtectedFields; |
| 1726 | ToData.HasPublicFields = FromData.HasPublicFields; |
| 1727 | ToData.HasMutableFields = FromData.HasMutableFields; |
Richard Smith | ab44d5b | 2013-12-10 08:25:00 +0000 | [diff] [blame] | 1728 | ToData.HasVariantMembers = FromData.HasVariantMembers; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1729 | ToData.HasOnlyCMembers = FromData.HasOnlyCMembers; |
Richard Smith | e2648ba | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 1730 | ToData.HasInClassInitializer = FromData.HasInClassInitializer; |
Richard Smith | 593f993 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 1731 | ToData.HasUninitializedReferenceMember |
| 1732 | = FromData.HasUninitializedReferenceMember; |
Nico Weber | 6a6376b | 2016-02-19 01:52:46 +0000 | [diff] [blame] | 1733 | ToData.HasUninitializedFields = FromData.HasUninitializedFields; |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 1734 | ToData.HasInheritedConstructor = FromData.HasInheritedConstructor; |
| 1735 | ToData.HasInheritedAssignment = FromData.HasInheritedAssignment; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1736 | ToData.NeedOverloadResolutionForCopyConstructor |
| 1737 | = FromData.NeedOverloadResolutionForCopyConstructor; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1738 | ToData.NeedOverloadResolutionForMoveConstructor |
| 1739 | = FromData.NeedOverloadResolutionForMoveConstructor; |
| 1740 | ToData.NeedOverloadResolutionForMoveAssignment |
| 1741 | = FromData.NeedOverloadResolutionForMoveAssignment; |
| 1742 | ToData.NeedOverloadResolutionForDestructor |
| 1743 | = FromData.NeedOverloadResolutionForDestructor; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1744 | ToData.DefaultedCopyConstructorIsDeleted |
| 1745 | = FromData.DefaultedCopyConstructorIsDeleted; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1746 | ToData.DefaultedMoveConstructorIsDeleted |
| 1747 | = FromData.DefaultedMoveConstructorIsDeleted; |
| 1748 | ToData.DefaultedMoveAssignmentIsDeleted |
| 1749 | = FromData.DefaultedMoveAssignmentIsDeleted; |
| 1750 | ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1751 | ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers; |
| 1752 | ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1753 | ToData.HasConstexprNonCopyMoveConstructor |
| 1754 | = FromData.HasConstexprNonCopyMoveConstructor; |
Nico Weber | 72c57f4 | 2016-02-24 20:58:14 +0000 | [diff] [blame] | 1755 | ToData.HasDefaultedDefaultConstructor |
| 1756 | = FromData.HasDefaultedDefaultConstructor; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1757 | ToData.DefaultedDefaultConstructorIsConstexpr |
| 1758 | = FromData.DefaultedDefaultConstructorIsConstexpr; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1759 | ToData.HasConstexprDefaultConstructor |
| 1760 | = FromData.HasConstexprDefaultConstructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1761 | ToData.HasNonLiteralTypeFieldsOrBases |
| 1762 | = FromData.HasNonLiteralTypeFieldsOrBases; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1763 | // ComputedVisibleConversions not imported. |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1764 | ToData.UserProvidedDefaultConstructor |
| 1765 | = FromData.UserProvidedDefaultConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1766 | ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers; |
Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 1767 | ToData.ImplicitCopyConstructorCanHaveConstParamForVBase |
| 1768 | = FromData.ImplicitCopyConstructorCanHaveConstParamForVBase; |
| 1769 | ToData.ImplicitCopyConstructorCanHaveConstParamForNonVBase |
| 1770 | = FromData.ImplicitCopyConstructorCanHaveConstParamForNonVBase; |
Richard Smith | 1c33fe8 | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 1771 | ToData.ImplicitCopyAssignmentHasConstParam |
| 1772 | = FromData.ImplicitCopyAssignmentHasConstParam; |
| 1773 | ToData.HasDeclaredCopyConstructorWithConstParam |
| 1774 | = FromData.HasDeclaredCopyConstructorWithConstParam; |
| 1775 | ToData.HasDeclaredCopyAssignmentWithConstParam |
| 1776 | = FromData.HasDeclaredCopyAssignmentWithConstParam; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1777 | |
Shafik Yaghmour | 16b9073 | 2019-04-26 18:51:28 +0000 | [diff] [blame] | 1778 | // Copy over the data stored in RecordDeclBits |
| 1779 | ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions()); |
| 1780 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1781 | SmallVector<CXXBaseSpecifier *, 4> Bases; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1782 | for (const auto &Base1 : FromCXX->bases()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1783 | ExpectedType TyOrErr = import(Base1.getType()); |
| 1784 | if (!TyOrErr) |
| 1785 | return TyOrErr.takeError(); |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1786 | |
| 1787 | SourceLocation EllipsisLoc; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1788 | if (Base1.isPackExpansion()) { |
| 1789 | if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc())) |
| 1790 | EllipsisLoc = *LocOrErr; |
| 1791 | else |
| 1792 | return LocOrErr.takeError(); |
| 1793 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1794 | |
| 1795 | // Ensure that we have a definition for the base. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1796 | if (Error Err = |
| 1797 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl())) |
| 1798 | return Err; |
| 1799 | |
| 1800 | auto RangeOrErr = import(Base1.getSourceRange()); |
| 1801 | if (!RangeOrErr) |
| 1802 | return RangeOrErr.takeError(); |
| 1803 | |
| 1804 | auto TSIOrErr = import(Base1.getTypeSourceInfo()); |
| 1805 | if (!TSIOrErr) |
| 1806 | return TSIOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1807 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1808 | Bases.push_back( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1809 | new (Importer.getToContext()) CXXBaseSpecifier( |
| 1810 | *RangeOrErr, |
| 1811 | Base1.isVirtual(), |
| 1812 | Base1.isBaseOfClass(), |
| 1813 | Base1.getAccessSpecifierAsWritten(), |
| 1814 | *TSIOrErr, |
| 1815 | EllipsisLoc)); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1816 | } |
| 1817 | if (!Bases.empty()) |
Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1818 | ToCXX->setBases(Bases.data(), Bases.size()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1819 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1820 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1821 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1822 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 1823 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1824 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1825 | To->completeDefinition(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1826 | return Error::success(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1827 | } |
| 1828 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1829 | Error ASTNodeImporter::ImportInitializer(VarDecl *From, VarDecl *To) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1830 | if (To->getAnyInitializer()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1831 | return Error::success(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1832 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1833 | Expr *FromInit = From->getInit(); |
| 1834 | if (!FromInit) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1835 | return Error::success(); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1836 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1837 | ExpectedExpr ToInitOrErr = import(FromInit); |
| 1838 | if (!ToInitOrErr) |
| 1839 | return ToInitOrErr.takeError(); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1840 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1841 | To->setInit(*ToInitOrErr); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1842 | if (From->isInitKnownICE()) { |
| 1843 | EvaluatedStmt *Eval = To->ensureEvaluatedStmt(); |
| 1844 | Eval->CheckedICE = true; |
| 1845 | Eval->IsICE = From->isInitICE(); |
| 1846 | } |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1847 | |
| 1848 | // FIXME: Other bits to merge? |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1849 | return Error::success(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1850 | } |
| 1851 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1852 | Error ASTNodeImporter::ImportDefinition( |
| 1853 | EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1854 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1855 | if (Kind == IDK_Everything) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1856 | return ImportDeclContext(From, /*ForceImport=*/true); |
| 1857 | return Error::success(); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1858 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1859 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1860 | To->startDefinition(); |
| 1861 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1862 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 1863 | return Err; |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1864 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1865 | ExpectedType ToTypeOrErr = |
| 1866 | import(Importer.getFromContext().getTypeDeclType(From)); |
| 1867 | if (!ToTypeOrErr) |
| 1868 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1869 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1870 | ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType()); |
| 1871 | if (!ToPromotionTypeOrErr) |
| 1872 | return ToPromotionTypeOrErr.takeError(); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1873 | |
| 1874 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1875 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 1876 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1877 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1878 | // FIXME: we might need to merge the number of positive or negative bits |
| 1879 | // if the enumerator lists don't match. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1880 | To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr, |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1881 | From->getNumPositiveBits(), |
| 1882 | From->getNumNegativeBits()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1883 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1884 | } |
| 1885 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1886 | Error ASTNodeImporter::ImportTemplateArguments( |
| 1887 | const TemplateArgument *FromArgs, unsigned NumFromArgs, |
| 1888 | SmallVectorImpl<TemplateArgument> &ToArgs) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1889 | for (unsigned I = 0; I != NumFromArgs; ++I) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1890 | if (auto ToOrErr = import(FromArgs[I])) |
| 1891 | ToArgs.push_back(*ToOrErr); |
| 1892 | else |
| 1893 | return ToOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1894 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1895 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1896 | return Error::success(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1897 | } |
| 1898 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1899 | // FIXME: Do not forget to remove this and use only 'import'. |
| 1900 | Expected<TemplateArgument> |
| 1901 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { |
| 1902 | return import(From); |
| 1903 | } |
| 1904 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1905 | template <typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1906 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1907 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { |
| 1908 | for (const auto &FromLoc : Container) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1909 | if (auto ToLocOrErr = import(FromLoc)) |
| 1910 | ToTAInfo.addArgument(*ToLocOrErr); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1911 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1912 | return ToLocOrErr.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1913 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1914 | return Error::success(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1915 | } |
| 1916 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1917 | static StructuralEquivalenceKind |
| 1918 | getStructuralEquivalenceKind(const ASTImporter &Importer) { |
| 1919 | return Importer.isMinimalImport() ? StructuralEquivalenceKind::Minimal |
| 1920 | : StructuralEquivalenceKind::Default; |
| 1921 | } |
| 1922 | |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1923 | bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) { |
| 1924 | StructuralEquivalenceContext Ctx( |
| 1925 | Importer.getFromContext(), Importer.getToContext(), |
| 1926 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1927 | false, Complain); |
| 1928 | return Ctx.IsEquivalent(From, To); |
| 1929 | } |
| 1930 | |
| 1931 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1932 | RecordDecl *ToRecord, bool Complain) { |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1933 | // Eliminate a potential failure point where we attempt to re-import |
| 1934 | // something we're trying to import while completing ToRecord. |
| 1935 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); |
| 1936 | if (ToOrigin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1937 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1938 | if (ToOriginRecord) |
| 1939 | ToRecord = ToOriginRecord; |
| 1940 | } |
| 1941 | |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1942 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1943 | ToRecord->getASTContext(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1944 | Importer.getNonEquivalentDecls(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1945 | getStructuralEquivalenceKind(Importer), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1946 | false, Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1947 | return Ctx.IsEquivalent(FromRecord, ToRecord); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1948 | } |
| 1949 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1950 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 1951 | bool Complain) { |
| 1952 | StructuralEquivalenceContext Ctx( |
| 1953 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1954 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1955 | false, Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1956 | return Ctx.IsEquivalent(FromVar, ToVar); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1957 | } |
| 1958 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1959 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { |
Shafik Yaghmour | e5094d6 | 2019-03-27 17:47:36 +0000 | [diff] [blame] | 1960 | // Eliminate a potential failure point where we attempt to re-import |
Raphael Isemann | fa26c20 | 2019-04-09 14:18:23 +0000 | [diff] [blame] | 1961 | // something we're trying to import while completing ToEnum. |
Shafik Yaghmour | e5094d6 | 2019-03-27 17:47:36 +0000 | [diff] [blame] | 1962 | if (Decl *ToOrigin = Importer.GetOriginalDecl(ToEnum)) |
| 1963 | if (auto *ToOriginEnum = dyn_cast<EnumDecl>(ToOrigin)) |
| 1964 | ToEnum = ToOriginEnum; |
| 1965 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1966 | StructuralEquivalenceContext Ctx( |
| 1967 | Importer.getFromContext(), Importer.getToContext(), |
| 1968 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1969 | return Ctx.IsEquivalent(FromEnum, ToEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1970 | } |
| 1971 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1972 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, |
| 1973 | FunctionTemplateDecl *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); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1979 | } |
| 1980 | |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 1981 | bool ASTNodeImporter::IsStructuralMatch(FunctionDecl *From, FunctionDecl *To) { |
| 1982 | StructuralEquivalenceContext Ctx( |
| 1983 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1984 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1985 | false, false); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1986 | return Ctx.IsEquivalent(From, To); |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 1987 | } |
| 1988 | |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1989 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1990 | EnumConstantDecl *ToEC) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1991 | const llvm::APSInt &FromVal = FromEC->getInitVal(); |
| 1992 | const llvm::APSInt &ToVal = ToEC->getInitVal(); |
| 1993 | |
| 1994 | return FromVal.isSigned() == ToVal.isSigned() && |
| 1995 | FromVal.getBitWidth() == ToVal.getBitWidth() && |
| 1996 | FromVal == ToVal; |
| 1997 | } |
| 1998 | |
| 1999 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2000 | ClassTemplateDecl *To) { |
| 2001 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2002 | Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2003 | Importer.getNonEquivalentDecls(), |
| 2004 | getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2005 | return Ctx.IsEquivalent(From, To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2006 | } |
| 2007 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2008 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, |
| 2009 | VarTemplateDecl *To) { |
| 2010 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2011 | Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2012 | Importer.getNonEquivalentDecls(), |
| 2013 | getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2014 | return Ctx.IsEquivalent(From, To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2015 | } |
| 2016 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2017 | ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 2018 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2019 | << D->getDeclKindName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2020 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2021 | } |
| 2022 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2023 | ExpectedDecl ASTNodeImporter::VisitImportDecl(ImportDecl *D) { |
| 2024 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 2025 | << D->getDeclKindName(); |
| 2026 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| 2027 | } |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2028 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2029 | ExpectedDecl ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { |
| 2030 | // Import the context of this declaration. |
| 2031 | DeclContext *DC, *LexicalDC; |
| 2032 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 2033 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2034 | |
| 2035 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2036 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2037 | if (!LocOrErr) |
| 2038 | return LocOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2039 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2040 | EmptyDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2041 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2042 | return ToD; |
| 2043 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2044 | ToD->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2045 | LexicalDC->addDeclInternal(ToD); |
| 2046 | return ToD; |
| 2047 | } |
| 2048 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2049 | ExpectedDecl ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2050 | TranslationUnitDecl *ToD = |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2051 | Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2052 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2053 | Importer.MapImported(D, ToD); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2054 | |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2055 | return ToD; |
| 2056 | } |
| 2057 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2058 | ExpectedDecl ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
| 2059 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2060 | if (!LocOrErr) |
| 2061 | return LocOrErr.takeError(); |
| 2062 | auto ColonLocOrErr = import(D->getColonLoc()); |
| 2063 | if (!ColonLocOrErr) |
| 2064 | return ColonLocOrErr.takeError(); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2065 | |
| 2066 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2067 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2068 | if (!DCOrErr) |
| 2069 | return DCOrErr.takeError(); |
| 2070 | DeclContext *DC = *DCOrErr; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2071 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2072 | AccessSpecDecl *ToD; |
| 2073 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2074 | DC, *LocOrErr, *ColonLocOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2075 | return ToD; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2076 | |
| 2077 | // Lexical DeclContext and Semantic DeclContext |
| 2078 | // is always the same for the accessSpec. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2079 | ToD->setLexicalDeclContext(DC); |
| 2080 | DC->addDeclInternal(ToD); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2081 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2082 | return ToD; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2083 | } |
| 2084 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2085 | ExpectedDecl ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 2086 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2087 | if (!DCOrErr) |
| 2088 | return DCOrErr.takeError(); |
| 2089 | DeclContext *DC = *DCOrErr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2090 | DeclContext *LexicalDC = DC; |
| 2091 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2092 | SourceLocation ToLocation, ToRParenLoc; |
| 2093 | Expr *ToAssertExpr; |
| 2094 | StringLiteral *ToMessage; |
| 2095 | if (auto Imp = importSeq( |
| 2096 | D->getLocation(), D->getAssertExpr(), D->getMessage(), D->getRParenLoc())) |
| 2097 | std::tie(ToLocation, ToAssertExpr, ToMessage, ToRParenLoc) = *Imp; |
| 2098 | else |
| 2099 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2100 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2101 | StaticAssertDecl *ToD; |
| 2102 | if (GetImportedOrCreateDecl( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2103 | ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage, |
| 2104 | ToRParenLoc, D->isFailed())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2105 | return ToD; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2106 | |
| 2107 | ToD->setLexicalDeclContext(LexicalDC); |
| 2108 | LexicalDC->addDeclInternal(ToD); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2109 | return ToD; |
| 2110 | } |
| 2111 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2112 | ExpectedDecl ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2113 | // Import the major distinguishing characteristics of this namespace. |
| 2114 | DeclContext *DC, *LexicalDC; |
| 2115 | DeclarationName Name; |
| 2116 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2117 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2118 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2119 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2120 | if (ToD) |
| 2121 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2122 | |
| 2123 | NamespaceDecl *MergeWithNamespace = nullptr; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2124 | if (!Name) { |
| 2125 | // This is an anonymous namespace. Adopt an existing anonymous |
| 2126 | // namespace if we can. |
| 2127 | // FIXME: Not testable. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2128 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2129 | MergeWithNamespace = TU->getAnonymousNamespace(); |
| 2130 | else |
| 2131 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); |
| 2132 | } else { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2133 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2134 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2135 | for (auto *FoundDecl : FoundDecls) { |
| 2136 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2137 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2138 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2139 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2140 | MergeWithNamespace = FoundNS; |
| 2141 | ConflictingDecls.clear(); |
| 2142 | break; |
| 2143 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2144 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2145 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2146 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2147 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2148 | if (!ConflictingDecls.empty()) { |
John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 2149 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2150 | ConflictingDecls.data(), |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2151 | ConflictingDecls.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2152 | if (!Name) |
| 2153 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2154 | } |
| 2155 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2156 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2157 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2158 | if (!BeginLocOrErr) |
| 2159 | return BeginLocOrErr.takeError(); |
| 2160 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2161 | // Create the "to" namespace, if needed. |
| 2162 | NamespaceDecl *ToNamespace = MergeWithNamespace; |
| 2163 | if (!ToNamespace) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2164 | if (GetImportedOrCreateDecl( |
| 2165 | ToNamespace, D, Importer.getToContext(), DC, D->isInline(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2166 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2167 | /*PrevDecl=*/nullptr)) |
| 2168 | return ToNamespace; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2169 | ToNamespace->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2170 | LexicalDC->addDeclInternal(ToNamespace); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2171 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2172 | // If this is an anonymous namespace, register it as the anonymous |
| 2173 | // namespace within its context. |
| 2174 | if (!Name) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2175 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2176 | TU->setAnonymousNamespace(ToNamespace); |
| 2177 | else |
| 2178 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); |
| 2179 | } |
| 2180 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2181 | Importer.MapImported(D, ToNamespace); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2182 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2183 | if (Error Err = ImportDeclContext(D)) |
| 2184 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2185 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2186 | return ToNamespace; |
| 2187 | } |
| 2188 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2189 | ExpectedDecl ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2190 | // Import the major distinguishing characteristics of this namespace. |
| 2191 | DeclContext *DC, *LexicalDC; |
| 2192 | DeclarationName Name; |
| 2193 | SourceLocation Loc; |
| 2194 | NamedDecl *LookupD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2195 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) |
| 2196 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2197 | if (LookupD) |
| 2198 | return LookupD; |
| 2199 | |
| 2200 | // NOTE: No conflict resolution is done for namespace aliases now. |
| 2201 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2202 | SourceLocation ToNamespaceLoc, ToAliasLoc, ToTargetNameLoc; |
| 2203 | NestedNameSpecifierLoc ToQualifierLoc; |
| 2204 | NamespaceDecl *ToNamespace; |
| 2205 | if (auto Imp = importSeq( |
| 2206 | D->getNamespaceLoc(), D->getAliasLoc(), D->getQualifierLoc(), |
| 2207 | D->getTargetNameLoc(), D->getNamespace())) |
| 2208 | std::tie( |
| 2209 | ToNamespaceLoc, ToAliasLoc, ToQualifierLoc, ToTargetNameLoc, |
| 2210 | ToNamespace) = *Imp; |
| 2211 | else |
| 2212 | return Imp.takeError(); |
| 2213 | IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier()); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2214 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2215 | NamespaceAliasDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2216 | if (GetImportedOrCreateDecl( |
| 2217 | ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc, |
| 2218 | ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2219 | return ToD; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2220 | |
| 2221 | ToD->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2222 | LexicalDC->addDeclInternal(ToD); |
| 2223 | |
| 2224 | return ToD; |
| 2225 | } |
| 2226 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2227 | ExpectedDecl |
| 2228 | ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2229 | // Import the major distinguishing characteristics of this typedef. |
| 2230 | DeclContext *DC, *LexicalDC; |
| 2231 | DeclarationName Name; |
| 2232 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2233 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2234 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2235 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2236 | if (ToD) |
| 2237 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2238 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2239 | // If this typedef is not in block scope, determine whether we've |
| 2240 | // seen a typedef with the same name (that we can merge with) or any |
| 2241 | // other entity by that name (which name lookup could conflict with). |
| 2242 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2243 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2244 | unsigned IDNS = Decl::IDNS_Ordinary; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2245 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2246 | for (auto *FoundDecl : FoundDecls) { |
| 2247 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2248 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2249 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2250 | QualType FromUT = D->getUnderlyingType(); |
| 2251 | QualType FoundUT = FoundTypedef->getUnderlyingType(); |
| 2252 | if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) { |
| 2253 | // If the "From" context has a complete underlying type but we |
| 2254 | // already have a complete underlying type then return with that. |
| 2255 | if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2256 | return Importer.MapImported(D, FoundTypedef); |
Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2257 | } |
Gabor Marton | dd2b76e | 2019-06-11 13:35:25 +0000 | [diff] [blame] | 2258 | // FIXME Handle redecl chain. When you do that make consistent changes |
| 2259 | // in ASTImporterLookupTable too. |
Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2260 | break; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2261 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2262 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2263 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2264 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2265 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2266 | if (!ConflictingDecls.empty()) { |
| 2267 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2268 | ConflictingDecls.data(), |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2269 | ConflictingDecls.size()); |
| 2270 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2271 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2272 | } |
| 2273 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2274 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2275 | QualType ToUnderlyingType; |
| 2276 | TypeSourceInfo *ToTypeSourceInfo; |
| 2277 | SourceLocation ToBeginLoc; |
| 2278 | if (auto Imp = importSeq( |
| 2279 | D->getUnderlyingType(), D->getTypeSourceInfo(), D->getBeginLoc())) |
| 2280 | std::tie(ToUnderlyingType, ToTypeSourceInfo, ToBeginLoc) = *Imp; |
| 2281 | else |
| 2282 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2283 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2284 | // Create the new typedef node. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2285 | // FIXME: ToUnderlyingType is not used. |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2286 | TypedefNameDecl *ToTypedef; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2287 | if (IsAlias) { |
| 2288 | if (GetImportedOrCreateDecl<TypeAliasDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2289 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2290 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2291 | return ToTypedef; |
| 2292 | } else if (GetImportedOrCreateDecl<TypedefDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2293 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2294 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2295 | return ToTypedef; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2296 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2297 | ToTypedef->setAccess(D->getAccess()); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2298 | ToTypedef->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2299 | |
| 2300 | // Templated declarations should not appear in DeclContext. |
| 2301 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; |
| 2302 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) |
| 2303 | LexicalDC->addDeclInternal(ToTypedef); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2304 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2305 | return ToTypedef; |
| 2306 | } |
| 2307 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2308 | ExpectedDecl ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2309 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); |
| 2310 | } |
| 2311 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2312 | ExpectedDecl ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2313 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); |
| 2314 | } |
| 2315 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2316 | ExpectedDecl |
| 2317 | ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2318 | // Import the major distinguishing characteristics of this typedef. |
| 2319 | DeclContext *DC, *LexicalDC; |
| 2320 | DeclarationName Name; |
| 2321 | SourceLocation Loc; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2322 | NamedDecl *FoundD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2323 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) |
| 2324 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2325 | if (FoundD) |
| 2326 | return FoundD; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2327 | |
| 2328 | // If this typedef is not in block scope, determine whether we've |
| 2329 | // seen a typedef with the same name (that we can merge with) or any |
| 2330 | // other entity by that name (which name lookup could conflict with). |
| 2331 | if (!DC->isFunctionOrMethod()) { |
| 2332 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 2333 | unsigned IDNS = Decl::IDNS_Ordinary; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2334 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2335 | for (auto *FoundDecl : FoundDecls) { |
| 2336 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2337 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2338 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2339 | return Importer.MapImported(D, FoundAlias); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2340 | ConflictingDecls.push_back(FoundDecl); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2341 | } |
| 2342 | |
| 2343 | if (!ConflictingDecls.empty()) { |
| 2344 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2345 | ConflictingDecls.data(), |
| 2346 | ConflictingDecls.size()); |
| 2347 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2348 | return make_error<ImportError>(ImportError::NameConflict); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2349 | } |
| 2350 | } |
| 2351 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2352 | TemplateParameterList *ToTemplateParameters; |
| 2353 | TypeAliasDecl *ToTemplatedDecl; |
| 2354 | if (auto Imp = importSeq(D->getTemplateParameters(), D->getTemplatedDecl())) |
| 2355 | std::tie(ToTemplateParameters, ToTemplatedDecl) = *Imp; |
| 2356 | else |
| 2357 | return Imp.takeError(); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2358 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2359 | TypeAliasTemplateDecl *ToAlias; |
| 2360 | if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2361 | Name, ToTemplateParameters, ToTemplatedDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2362 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2363 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2364 | ToTemplatedDecl->setDescribedAliasTemplate(ToAlias); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2365 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2366 | ToAlias->setAccess(D->getAccess()); |
| 2367 | ToAlias->setLexicalDeclContext(LexicalDC); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2368 | LexicalDC->addDeclInternal(ToAlias); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2369 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2370 | } |
| 2371 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2372 | ExpectedDecl ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2373 | // Import the major distinguishing characteristics of this label. |
| 2374 | DeclContext *DC, *LexicalDC; |
| 2375 | DeclarationName Name; |
| 2376 | SourceLocation Loc; |
| 2377 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2378 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2379 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2380 | if (ToD) |
| 2381 | return ToD; |
| 2382 | |
| 2383 | assert(LexicalDC->isFunctionOrMethod()); |
| 2384 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2385 | LabelDecl *ToLabel; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2386 | if (D->isGnuLocal()) { |
| 2387 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2388 | if (!BeginLocOrErr) |
| 2389 | return BeginLocOrErr.takeError(); |
| 2390 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2391 | Name.getAsIdentifierInfo(), *BeginLocOrErr)) |
| 2392 | return ToLabel; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2393 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2394 | } else { |
| 2395 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2396 | Name.getAsIdentifierInfo())) |
| 2397 | return ToLabel; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2398 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2399 | } |
| 2400 | |
| 2401 | Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt()); |
| 2402 | if (!ToStmtOrErr) |
| 2403 | return ToStmtOrErr.takeError(); |
| 2404 | |
| 2405 | ToLabel->setStmt(*ToStmtOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2406 | ToLabel->setLexicalDeclContext(LexicalDC); |
| 2407 | LexicalDC->addDeclInternal(ToLabel); |
| 2408 | return ToLabel; |
| 2409 | } |
| 2410 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2411 | ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2412 | // Import the major distinguishing characteristics of this enum. |
| 2413 | DeclContext *DC, *LexicalDC; |
| 2414 | DeclarationName Name; |
| 2415 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2416 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2417 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2418 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2419 | if (ToD) |
| 2420 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2421 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2422 | // Figure out what enum name we're looking for. |
| 2423 | unsigned IDNS = Decl::IDNS_Tag; |
| 2424 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2425 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2426 | if (Error Err = importInto( |
| 2427 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2428 | return std::move(Err); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2429 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2430 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2431 | IDNS |= Decl::IDNS_Ordinary; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2432 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2433 | // We may already have an enum of the same name; try to find and match it. |
| 2434 | if (!DC->isFunctionOrMethod() && SearchName) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2435 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2436 | auto FoundDecls = |
| 2437 | Importer.findDeclsInToCtx(DC, SearchName); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2438 | for (auto *FoundDecl : FoundDecls) { |
| 2439 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2440 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2441 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2442 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2443 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2444 | FoundDecl = Tag->getDecl(); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2445 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2446 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2447 | if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) { |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2448 | if (IsStructuralMatch(D, FoundEnum)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2449 | return Importer.MapImported(D, FoundEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2450 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2451 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2452 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2453 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2454 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2455 | if (!ConflictingDecls.empty()) { |
Shafik Yaghmour | d426312 | 2019-04-08 20:50:21 +0000 | [diff] [blame] | 2456 | Name = Importer.HandleNameConflict(SearchName, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2457 | ConflictingDecls.data(), |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2458 | ConflictingDecls.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2459 | if (!Name) |
| 2460 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2461 | } |
| 2462 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2463 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2464 | SourceLocation ToBeginLoc; |
| 2465 | NestedNameSpecifierLoc ToQualifierLoc; |
| 2466 | QualType ToIntegerType; |
| 2467 | if (auto Imp = importSeq( |
| 2468 | D->getBeginLoc(), D->getQualifierLoc(), D->getIntegerType())) |
| 2469 | std::tie(ToBeginLoc, ToQualifierLoc, ToIntegerType) = *Imp; |
| 2470 | else |
| 2471 | return Imp.takeError(); |
| 2472 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2473 | // Create the enum declaration. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2474 | EnumDecl *D2; |
| 2475 | if (GetImportedOrCreateDecl( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2476 | D2, D, Importer.getToContext(), DC, ToBeginLoc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2477 | Loc, Name.getAsIdentifierInfo(), nullptr, D->isScoped(), |
| 2478 | D->isScopedUsingClassTag(), D->isFixed())) |
| 2479 | return D2; |
| 2480 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2481 | D2->setQualifierInfo(ToQualifierLoc); |
| 2482 | D2->setIntegerType(ToIntegerType); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2483 | D2->setAccess(D->getAccess()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2484 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2485 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2486 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2487 | // Import the definition |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2488 | if (D->isCompleteDefinition()) |
| 2489 | if (Error Err = ImportDefinition(D, D2)) |
| 2490 | return std::move(Err); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2491 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2492 | return D2; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2493 | } |
| 2494 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2495 | ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2496 | bool IsFriendTemplate = false; |
| 2497 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2498 | IsFriendTemplate = |
| 2499 | DCXX->getDescribedClassTemplate() && |
| 2500 | DCXX->getDescribedClassTemplate()->getFriendObjectKind() != |
| 2501 | Decl::FOK_None; |
| 2502 | } |
| 2503 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2504 | // Import the major distinguishing characteristics of this record. |
| 2505 | DeclContext *DC, *LexicalDC; |
| 2506 | DeclarationName Name; |
| 2507 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2508 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2509 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2510 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2511 | if (ToD) |
| 2512 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2513 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2514 | // Figure out what structure name we're looking for. |
| 2515 | unsigned IDNS = Decl::IDNS_Tag; |
| 2516 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2517 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2518 | if (Error Err = importInto( |
| 2519 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2520 | return std::move(Err); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2521 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2522 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2523 | IDNS |= Decl::IDNS_Ordinary | Decl::IDNS_TagFriend; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2524 | |
| 2525 | // 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] | 2526 | RecordDecl *PrevDecl = nullptr; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2527 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2528 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2529 | auto FoundDecls = |
| 2530 | Importer.findDeclsInToCtx(DC, SearchName); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2531 | if (!FoundDecls.empty()) { |
Gabor Marton | 41e3892 | 2019-03-05 11:23:24 +0000 | [diff] [blame] | 2532 | // We're going to have to compare D against potentially conflicting Decls, |
| 2533 | // so complete it. |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2534 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) |
| 2535 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 2536 | } |
| 2537 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2538 | for (auto *FoundDecl : FoundDecls) { |
| 2539 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2540 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2541 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2542 | Decl *Found = FoundDecl; |
| 2543 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 2544 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2545 | Found = Tag->getDecl(); |
| 2546 | } |
Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2547 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2548 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2549 | // Do not emit false positive diagnostic in case of unnamed |
| 2550 | // struct/union and in case of anonymous structs. Would be false |
| 2551 | // because there may be several anonymous/unnamed structs in a class. |
| 2552 | // E.g. these are both valid: |
| 2553 | // struct A { // unnamed structs |
| 2554 | // struct { struct A *next; } entry0; |
| 2555 | // struct { struct A *next; } entry1; |
| 2556 | // }; |
| 2557 | // struct X { struct { int a; }; struct { int b; }; }; // anon structs |
| 2558 | if (!SearchName) |
Gabor Marton | 0bebf95 | 2018-07-05 09:51:13 +0000 | [diff] [blame] | 2559 | if (!IsStructuralMatch(D, FoundRecord, false)) |
| 2560 | continue; |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2561 | |
Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 2562 | if (!hasSameVisibilityContext(FoundRecord, D)) |
| 2563 | continue; |
| 2564 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2565 | if (IsStructuralMatch(D, FoundRecord)) { |
| 2566 | RecordDecl *FoundDef = FoundRecord->getDefinition(); |
| 2567 | if (D->isThisDeclarationADefinition() && FoundDef) { |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2568 | // FIXME: Structural equivalence check should check for same |
| 2569 | // user-defined methods. |
| 2570 | Importer.MapImported(D, FoundDef); |
| 2571 | if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2572 | auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef); |
| 2573 | assert(FoundCXX && "Record type mismatch"); |
| 2574 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2575 | if (!Importer.isMinimalImport()) |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2576 | // FoundDef may not have every implicit method that D has |
| 2577 | // because implicit methods are created only if they are used. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2578 | if (Error Err = ImportImplicitMethods(DCXX, FoundCXX)) |
| 2579 | return std::move(Err); |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2580 | } |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2581 | } |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2582 | PrevDecl = FoundRecord->getMostRecentDecl(); |
| 2583 | break; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2584 | } |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2585 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2586 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2587 | ConflictingDecls.push_back(FoundDecl); |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2588 | } // for |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2589 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2590 | if (!ConflictingDecls.empty() && SearchName) { |
Shafik Yaghmour | 468724e | 2019-05-24 16:53:44 +0000 | [diff] [blame] | 2591 | Name = Importer.HandleNameConflict(SearchName, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2592 | ConflictingDecls.data(), |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2593 | ConflictingDecls.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2594 | if (!Name) |
| 2595 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2596 | } |
| 2597 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2598 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2599 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2600 | if (!BeginLocOrErr) |
| 2601 | return BeginLocOrErr.takeError(); |
| 2602 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2603 | // Create the record declaration. |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2604 | RecordDecl *D2 = nullptr; |
| 2605 | CXXRecordDecl *D2CXX = nullptr; |
| 2606 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2607 | if (DCXX->isLambda()) { |
| 2608 | auto TInfoOrErr = import(DCXX->getLambdaTypeInfo()); |
| 2609 | if (!TInfoOrErr) |
| 2610 | return TInfoOrErr.takeError(); |
| 2611 | if (GetImportedOrCreateSpecialDecl( |
| 2612 | D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(), |
| 2613 | DC, *TInfoOrErr, Loc, DCXX->isDependentLambda(), |
| 2614 | DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault())) |
| 2615 | return D2CXX; |
| 2616 | ExpectedDecl CDeclOrErr = import(DCXX->getLambdaContextDecl()); |
| 2617 | if (!CDeclOrErr) |
| 2618 | return CDeclOrErr.takeError(); |
| 2619 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), *CDeclOrErr); |
| 2620 | } else if (DCXX->isInjectedClassName()) { |
| 2621 | // We have to be careful to do a similar dance to the one in |
| 2622 | // Sema::ActOnStartCXXMemberDeclarations |
| 2623 | const bool DelayTypeCreation = true; |
| 2624 | if (GetImportedOrCreateDecl( |
| 2625 | D2CXX, D, Importer.getToContext(), D->getTagKind(), DC, |
| 2626 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), |
| 2627 | cast_or_null<CXXRecordDecl>(PrevDecl), DelayTypeCreation)) |
| 2628 | return D2CXX; |
| 2629 | Importer.getToContext().getTypeDeclType( |
| 2630 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); |
| 2631 | } else { |
| 2632 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), |
| 2633 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
| 2634 | Name.getAsIdentifierInfo(), |
| 2635 | cast_or_null<CXXRecordDecl>(PrevDecl))) |
| 2636 | return D2CXX; |
| 2637 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2638 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2639 | D2 = D2CXX; |
| 2640 | D2->setAccess(D->getAccess()); |
| 2641 | D2->setLexicalDeclContext(LexicalDC); |
| 2642 | if (!DCXX->getDescribedClassTemplate() || DCXX->isImplicit()) |
| 2643 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2644 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2645 | if (LexicalDC != DC && D->isInIdentifierNamespace(Decl::IDNS_TagFriend)) |
| 2646 | DC->makeDeclVisibleInContext(D2); |
| 2647 | |
| 2648 | if (ClassTemplateDecl *FromDescribed = |
| 2649 | DCXX->getDescribedClassTemplate()) { |
| 2650 | ClassTemplateDecl *ToDescribed; |
| 2651 | if (Error Err = importInto(ToDescribed, FromDescribed)) |
| 2652 | return std::move(Err); |
| 2653 | D2CXX->setDescribedClassTemplate(ToDescribed); |
| 2654 | if (!DCXX->isInjectedClassName() && !IsFriendTemplate) { |
| 2655 | // In a record describing a template the type should be an |
| 2656 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the |
| 2657 | // previously set type to the correct value here (ToDescribed is not |
| 2658 | // available at record create). |
| 2659 | // FIXME: The previous type is cleared but not removed from |
| 2660 | // ASTContext's internal storage. |
| 2661 | CXXRecordDecl *Injected = nullptr; |
| 2662 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { |
| 2663 | auto *Record = dyn_cast<CXXRecordDecl>(Found); |
| 2664 | if (Record && Record->isInjectedClassName()) { |
| 2665 | Injected = Record; |
| 2666 | break; |
Gabor Marton | 5915777e | 2018-06-26 13:44:24 +0000 | [diff] [blame] | 2667 | } |
| 2668 | } |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2669 | // Create an injected type for the whole redecl chain. |
| 2670 | SmallVector<Decl *, 2> Redecls = |
| 2671 | getCanonicalForwardRedeclChain(D2CXX); |
| 2672 | for (auto *R : Redecls) { |
| 2673 | auto *RI = cast<CXXRecordDecl>(R); |
| 2674 | RI->setTypeForDecl(nullptr); |
| 2675 | // Below we create a new injected type and assign that to the |
| 2676 | // canonical decl, subsequent declarations in the chain will reuse |
| 2677 | // that type. |
| 2678 | Importer.getToContext().getInjectedClassNameType( |
| 2679 | RI, ToDescribed->getInjectedClassNameSpecialization()); |
| 2680 | } |
| 2681 | // Set the new type for the previous injected decl too. |
| 2682 | if (Injected) { |
| 2683 | Injected->setTypeForDecl(nullptr); |
| 2684 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); |
| 2685 | } |
| 2686 | } |
| 2687 | } else if (MemberSpecializationInfo *MemberInfo = |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2688 | DCXX->getMemberSpecializationInfo()) { |
| 2689 | TemplateSpecializationKind SK = |
| 2690 | MemberInfo->getTemplateSpecializationKind(); |
| 2691 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2692 | |
| 2693 | if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst)) |
| 2694 | D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK); |
| 2695 | else |
| 2696 | return ToInstOrErr.takeError(); |
| 2697 | |
| 2698 | if (ExpectedSLoc POIOrErr = |
| 2699 | import(MemberInfo->getPointOfInstantiation())) |
| 2700 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( |
| 2701 | *POIOrErr); |
| 2702 | else |
| 2703 | return POIOrErr.takeError(); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2704 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2705 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2706 | } else { |
| 2707 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), |
| 2708 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
| 2709 | Name.getAsIdentifierInfo(), PrevDecl)) |
| 2710 | return D2; |
| 2711 | D2->setLexicalDeclContext(LexicalDC); |
| 2712 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2713 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2714 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2715 | if (auto QualifierLocOrErr = import(D->getQualifierLoc())) |
| 2716 | D2->setQualifierInfo(*QualifierLocOrErr); |
| 2717 | else |
| 2718 | return QualifierLocOrErr.takeError(); |
| 2719 | |
| 2720 | if (D->isAnonymousStructOrUnion()) |
| 2721 | D2->setAnonymousStructOrUnion(true); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2722 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2723 | if (D->isCompleteDefinition()) |
| 2724 | if (Error Err = ImportDefinition(D, D2, IDK_Default)) |
| 2725 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2726 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2727 | return D2; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2728 | } |
| 2729 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2730 | ExpectedDecl ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2731 | // Import the major distinguishing characteristics of this enumerator. |
| 2732 | DeclContext *DC, *LexicalDC; |
| 2733 | DeclarationName Name; |
| 2734 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2735 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2736 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2737 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2738 | if (ToD) |
| 2739 | return ToD; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2740 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2741 | // Determine whether there are any other declarations with the same name and |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2742 | // in the same context. |
| 2743 | if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2744 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2745 | unsigned IDNS = Decl::IDNS_Ordinary; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2746 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2747 | for (auto *FoundDecl : FoundDecls) { |
| 2748 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2749 | continue; |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2750 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2751 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2752 | if (IsStructuralMatch(D, FoundEnumConstant)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2753 | return Importer.MapImported(D, FoundEnumConstant); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2754 | } |
| 2755 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2756 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2757 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2758 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2759 | if (!ConflictingDecls.empty()) { |
| 2760 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2761 | ConflictingDecls.data(), |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2762 | ConflictingDecls.size()); |
| 2763 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2764 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2765 | } |
| 2766 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2767 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2768 | ExpectedType TypeOrErr = import(D->getType()); |
| 2769 | if (!TypeOrErr) |
| 2770 | return TypeOrErr.takeError(); |
| 2771 | |
| 2772 | ExpectedExpr InitOrErr = import(D->getInitExpr()); |
| 2773 | if (!InitOrErr) |
| 2774 | return InitOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2775 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2776 | EnumConstantDecl *ToEnumerator; |
| 2777 | if (GetImportedOrCreateDecl( |
| 2778 | ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2779 | Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2780 | return ToEnumerator; |
| 2781 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2782 | ToEnumerator->setAccess(D->getAccess()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2783 | ToEnumerator->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2784 | LexicalDC->addDeclInternal(ToEnumerator); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2785 | return ToEnumerator; |
| 2786 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2787 | |
Balazs Keri | 1efc974 | 2019-05-07 10:55:11 +0000 | [diff] [blame] | 2788 | Error ASTNodeImporter::ImportTemplateParameterLists(const DeclaratorDecl *FromD, |
| 2789 | DeclaratorDecl *ToD) { |
| 2790 | unsigned int Num = FromD->getNumTemplateParameterLists(); |
| 2791 | if (Num == 0) |
| 2792 | return Error::success(); |
| 2793 | SmallVector<TemplateParameterList *, 2> ToTPLists(Num); |
| 2794 | for (unsigned int I = 0; I < Num; ++I) |
| 2795 | if (Expected<TemplateParameterList *> ToTPListOrErr = |
| 2796 | import(FromD->getTemplateParameterList(I))) |
| 2797 | ToTPLists[I] = *ToTPListOrErr; |
| 2798 | else |
| 2799 | return ToTPListOrErr.takeError(); |
| 2800 | ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists); |
| 2801 | return Error::success(); |
| 2802 | } |
| 2803 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2804 | Error ASTNodeImporter::ImportTemplateInformation( |
| 2805 | FunctionDecl *FromFD, FunctionDecl *ToFD) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2806 | switch (FromFD->getTemplatedKind()) { |
| 2807 | case FunctionDecl::TK_NonTemplate: |
| 2808 | case FunctionDecl::TK_FunctionTemplate: |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2809 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2810 | |
| 2811 | case FunctionDecl::TK_MemberSpecialization: { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2812 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2813 | |
| 2814 | if (Expected<FunctionDecl *> InstFDOrErr = |
| 2815 | import(FromFD->getInstantiatedFromMemberFunction())) |
| 2816 | ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK); |
| 2817 | else |
| 2818 | return InstFDOrErr.takeError(); |
| 2819 | |
| 2820 | if (ExpectedSLoc POIOrErr = import( |
| 2821 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation())) |
| 2822 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr); |
| 2823 | else |
| 2824 | return POIOrErr.takeError(); |
| 2825 | |
| 2826 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2827 | } |
| 2828 | |
| 2829 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2830 | auto FunctionAndArgsOrErr = |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2831 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2832 | if (!FunctionAndArgsOrErr) |
| 2833 | return FunctionAndArgsOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2834 | |
| 2835 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2836 | Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr)); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2837 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2838 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2839 | TemplateArgumentListInfo ToTAInfo; |
| 2840 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2841 | if (FromTAArgsAsWritten) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2842 | if (Error Err = ImportTemplateArgumentListInfo( |
| 2843 | *FromTAArgsAsWritten, ToTAInfo)) |
| 2844 | return Err; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2845 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2846 | ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation()); |
| 2847 | if (!POIOrErr) |
| 2848 | return POIOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2849 | |
Balazs Keri | 1efc974 | 2019-05-07 10:55:11 +0000 | [diff] [blame] | 2850 | if (Error Err = ImportTemplateParameterLists(FromFD, ToFD)) |
| 2851 | return Err; |
| 2852 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2853 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2854 | ToFD->setFunctionTemplateSpecialization( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2855 | std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr, |
| 2856 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr); |
| 2857 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2858 | } |
| 2859 | |
| 2860 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 2861 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); |
| 2862 | UnresolvedSet<8> TemplDecls; |
| 2863 | unsigned NumTemplates = FromInfo->getNumTemplates(); |
| 2864 | for (unsigned I = 0; I < NumTemplates; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2865 | if (Expected<FunctionTemplateDecl *> ToFTDOrErr = |
| 2866 | import(FromInfo->getTemplate(I))) |
| 2867 | TemplDecls.addDecl(*ToFTDOrErr); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2868 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2869 | return ToFTDOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2870 | } |
| 2871 | |
| 2872 | // Import TemplateArgumentListInfo. |
| 2873 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2874 | if (Error Err = ImportTemplateArgumentListInfo( |
| 2875 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), |
| 2876 | llvm::makeArrayRef( |
| 2877 | FromInfo->getTemplateArgs(), FromInfo->getNumTemplateArgs()), |
| 2878 | ToTAInfo)) |
| 2879 | return Err; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2880 | |
| 2881 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), |
| 2882 | TemplDecls, ToTAInfo); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2883 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2884 | } |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2885 | } |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2886 | llvm_unreachable("All cases should be covered!"); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2887 | } |
| 2888 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2889 | Expected<FunctionDecl *> |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2890 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2891 | auto FunctionAndArgsOrErr = |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2892 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2893 | if (!FunctionAndArgsOrErr) |
| 2894 | return FunctionAndArgsOrErr.takeError(); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2895 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2896 | FunctionTemplateDecl *Template; |
| 2897 | TemplateArgsTy ToTemplArgs; |
| 2898 | std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2899 | void *InsertPos = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2900 | auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2901 | return FoundSpec; |
| 2902 | } |
| 2903 | |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 2904 | Error ASTNodeImporter::ImportFunctionDeclBody(FunctionDecl *FromFD, |
| 2905 | FunctionDecl *ToFD) { |
| 2906 | if (Stmt *FromBody = FromFD->getBody()) { |
| 2907 | if (ExpectedStmt ToBodyOrErr = import(FromBody)) |
| 2908 | ToFD->setBody(*ToBodyOrErr); |
| 2909 | else |
| 2910 | return ToBodyOrErr.takeError(); |
| 2911 | } |
| 2912 | return Error::success(); |
| 2913 | } |
| 2914 | |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 2915 | template <typename T> |
| 2916 | bool ASTNodeImporter::hasSameVisibilityContext(T *Found, T *From) { |
| 2917 | if (From->hasExternalFormalLinkage()) |
| 2918 | return Found->hasExternalFormalLinkage(); |
| 2919 | if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl()) |
| 2920 | return false; |
| 2921 | if (From->isInAnonymousNamespace()) |
| 2922 | return Found->isInAnonymousNamespace(); |
| 2923 | else |
| 2924 | return !Found->isInAnonymousNamespace() && |
| 2925 | !Found->hasExternalFormalLinkage(); |
| 2926 | } |
| 2927 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2928 | ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2929 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2930 | SmallVector<Decl *, 2> Redecls = getCanonicalForwardRedeclChain(D); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2931 | auto RedeclIt = Redecls.begin(); |
| 2932 | // Import the first part of the decl chain. I.e. import all previous |
| 2933 | // declarations starting from the canonical decl. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2934 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 2935 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 2936 | if (!ToRedeclOrErr) |
| 2937 | return ToRedeclOrErr.takeError(); |
| 2938 | } |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2939 | assert(*RedeclIt == D); |
| 2940 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2941 | // Import the major distinguishing characteristics of this function. |
| 2942 | DeclContext *DC, *LexicalDC; |
| 2943 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2944 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2945 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2946 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2947 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2948 | if (ToD) |
| 2949 | return ToD; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2950 | |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 2951 | FunctionDecl *FoundByLookup = nullptr; |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 2952 | FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2953 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2954 | // 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] | 2955 | // existing specialization in the "to" context. The lookup below will not |
| 2956 | // find any specialization, but would find the primary template; thus, we |
| 2957 | // have to skip normal lookup in case of specializations. |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2958 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? |
| 2959 | if (D->getTemplatedKind() == |
| 2960 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2961 | auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D); |
| 2962 | if (!FoundFunctionOrErr) |
| 2963 | return FoundFunctionOrErr.takeError(); |
| 2964 | if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) { |
Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 2965 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) |
| 2966 | return Def; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2967 | FoundByLookup = FoundFunction; |
| 2968 | } |
| 2969 | } |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2970 | // Try to find a function in our own ("to") context with the same name, same |
| 2971 | // type, and in the same context as the function we're importing. |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2972 | else if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2973 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2974 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2975 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2976 | for (auto *FoundDecl : FoundDecls) { |
| 2977 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2978 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2979 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2980 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 2981 | if (!hasSameVisibilityContext(FoundFunction, D)) |
| 2982 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2983 | |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 2984 | if (IsStructuralMatch(D, FoundFunction)) { |
Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 2985 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) |
| 2986 | return Def; |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 2987 | FoundByLookup = FoundFunction; |
| 2988 | break; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2989 | } |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 2990 | // FIXME: Check for overloading more carefully, e.g., by boosting |
| 2991 | // Sema::IsOverload out to the AST library. |
| 2992 | |
| 2993 | // Function overloading is okay in C++. |
| 2994 | if (Importer.getToContext().getLangOpts().CPlusPlus) |
| 2995 | continue; |
| 2996 | |
| 2997 | // Complain about inconsistent function types. |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 2998 | Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent) |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 2999 | << Name << D->getType() << FoundFunction->getType(); |
| 3000 | Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here) |
| 3001 | << FoundFunction->getType(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3002 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3003 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3004 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3005 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3006 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3007 | if (!ConflictingDecls.empty()) { |
| 3008 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3009 | ConflictingDecls.data(), |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3010 | ConflictingDecls.size()); |
| 3011 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3012 | return make_error<ImportError>(ImportError::NameConflict); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3013 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3014 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3015 | |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3016 | // We do not allow more than one in-class declaration of a function. This is |
| 3017 | // because AST clients like VTableBuilder asserts on this. VTableBuilder |
| 3018 | // assumes there is only one in-class declaration. Building a redecl |
| 3019 | // chain would result in more than one in-class declaration for |
| 3020 | // overrides (even if they are part of the same redecl chain inside the |
| 3021 | // derived class.) |
| 3022 | if (FoundByLookup) { |
Mikael Holmen | c1c97aa | 2019-01-29 06:53:31 +0000 | [diff] [blame] | 3023 | if (isa<CXXMethodDecl>(FoundByLookup)) { |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3024 | if (D->getLexicalDeclContext() == D->getDeclContext()) { |
| 3025 | if (!D->doesThisDeclarationHaveABody()) |
| 3026 | return Importer.MapImported(D, FoundByLookup); |
| 3027 | else { |
| 3028 | // Let's continue and build up the redecl chain in this case. |
| 3029 | // FIXME Merge the functions into one decl. |
| 3030 | } |
| 3031 | } |
| 3032 | } |
| 3033 | } |
| 3034 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3035 | DeclarationNameInfo NameInfo(Name, Loc); |
| 3036 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3037 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 3038 | return std::move(Err); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3039 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3040 | QualType FromTy = D->getType(); |
| 3041 | bool usedDifferentExceptionSpec = false; |
| 3042 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3043 | if (const auto *FromFPT = D->getType()->getAs<FunctionProtoType>()) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3044 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); |
| 3045 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the |
| 3046 | // FunctionDecl that we are importing the FunctionProtoType for. |
| 3047 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| 3048 | // with a simplified function type and update it afterwards. |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 3049 | if (FromEPI.ExceptionSpec.SourceDecl || |
| 3050 | FromEPI.ExceptionSpec.SourceTemplate || |
| 3051 | FromEPI.ExceptionSpec.NoexceptExpr) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3052 | FunctionProtoType::ExtProtoInfo DefaultEPI; |
| 3053 | FromTy = Importer.getFromContext().getFunctionType( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3054 | FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI); |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3055 | usedDifferentExceptionSpec = true; |
| 3056 | } |
| 3057 | } |
| 3058 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3059 | QualType T; |
| 3060 | TypeSourceInfo *TInfo; |
| 3061 | SourceLocation ToInnerLocStart, ToEndLoc; |
| 3062 | NestedNameSpecifierLoc ToQualifierLoc; |
| 3063 | if (auto Imp = importSeq( |
| 3064 | FromTy, D->getTypeSourceInfo(), D->getInnerLocStart(), |
| 3065 | D->getQualifierLoc(), D->getEndLoc())) |
| 3066 | std::tie(T, TInfo, ToInnerLocStart, ToQualifierLoc, ToEndLoc) = *Imp; |
| 3067 | else |
| 3068 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3069 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3070 | // Import the function parameters. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3071 | SmallVector<ParmVarDecl *, 8> Parameters; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3072 | for (auto P : D->parameters()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3073 | if (Expected<ParmVarDecl *> ToPOrErr = import(P)) |
| 3074 | Parameters.push_back(*ToPOrErr); |
| 3075 | else |
| 3076 | return ToPOrErr.takeError(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3077 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3078 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3079 | // Create the imported function. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3080 | FunctionDecl *ToFunction = nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3081 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3082 | Expr *ExplicitExpr = nullptr; |
| 3083 | if (FromConstructor->getExplicitSpecifier().getExpr()) { |
| 3084 | auto Imp = importSeq(FromConstructor->getExplicitSpecifier().getExpr()); |
| 3085 | if (!Imp) |
| 3086 | return Imp.takeError(); |
| 3087 | std::tie(ExplicitExpr) = *Imp; |
| 3088 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3089 | if (GetImportedOrCreateDecl<CXXConstructorDecl>( |
Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3090 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3091 | ToInnerLocStart, NameInfo, T, TInfo, |
| 3092 | ExplicitSpecifier( |
| 3093 | ExplicitExpr, |
| 3094 | FromConstructor->getExplicitSpecifier().getKind()), |
Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3095 | D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3096 | return ToFunction; |
Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3097 | } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) { |
| 3098 | |
| 3099 | auto Imp = |
| 3100 | importSeq(const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()), |
| 3101 | FromDtor->getOperatorDeleteThisArg()); |
| 3102 | |
| 3103 | if (!Imp) |
| 3104 | return Imp.takeError(); |
| 3105 | |
| 3106 | FunctionDecl *ToOperatorDelete; |
| 3107 | Expr *ToThisArg; |
| 3108 | std::tie(ToOperatorDelete, ToThisArg) = *Imp; |
| 3109 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3110 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3111 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3112 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| 3113 | D->isImplicit())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3114 | return ToFunction; |
Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3115 | |
| 3116 | CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction); |
| 3117 | |
| 3118 | ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3119 | } else if (CXXConversionDecl *FromConversion = |
| 3120 | dyn_cast<CXXConversionDecl>(D)) { |
Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3121 | Expr *ExplicitExpr = nullptr; |
| 3122 | if (FromConversion->getExplicitSpecifier().getExpr()) { |
| 3123 | auto Imp = importSeq(FromConversion->getExplicitSpecifier().getExpr()); |
| 3124 | if (!Imp) |
| 3125 | return Imp.takeError(); |
| 3126 | std::tie(ExplicitExpr) = *Imp; |
| 3127 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3128 | if (GetImportedOrCreateDecl<CXXConversionDecl>( |
| 3129 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3130 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3131 | ExplicitSpecifier(ExplicitExpr, |
| 3132 | FromConversion->getExplicitSpecifier().getKind()), |
Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3133 | D->getConstexprKind(), SourceLocation())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3134 | return ToFunction; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3135 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3136 | if (GetImportedOrCreateDecl<CXXMethodDecl>( |
| 3137 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3138 | ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), |
Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3139 | Method->isInlineSpecified(), D->getConstexprKind(), |
| 3140 | SourceLocation())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3141 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3142 | } else { |
Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3143 | if (GetImportedOrCreateDecl( |
| 3144 | ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, |
| 3145 | NameInfo, T, TInfo, D->getStorageClass(), D->isInlineSpecified(), |
| 3146 | D->hasWrittenPrototype(), D->getConstexprKind())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3147 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3148 | } |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3149 | |
Gabor Marton | f5e4f0a | 2018-11-20 14:19:39 +0000 | [diff] [blame] | 3150 | // Connect the redecl chain. |
| 3151 | if (FoundByLookup) { |
| 3152 | auto *Recent = const_cast<FunctionDecl *>( |
| 3153 | FoundByLookup->getMostRecentDecl()); |
| 3154 | ToFunction->setPreviousDecl(Recent); |
Gabor Marton | ce6b781 | 2019-05-08 15:23:48 +0000 | [diff] [blame] | 3155 | // FIXME Probably we should merge exception specifications. E.g. In the |
| 3156 | // "To" context the existing function may have exception specification with |
| 3157 | // noexcept-unevaluated, while the newly imported function may have an |
| 3158 | // evaluated noexcept. A call to adjustExceptionSpec() on the imported |
| 3159 | // decl and its redeclarations may be required. |
Gabor Marton | f5e4f0a | 2018-11-20 14:19:39 +0000 | [diff] [blame] | 3160 | } |
| 3161 | |
| 3162 | // Import Ctor initializers. |
| 3163 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
| 3164 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
| 3165 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers); |
| 3166 | // Import first, then allocate memory and copy if there was no error. |
| 3167 | if (Error Err = ImportContainerChecked( |
| 3168 | FromConstructor->inits(), CtorInitializers)) |
| 3169 | return std::move(Err); |
| 3170 | auto **Memory = |
| 3171 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 3172 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
| 3173 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); |
| 3174 | ToCtor->setCtorInitializers(Memory); |
| 3175 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 3176 | } |
| 3177 | } |
| 3178 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3179 | ToFunction->setQualifierInfo(ToQualifierLoc); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3180 | ToFunction->setAccess(D->getAccess()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3181 | ToFunction->setLexicalDeclContext(LexicalDC); |
John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 3182 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 3183 | ToFunction->setTrivial(D->isTrivial()); |
| 3184 | ToFunction->setPure(D->isPure()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3185 | ToFunction->setRangeEnd(ToEndLoc); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3186 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3187 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3188 | for (auto *Param : Parameters) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3189 | Param->setOwningFunction(ToFunction); |
| 3190 | ToFunction->addDeclInternal(Param); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3191 | } |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 3192 | ToFunction->setParams(Parameters); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3193 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3194 | // We need to complete creation of FunctionProtoTypeLoc manually with setting |
| 3195 | // params it refers to. |
| 3196 | if (TInfo) { |
| 3197 | if (auto ProtoLoc = |
| 3198 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { |
| 3199 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) |
| 3200 | ProtoLoc.setParam(I, Parameters[I]); |
| 3201 | } |
| 3202 | } |
| 3203 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3204 | if (usedDifferentExceptionSpec) { |
| 3205 | // Update FunctionProtoType::ExtProtoInfo. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3206 | if (ExpectedType TyOrErr = import(D->getType())) |
| 3207 | ToFunction->setType(*TyOrErr); |
| 3208 | else |
| 3209 | return TyOrErr.takeError(); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 3210 | } |
| 3211 | |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3212 | // Import the describing template function, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3213 | if (FromFT) { |
| 3214 | auto ToFTOrErr = import(FromFT); |
| 3215 | if (!ToFTOrErr) |
| 3216 | return ToFTOrErr.takeError(); |
| 3217 | } |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3218 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3219 | if (D->doesThisDeclarationHaveABody()) { |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3220 | Error Err = ImportFunctionDeclBody(D, ToFunction); |
| 3221 | |
| 3222 | if (Err) |
| 3223 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3224 | } |
| 3225 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3226 | // FIXME: Other bits to merge? |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3227 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3228 | // If it is a template, import all related things. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3229 | if (Error Err = ImportTemplateInformation(D, ToFunction)) |
| 3230 | return std::move(Err); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3231 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3232 | bool IsFriend = D->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend); |
| 3233 | |
| 3234 | // TODO Can we generalize this approach to other AST nodes as well? |
| 3235 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 3236 | DC->addDeclInternal(ToFunction); |
| 3237 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3238 | LexicalDC->addDeclInternal(ToFunction); |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3239 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3240 | // Friend declaration's lexical context is the befriending class, but the |
| 3241 | // semantic context is the enclosing scope of the befriending class. |
| 3242 | // We want the friend functions to be found in the semantic context by lookup. |
| 3243 | // FIXME should we handle this generically in VisitFriendDecl? |
| 3244 | // In Other cases when LexicalDC != DC we don't want it to be added, |
| 3245 | // e.g out-of-class definitions like void B::f() {} . |
| 3246 | if (LexicalDC != DC && IsFriend) { |
| 3247 | DC->makeDeclVisibleInContext(ToFunction); |
| 3248 | } |
| 3249 | |
Gabor Marton | 7a0841e | 2018-10-29 10:18:28 +0000 | [diff] [blame] | 3250 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) |
| 3251 | ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod); |
| 3252 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3253 | // Import the rest of the chain. I.e. import all subsequent declarations. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3254 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3255 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 3256 | if (!ToRedeclOrErr) |
| 3257 | return ToRedeclOrErr.takeError(); |
| 3258 | } |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3259 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3260 | return ToFunction; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3261 | } |
| 3262 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3263 | ExpectedDecl ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3264 | return VisitFunctionDecl(D); |
| 3265 | } |
| 3266 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3267 | ExpectedDecl ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3268 | return VisitCXXMethodDecl(D); |
| 3269 | } |
| 3270 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3271 | ExpectedDecl ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3272 | return VisitCXXMethodDecl(D); |
| 3273 | } |
| 3274 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3275 | ExpectedDecl ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3276 | return VisitCXXMethodDecl(D); |
| 3277 | } |
| 3278 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3279 | ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3280 | // Import the major distinguishing characteristics of a variable. |
| 3281 | DeclContext *DC, *LexicalDC; |
| 3282 | DeclarationName Name; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3283 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3284 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3285 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3286 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3287 | if (ToD) |
| 3288 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3289 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3290 | // Determine whether we've already imported this field. |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3291 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3292 | for (auto *FoundDecl : FoundDecls) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3293 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3294 | // For anonymous fields, match up by index. |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3295 | if (!Name && |
| 3296 | ASTImporter::getFieldIndex(D) != |
| 3297 | ASTImporter::getFieldIndex(FoundField)) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3298 | continue; |
| 3299 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3300 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3301 | FoundField->getType())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3302 | Importer.MapImported(D, FoundField); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3303 | // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the |
| 3304 | // initializer of a FieldDecl might not had been instantiated in the |
| 3305 | // "To" context. However, the "From" context might instantiated that, |
| 3306 | // thus we have to merge that. |
| 3307 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
| 3308 | // We don't have yet the initializer set. |
| 3309 | if (FoundField->hasInClassInitializer() && |
| 3310 | !FoundField->getInClassInitializer()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3311 | if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) |
| 3312 | FoundField->setInClassInitializer(*ToInitializerOrErr); |
| 3313 | else { |
| 3314 | // We can't return error here, |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3315 | // since we already mapped D as imported. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3316 | // FIXME: warning message? |
| 3317 | consumeError(ToInitializerOrErr.takeError()); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3318 | return FoundField; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3319 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3320 | } |
| 3321 | } |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3322 | return FoundField; |
| 3323 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3324 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3325 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3326 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3327 | << Name << D->getType() << FoundField->getType(); |
| 3328 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3329 | << FoundField->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3330 | |
| 3331 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3332 | } |
| 3333 | } |
| 3334 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3335 | QualType ToType; |
| 3336 | TypeSourceInfo *ToTInfo; |
| 3337 | Expr *ToBitWidth; |
| 3338 | SourceLocation ToInnerLocStart; |
| 3339 | Expr *ToInitializer; |
| 3340 | if (auto Imp = importSeq( |
| 3341 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), |
| 3342 | D->getInnerLocStart(), D->getInClassInitializer())) |
| 3343 | std::tie( |
| 3344 | ToType, ToTInfo, ToBitWidth, ToInnerLocStart, ToInitializer) = *Imp; |
| 3345 | else |
| 3346 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3347 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3348 | FieldDecl *ToField; |
| 3349 | if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3350 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3351 | ToType, ToTInfo, ToBitWidth, D->isMutable(), |
| 3352 | D->getInClassInitStyle())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3353 | return ToField; |
| 3354 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3355 | ToField->setAccess(D->getAccess()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3356 | ToField->setLexicalDeclContext(LexicalDC); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3357 | if (ToInitializer) |
| 3358 | ToField->setInClassInitializer(ToInitializer); |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3359 | ToField->setImplicit(D->isImplicit()); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3360 | LexicalDC->addDeclInternal(ToField); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3361 | return ToField; |
| 3362 | } |
| 3363 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3364 | ExpectedDecl ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3365 | // Import the major distinguishing characteristics of a variable. |
| 3366 | DeclContext *DC, *LexicalDC; |
| 3367 | DeclarationName Name; |
| 3368 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3369 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3370 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3371 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3372 | if (ToD) |
| 3373 | return ToD; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3374 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3375 | // Determine whether we've already imported this field. |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3376 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3377 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3378 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3379 | // For anonymous indirect fields, match up by index. |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3380 | if (!Name && |
| 3381 | ASTImporter::getFieldIndex(D) != |
| 3382 | ASTImporter::getFieldIndex(FoundField)) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3383 | continue; |
| 3384 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3385 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3386 | FoundField->getType(), |
David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 3387 | !Name.isEmpty())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3388 | Importer.MapImported(D, FoundField); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3389 | return FoundField; |
| 3390 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3391 | |
| 3392 | // If there are more anonymous fields to check, continue. |
| 3393 | if (!Name && I < N-1) |
| 3394 | continue; |
| 3395 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3396 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3397 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3398 | << Name << D->getType() << FoundField->getType(); |
| 3399 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3400 | << FoundField->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3401 | |
| 3402 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3403 | } |
| 3404 | } |
| 3405 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3406 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3407 | auto TypeOrErr = import(D->getType()); |
| 3408 | if (!TypeOrErr) |
| 3409 | return TypeOrErr.takeError(); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3410 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3411 | auto **NamedChain = |
| 3412 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3413 | |
| 3414 | unsigned i = 0; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3415 | for (auto *PI : D->chain()) |
| 3416 | if (Expected<NamedDecl *> ToD = import(PI)) |
| 3417 | NamedChain[i++] = *ToD; |
| 3418 | else |
| 3419 | return ToD.takeError(); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3420 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3421 | llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()}; |
| 3422 | IndirectFieldDecl *ToIndirectField; |
| 3423 | if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3424 | Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3425 | // FIXME here we leak `NamedChain` which is allocated before |
| 3426 | return ToIndirectField; |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 3427 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3428 | ToIndirectField->setAccess(D->getAccess()); |
| 3429 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3430 | LexicalDC->addDeclInternal(ToIndirectField); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3431 | return ToIndirectField; |
| 3432 | } |
| 3433 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3434 | ExpectedDecl ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3435 | // Import the major distinguishing characteristics of a declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3436 | DeclContext *DC, *LexicalDC; |
| 3437 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 3438 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3439 | |
| 3440 | // Determine whether we've already imported this decl. |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3441 | // FriendDecl is not a NamedDecl so we cannot use lookup. |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3442 | auto *RD = cast<CXXRecordDecl>(DC); |
| 3443 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3444 | |
| 3445 | while (ImportedFriend) { |
| 3446 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 3447 | if (IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(), |
| 3448 | /*Complain=*/false)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3449 | return Importer.MapImported(D, ImportedFriend); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3450 | |
| 3451 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| 3452 | if (Importer.IsStructurallyEquivalent( |
| 3453 | D->getFriendType()->getType(), |
| 3454 | ImportedFriend->getFriendType()->getType(), true)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3455 | return Importer.MapImported(D, ImportedFriend); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3456 | } |
| 3457 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 3458 | } |
| 3459 | |
| 3460 | // Not found. Create it. |
| 3461 | FriendDecl::FriendUnion ToFU; |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3462 | if (NamedDecl *FriendD = D->getFriendDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3463 | NamedDecl *ToFriendD; |
| 3464 | if (Error Err = importInto(ToFriendD, FriendD)) |
| 3465 | return std::move(Err); |
| 3466 | |
| 3467 | if (FriendD->getFriendObjectKind() != Decl::FOK_None && |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3468 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) |
| 3469 | ToFriendD->setObjectOfFriendDecl(false); |
| 3470 | |
| 3471 | ToFU = ToFriendD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3472 | } else { // The friend is a type, not a decl. |
| 3473 | if (auto TSIOrErr = import(D->getFriendType())) |
| 3474 | ToFU = *TSIOrErr; |
| 3475 | else |
| 3476 | return TSIOrErr.takeError(); |
| 3477 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3478 | |
| 3479 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3480 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3481 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 3482 | if (auto ListOrErr = import(FromTPLists[I])) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3483 | ToTPLists[I] = *ListOrErr; |
| 3484 | else |
| 3485 | return ListOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3486 | } |
| 3487 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3488 | auto LocationOrErr = import(D->getLocation()); |
| 3489 | if (!LocationOrErr) |
| 3490 | return LocationOrErr.takeError(); |
| 3491 | auto FriendLocOrErr = import(D->getFriendLoc()); |
| 3492 | if (!FriendLocOrErr) |
| 3493 | return FriendLocOrErr.takeError(); |
| 3494 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3495 | FriendDecl *FrD; |
| 3496 | if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3497 | *LocationOrErr, ToFU, |
| 3498 | *FriendLocOrErr, ToTPLists)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3499 | return FrD; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3500 | |
| 3501 | FrD->setAccess(D->getAccess()); |
| 3502 | FrD->setLexicalDeclContext(LexicalDC); |
| 3503 | LexicalDC->addDeclInternal(FrD); |
| 3504 | return FrD; |
| 3505 | } |
| 3506 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3507 | ExpectedDecl ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3508 | // Import the major distinguishing characteristics of an ivar. |
| 3509 | DeclContext *DC, *LexicalDC; |
| 3510 | DeclarationName Name; |
| 3511 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3512 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3513 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3514 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3515 | if (ToD) |
| 3516 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3517 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3518 | // Determine whether we've already imported this ivar |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3519 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3520 | for (auto *FoundDecl : FoundDecls) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3521 | if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3522 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3523 | FoundIvar->getType())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3524 | Importer.MapImported(D, FoundIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3525 | return FoundIvar; |
| 3526 | } |
| 3527 | |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3528 | Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent) |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3529 | << Name << D->getType() << FoundIvar->getType(); |
| 3530 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) |
| 3531 | << FoundIvar->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3532 | |
| 3533 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3534 | } |
| 3535 | } |
| 3536 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3537 | QualType ToType; |
| 3538 | TypeSourceInfo *ToTypeSourceInfo; |
| 3539 | Expr *ToBitWidth; |
| 3540 | SourceLocation ToInnerLocStart; |
| 3541 | if (auto Imp = importSeq( |
| 3542 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), D->getInnerLocStart())) |
| 3543 | std::tie(ToType, ToTypeSourceInfo, ToBitWidth, ToInnerLocStart) = *Imp; |
| 3544 | else |
| 3545 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3546 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3547 | ObjCIvarDecl *ToIvar; |
| 3548 | if (GetImportedOrCreateDecl( |
| 3549 | ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3550 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3551 | ToType, ToTypeSourceInfo, |
| 3552 | D->getAccessControl(),ToBitWidth, D->getSynthesize())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3553 | return ToIvar; |
| 3554 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3555 | ToIvar->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3556 | LexicalDC->addDeclInternal(ToIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3557 | return ToIvar; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3558 | } |
| 3559 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3560 | ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) { |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3561 | |
| 3562 | SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D); |
| 3563 | auto RedeclIt = Redecls.begin(); |
| 3564 | // Import the first part of the decl chain. I.e. import all previous |
| 3565 | // declarations starting from the canonical decl. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3566 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 3567 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3568 | if (!RedeclOrErr) |
| 3569 | return RedeclOrErr.takeError(); |
| 3570 | } |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3571 | assert(*RedeclIt == D); |
| 3572 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3573 | // Import the major distinguishing characteristics of a variable. |
| 3574 | DeclContext *DC, *LexicalDC; |
| 3575 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3576 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3577 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3578 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3579 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3580 | if (ToD) |
| 3581 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3582 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3583 | // Try to find a variable in our own ("to") context with the same name and |
| 3584 | // in the same context as the variable we're importing. |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3585 | VarDecl *FoundByLookup = nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3586 | if (D->isFileVarDecl()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3587 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3588 | unsigned IDNS = Decl::IDNS_Ordinary; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3589 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3590 | for (auto *FoundDecl : FoundDecls) { |
| 3591 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3592 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3593 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3594 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3595 | if (!hasSameVisibilityContext(FoundVar, D)) |
| 3596 | continue; |
| 3597 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| 3598 | FoundVar->getType())) { |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3599 | |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3600 | // The VarDecl in the "From" context has a definition, but in the |
| 3601 | // "To" context we already have a definition. |
| 3602 | VarDecl *FoundDef = FoundVar->getDefinition(); |
| 3603 | if (D->isThisDeclarationADefinition() && FoundDef) |
| 3604 | // FIXME Check for ODR error if the two definitions have |
| 3605 | // different initializers? |
| 3606 | return Importer.MapImported(D, FoundDef); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3607 | |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3608 | // The VarDecl in the "From" context has an initializer, but in the |
| 3609 | // "To" context we already have an initializer. |
| 3610 | const VarDecl *FoundDInit = nullptr; |
| 3611 | if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit)) |
| 3612 | // FIXME Diagnose ODR error if the two initializers are different? |
| 3613 | return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit)); |
| 3614 | |
| 3615 | FoundByLookup = FoundVar; |
| 3616 | break; |
| 3617 | } |
| 3618 | |
| 3619 | const ArrayType *FoundArray |
| 3620 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 3621 | const ArrayType *TArray |
| 3622 | = Importer.getToContext().getAsArrayType(D->getType()); |
| 3623 | if (FoundArray && TArray) { |
| 3624 | if (isa<IncompleteArrayType>(FoundArray) && |
| 3625 | isa<ConstantArrayType>(TArray)) { |
| 3626 | // Import the type. |
| 3627 | if (auto TyOrErr = import(D->getType())) |
| 3628 | FoundVar->setType(*TyOrErr); |
| 3629 | else |
| 3630 | return TyOrErr.takeError(); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3631 | |
| 3632 | FoundByLookup = FoundVar; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3633 | break; |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3634 | } else if (isa<IncompleteArrayType>(TArray) && |
| 3635 | isa<ConstantArrayType>(FoundArray)) { |
| 3636 | FoundByLookup = FoundVar; |
| 3637 | break; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3638 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3639 | } |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3640 | |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3641 | Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent) |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3642 | << Name << D->getType() << FoundVar->getType(); |
| 3643 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 3644 | << FoundVar->getType(); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3645 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3646 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3647 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3648 | } |
| 3649 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3650 | if (!ConflictingDecls.empty()) { |
| 3651 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3652 | ConflictingDecls.data(), |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3653 | ConflictingDecls.size()); |
| 3654 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3655 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3656 | } |
| 3657 | } |
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 | QualType ToType; |
| 3660 | TypeSourceInfo *ToTypeSourceInfo; |
| 3661 | SourceLocation ToInnerLocStart; |
| 3662 | NestedNameSpecifierLoc ToQualifierLoc; |
| 3663 | if (auto Imp = importSeq( |
| 3664 | D->getType(), D->getTypeSourceInfo(), D->getInnerLocStart(), |
| 3665 | D->getQualifierLoc())) |
| 3666 | std::tie(ToType, ToTypeSourceInfo, ToInnerLocStart, ToQualifierLoc) = *Imp; |
| 3667 | else |
| 3668 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3669 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3670 | // Create the imported variable. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3671 | VarDecl *ToVar; |
| 3672 | if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3673 | ToInnerLocStart, Loc, |
| 3674 | Name.getAsIdentifierInfo(), |
| 3675 | ToType, ToTypeSourceInfo, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3676 | D->getStorageClass())) |
| 3677 | return ToVar; |
| 3678 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3679 | ToVar->setQualifierInfo(ToQualifierLoc); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3680 | ToVar->setAccess(D->getAccess()); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3681 | ToVar->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3682 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3683 | if (FoundByLookup) { |
| 3684 | auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl()); |
| 3685 | ToVar->setPreviousDecl(Recent); |
| 3686 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3687 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3688 | if (Error Err = ImportInitializer(D, ToVar)) |
| 3689 | return std::move(Err); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3690 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3691 | if (D->isConstexpr()) |
| 3692 | ToVar->setConstexpr(true); |
| 3693 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3694 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 3695 | DC->addDeclInternal(ToVar); |
| 3696 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
| 3697 | LexicalDC->addDeclInternal(ToVar); |
| 3698 | |
| 3699 | // Import the rest of the chain. I.e. import all subsequent declarations. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3700 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3701 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3702 | if (!RedeclOrErr) |
| 3703 | return RedeclOrErr.takeError(); |
| 3704 | } |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3705 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3706 | return ToVar; |
| 3707 | } |
| 3708 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3709 | ExpectedDecl ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3710 | // Parameters are created in the translation unit's context, then moved |
| 3711 | // into the function declaration's context afterward. |
| 3712 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3713 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3714 | DeclarationName ToDeclName; |
| 3715 | SourceLocation ToLocation; |
| 3716 | QualType ToType; |
| 3717 | if (auto Imp = importSeq(D->getDeclName(), D->getLocation(), D->getType())) |
| 3718 | std::tie(ToDeclName, ToLocation, ToType) = *Imp; |
| 3719 | else |
| 3720 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3721 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3722 | // Create the imported parameter. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3723 | ImplicitParamDecl *ToParm = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3724 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
| 3725 | ToLocation, ToDeclName.getAsIdentifierInfo(), |
| 3726 | ToType, D->getParameterKind())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3727 | return ToParm; |
| 3728 | return ToParm; |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3729 | } |
| 3730 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3731 | ExpectedDecl ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3732 | // Parameters are created in the translation unit's context, then moved |
| 3733 | // into the function declaration's context afterward. |
| 3734 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3735 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3736 | DeclarationName ToDeclName; |
| 3737 | SourceLocation ToLocation, ToInnerLocStart; |
| 3738 | QualType ToType; |
| 3739 | TypeSourceInfo *ToTypeSourceInfo; |
| 3740 | if (auto Imp = importSeq( |
| 3741 | D->getDeclName(), D->getLocation(), D->getType(), D->getInnerLocStart(), |
| 3742 | D->getTypeSourceInfo())) |
| 3743 | std::tie( |
| 3744 | ToDeclName, ToLocation, ToType, ToInnerLocStart, |
| 3745 | ToTypeSourceInfo) = *Imp; |
| 3746 | else |
| 3747 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3748 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3749 | ParmVarDecl *ToParm; |
| 3750 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3751 | ToInnerLocStart, ToLocation, |
| 3752 | ToDeclName.getAsIdentifierInfo(), ToType, |
| 3753 | ToTypeSourceInfo, D->getStorageClass(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3754 | /*DefaultArg*/ nullptr)) |
| 3755 | return ToParm; |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3756 | |
| 3757 | // Set the default argument. |
John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 3758 | ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg()); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3759 | ToParm->setKNRPromoted(D->isKNRPromoted()); |
| 3760 | |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3761 | if (D->hasUninstantiatedDefaultArg()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3762 | if (auto ToDefArgOrErr = import(D->getUninstantiatedDefaultArg())) |
| 3763 | ToParm->setUninstantiatedDefaultArg(*ToDefArgOrErr); |
| 3764 | else |
| 3765 | return ToDefArgOrErr.takeError(); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3766 | } else if (D->hasUnparsedDefaultArg()) { |
| 3767 | ToParm->setUnparsedDefaultArg(); |
| 3768 | } else if (D->hasDefaultArg()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3769 | if (auto ToDefArgOrErr = import(D->getDefaultArg())) |
| 3770 | ToParm->setDefaultArg(*ToDefArgOrErr); |
| 3771 | else |
| 3772 | return ToDefArgOrErr.takeError(); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3773 | } |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3774 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3775 | if (D->isObjCMethodParameter()) { |
| 3776 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); |
| 3777 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); |
| 3778 | } else { |
| 3779 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), |
| 3780 | D->getFunctionScopeIndex()); |
| 3781 | } |
| 3782 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3783 | return ToParm; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3784 | } |
| 3785 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3786 | ExpectedDecl ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3787 | // Import the major distinguishing characteristics of a method. |
| 3788 | DeclContext *DC, *LexicalDC; |
| 3789 | DeclarationName Name; |
| 3790 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3791 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3792 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3793 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3794 | if (ToD) |
| 3795 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3796 | |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3797 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3798 | for (auto *FoundDecl : FoundDecls) { |
| 3799 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3800 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 3801 | continue; |
| 3802 | |
| 3803 | // Check return types. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3804 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 3805 | FoundMethod->getReturnType())) { |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3806 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent) |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3807 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 3808 | << FoundMethod->getReturnType(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3809 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3810 | diag::note_odr_objc_method_here) |
| 3811 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3812 | |
| 3813 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3814 | } |
| 3815 | |
| 3816 | // Check the number of parameters. |
| 3817 | if (D->param_size() != FoundMethod->param_size()) { |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3818 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent) |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3819 | << D->isInstanceMethod() << Name |
| 3820 | << D->param_size() << FoundMethod->param_size(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3821 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3822 | diag::note_odr_objc_method_here) |
| 3823 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3824 | |
| 3825 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3826 | } |
| 3827 | |
| 3828 | // Check parameter types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3829 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3830 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 3831 | P != PEnd; ++P, ++FoundP) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3832 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3833 | (*FoundP)->getType())) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3834 | Importer.FromDiag((*P)->getLocation(), |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3835 | diag::warn_odr_objc_method_param_type_inconsistent) |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3836 | << D->isInstanceMethod() << Name |
| 3837 | << (*P)->getType() << (*FoundP)->getType(); |
| 3838 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 3839 | << (*FoundP)->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3840 | |
| 3841 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3842 | } |
| 3843 | } |
| 3844 | |
| 3845 | // Check variadic/non-variadic. |
| 3846 | // Check the number of parameters. |
| 3847 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3848 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent) |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3849 | << D->isInstanceMethod() << Name; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3850 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3851 | diag::note_odr_objc_method_here) |
| 3852 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3853 | |
| 3854 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3855 | } |
| 3856 | |
| 3857 | // FIXME: Any other bits we need to merge? |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3858 | return Importer.MapImported(D, FoundMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3859 | } |
| 3860 | } |
| 3861 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3862 | SourceLocation ToEndLoc; |
| 3863 | QualType ToReturnType; |
| 3864 | TypeSourceInfo *ToReturnTypeSourceInfo; |
| 3865 | if (auto Imp = importSeq( |
| 3866 | D->getEndLoc(), D->getReturnType(), D->getReturnTypeSourceInfo())) |
| 3867 | std::tie(ToEndLoc, ToReturnType, ToReturnTypeSourceInfo) = *Imp; |
| 3868 | else |
| 3869 | return Imp.takeError(); |
Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 3870 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3871 | ObjCMethodDecl *ToMethod; |
| 3872 | if (GetImportedOrCreateDecl( |
| 3873 | ToMethod, D, Importer.getToContext(), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3874 | ToEndLoc, Name.getObjCSelector(), ToReturnType, |
| 3875 | ToReturnTypeSourceInfo, DC, D->isInstanceMethod(), D->isVariadic(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3876 | D->isPropertyAccessor(), D->isImplicit(), D->isDefined(), |
| 3877 | D->getImplementationControl(), D->hasRelatedResultType())) |
| 3878 | return ToMethod; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3879 | |
| 3880 | // FIXME: When we decide to merge method definitions, we'll need to |
| 3881 | // deal with implicit parameters. |
| 3882 | |
| 3883 | // Import the parameters |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3884 | SmallVector<ParmVarDecl *, 5> ToParams; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3885 | for (auto *FromP : D->parameters()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3886 | if (Expected<ParmVarDecl *> ToPOrErr = import(FromP)) |
| 3887 | ToParams.push_back(*ToPOrErr); |
| 3888 | else |
| 3889 | return ToPOrErr.takeError(); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3890 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3891 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3892 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3893 | for (auto *ToParam : ToParams) { |
| 3894 | ToParam->setOwningFunction(ToMethod); |
| 3895 | ToMethod->addDeclInternal(ToParam); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3896 | } |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3897 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3898 | SmallVector<SourceLocation, 12> FromSelLocs; |
| 3899 | D->getSelectorLocs(FromSelLocs); |
| 3900 | SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size()); |
| 3901 | if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs)) |
| 3902 | return std::move(Err); |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3903 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3904 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3905 | |
| 3906 | ToMethod->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3907 | LexicalDC->addDeclInternal(ToMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3908 | return ToMethod; |
| 3909 | } |
| 3910 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3911 | ExpectedDecl ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3912 | // Import the major distinguishing characteristics of a category. |
| 3913 | DeclContext *DC, *LexicalDC; |
| 3914 | DeclarationName Name; |
| 3915 | SourceLocation Loc; |
| 3916 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3917 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3918 | return std::move(Err); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3919 | if (ToD) |
| 3920 | return ToD; |
| 3921 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3922 | SourceLocation ToVarianceLoc, ToLocation, ToColonLoc; |
| 3923 | TypeSourceInfo *ToTypeSourceInfo; |
| 3924 | if (auto Imp = importSeq( |
| 3925 | D->getVarianceLoc(), D->getLocation(), D->getColonLoc(), |
| 3926 | D->getTypeSourceInfo())) |
| 3927 | std::tie(ToVarianceLoc, ToLocation, ToColonLoc, ToTypeSourceInfo) = *Imp; |
| 3928 | else |
| 3929 | return Imp.takeError(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3930 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3931 | ObjCTypeParamDecl *Result; |
| 3932 | if (GetImportedOrCreateDecl( |
| 3933 | Result, D, Importer.getToContext(), DC, D->getVariance(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3934 | ToVarianceLoc, D->getIndex(), |
| 3935 | ToLocation, Name.getAsIdentifierInfo(), |
| 3936 | ToColonLoc, ToTypeSourceInfo)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3937 | return Result; |
| 3938 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3939 | Result->setLexicalDeclContext(LexicalDC); |
| 3940 | return Result; |
| 3941 | } |
| 3942 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3943 | ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3944 | // Import the major distinguishing characteristics of a category. |
| 3945 | DeclContext *DC, *LexicalDC; |
| 3946 | DeclarationName Name; |
| 3947 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3948 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3949 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3950 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3951 | if (ToD) |
| 3952 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3953 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3954 | ObjCInterfaceDecl *ToInterface; |
| 3955 | if (Error Err = importInto(ToInterface, D->getClassInterface())) |
| 3956 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3957 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3958 | // Determine if we've already encountered this category. |
| 3959 | ObjCCategoryDecl *MergeWithCategory |
| 3960 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 3961 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 3962 | if (!ToCategory) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3963 | SourceLocation ToAtStartLoc, ToCategoryNameLoc; |
| 3964 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; |
| 3965 | if (auto Imp = importSeq( |
| 3966 | D->getAtStartLoc(), D->getCategoryNameLoc(), |
| 3967 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) |
| 3968 | std::tie( |
| 3969 | ToAtStartLoc, ToCategoryNameLoc, |
| 3970 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; |
| 3971 | else |
| 3972 | return Imp.takeError(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3973 | |
| 3974 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3975 | ToAtStartLoc, Loc, |
| 3976 | ToCategoryNameLoc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3977 | Name.getAsIdentifierInfo(), ToInterface, |
| 3978 | /*TypeParamList=*/nullptr, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3979 | ToIvarLBraceLoc, |
| 3980 | ToIvarRBraceLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3981 | return ToCategory; |
| 3982 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3983 | ToCategory->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3984 | LexicalDC->addDeclInternal(ToCategory); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3985 | // Import the type parameter list after MapImported, to avoid |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3986 | // loops when bringing in their DeclContext. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3987 | if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList())) |
| 3988 | ToCategory->setTypeParamList(*PListOrErr); |
| 3989 | else |
| 3990 | return PListOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3991 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3992 | // Import protocols |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3993 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3994 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3995 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 3996 | = D->protocol_loc_begin(); |
| 3997 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 3998 | FromProtoEnd = D->protocol_end(); |
| 3999 | FromProto != FromProtoEnd; |
| 4000 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4001 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4002 | Protocols.push_back(*ToProtoOrErr); |
| 4003 | else |
| 4004 | return ToProtoOrErr.takeError(); |
| 4005 | |
| 4006 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4007 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4008 | else |
| 4009 | return ToProtoLocOrErr.takeError(); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4010 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4011 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4012 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4013 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 4014 | ProtocolLocs.data(), Importer.getToContext()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4015 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4016 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4017 | Importer.MapImported(D, ToCategory); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4018 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4019 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4020 | // Import all of the members of this category. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4021 | if (Error Err = ImportDeclContext(D)) |
| 4022 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4023 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4024 | // If we have an implementation, import it as well. |
| 4025 | if (D->getImplementation()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4026 | if (Expected<ObjCCategoryImplDecl *> ToImplOrErr = |
| 4027 | import(D->getImplementation())) |
| 4028 | ToCategory->setImplementation(*ToImplOrErr); |
| 4029 | else |
| 4030 | return ToImplOrErr.takeError(); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4031 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4032 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4033 | return ToCategory; |
| 4034 | } |
| 4035 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4036 | Error ASTNodeImporter::ImportDefinition( |
| 4037 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4038 | if (To->getDefinition()) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4039 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4040 | if (Error Err = ImportDeclContext(From)) |
| 4041 | return Err; |
| 4042 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4043 | } |
| 4044 | |
| 4045 | // Start the protocol definition |
| 4046 | To->startDefinition(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4047 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4048 | // Import protocols |
| 4049 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4050 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4051 | ObjCProtocolDecl::protocol_loc_iterator FromProtoLoc = |
| 4052 | From->protocol_loc_begin(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4053 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4054 | FromProtoEnd = From->protocol_end(); |
| 4055 | FromProto != FromProtoEnd; |
| 4056 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4057 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4058 | Protocols.push_back(*ToProtoOrErr); |
| 4059 | else |
| 4060 | return ToProtoOrErr.takeError(); |
| 4061 | |
| 4062 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4063 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4064 | else |
| 4065 | return ToProtoLocOrErr.takeError(); |
| 4066 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4067 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4068 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4069 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4070 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4071 | ProtocolLocs.data(), Importer.getToContext()); |
| 4072 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4073 | if (shouldForceImportDeclContext(Kind)) { |
| 4074 | // Import all of the members of this protocol. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4075 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4076 | return Err; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4077 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4078 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4079 | } |
| 4080 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4081 | ExpectedDecl ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4082 | // 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] | 4083 | // from, but this particular declaration is not that definition, import the |
| 4084 | // definition and map to that. |
| 4085 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 4086 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4087 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4088 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4089 | else |
| 4090 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4091 | } |
| 4092 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4093 | // Import the major distinguishing characteristics of a protocol. |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4094 | DeclContext *DC, *LexicalDC; |
| 4095 | DeclarationName Name; |
| 4096 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4097 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4098 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4099 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4100 | if (ToD) |
| 4101 | return ToD; |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4102 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4103 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4104 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4105 | for (auto *FoundDecl : FoundDecls) { |
| 4106 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4107 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4108 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4109 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4110 | break; |
| 4111 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4112 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4113 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4114 | if (!ToProto) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4115 | auto ToAtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4116 | if (!ToAtBeginLocOrErr) |
| 4117 | return ToAtBeginLocOrErr.takeError(); |
| 4118 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4119 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, |
| 4120 | Name.getAsIdentifierInfo(), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4121 | *ToAtBeginLocOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4122 | /*PrevDecl=*/nullptr)) |
| 4123 | return ToProto; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4124 | ToProto->setLexicalDeclContext(LexicalDC); |
| 4125 | LexicalDC->addDeclInternal(ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4126 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4127 | |
| 4128 | Importer.MapImported(D, ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4129 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4130 | if (D->isThisDeclarationADefinition()) |
| 4131 | if (Error Err = ImportDefinition(D, ToProto)) |
| 4132 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4133 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4134 | return ToProto; |
| 4135 | } |
| 4136 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4137 | ExpectedDecl ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 4138 | DeclContext *DC, *LexicalDC; |
| 4139 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4140 | return std::move(Err); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4141 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4142 | ExpectedSLoc ExternLocOrErr = import(D->getExternLoc()); |
| 4143 | if (!ExternLocOrErr) |
| 4144 | return ExternLocOrErr.takeError(); |
| 4145 | |
| 4146 | ExpectedSLoc LangLocOrErr = import(D->getLocation()); |
| 4147 | if (!LangLocOrErr) |
| 4148 | return LangLocOrErr.takeError(); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4149 | |
| 4150 | bool HasBraces = D->hasBraces(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4151 | |
| 4152 | LinkageSpecDecl *ToLinkageSpec; |
| 4153 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4154 | *ExternLocOrErr, *LangLocOrErr, |
| 4155 | D->getLanguage(), HasBraces)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4156 | return ToLinkageSpec; |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4157 | |
| 4158 | if (HasBraces) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4159 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); |
| 4160 | if (!RBraceLocOrErr) |
| 4161 | return RBraceLocOrErr.takeError(); |
| 4162 | ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4163 | } |
| 4164 | |
| 4165 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 4166 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 4167 | |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4168 | return ToLinkageSpec; |
| 4169 | } |
| 4170 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4171 | ExpectedDecl ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4172 | DeclContext *DC, *LexicalDC; |
| 4173 | DeclarationName Name; |
| 4174 | SourceLocation Loc; |
| 4175 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4176 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4177 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4178 | if (ToD) |
| 4179 | return ToD; |
| 4180 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4181 | SourceLocation ToLoc, ToUsingLoc; |
| 4182 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4183 | if (auto Imp = importSeq( |
| 4184 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc())) |
| 4185 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc) = *Imp; |
| 4186 | else |
| 4187 | return Imp.takeError(); |
| 4188 | |
| 4189 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4190 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4191 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4192 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4193 | UsingDecl *ToUsing; |
| 4194 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4195 | ToUsingLoc, ToQualifierLoc, NameInfo, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4196 | D->hasTypename())) |
| 4197 | return ToUsing; |
| 4198 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4199 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4200 | LexicalDC->addDeclInternal(ToUsing); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4201 | |
| 4202 | if (NamedDecl *FromPattern = |
| 4203 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4204 | if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern)) |
| 4205 | Importer.getToContext().setInstantiatedFromUsingDecl( |
| 4206 | ToUsing, *ToPatternOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4207 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4208 | return ToPatternOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4209 | } |
| 4210 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4211 | for (UsingShadowDecl *FromShadow : D->shadows()) { |
| 4212 | if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow)) |
| 4213 | ToUsing->addShadowDecl(*ToShadowOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4214 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4215 | // FIXME: We return error here but the definition is already created |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4216 | // and available with lookups. How to fix this?.. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4217 | return ToShadowOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4218 | } |
| 4219 | return ToUsing; |
| 4220 | } |
| 4221 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4222 | ExpectedDecl ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4223 | DeclContext *DC, *LexicalDC; |
| 4224 | DeclarationName Name; |
| 4225 | SourceLocation Loc; |
| 4226 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4227 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4228 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4229 | if (ToD) |
| 4230 | return ToD; |
| 4231 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4232 | Expected<UsingDecl *> ToUsingOrErr = import(D->getUsingDecl()); |
| 4233 | if (!ToUsingOrErr) |
| 4234 | return ToUsingOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4235 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4236 | Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl()); |
| 4237 | if (!ToTargetOrErr) |
| 4238 | return ToTargetOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4239 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4240 | UsingShadowDecl *ToShadow; |
| 4241 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4242 | *ToUsingOrErr, *ToTargetOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4243 | return ToShadow; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4244 | |
| 4245 | ToShadow->setLexicalDeclContext(LexicalDC); |
| 4246 | ToShadow->setAccess(D->getAccess()); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4247 | |
| 4248 | if (UsingShadowDecl *FromPattern = |
| 4249 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4250 | if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern)) |
| 4251 | Importer.getToContext().setInstantiatedFromUsingShadowDecl( |
| 4252 | ToShadow, *ToPatternOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4253 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4254 | // FIXME: We return error here but the definition is already created |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4255 | // and available with lookups. How to fix this?.. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4256 | return ToPatternOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4257 | } |
| 4258 | |
| 4259 | LexicalDC->addDeclInternal(ToShadow); |
| 4260 | |
| 4261 | return ToShadow; |
| 4262 | } |
| 4263 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4264 | ExpectedDecl ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4265 | DeclContext *DC, *LexicalDC; |
| 4266 | DeclarationName Name; |
| 4267 | SourceLocation Loc; |
| 4268 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4269 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4270 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4271 | if (ToD) |
| 4272 | return ToD; |
| 4273 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4274 | auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor()); |
| 4275 | if (!ToComAncestorOrErr) |
| 4276 | return ToComAncestorOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4277 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4278 | NamespaceDecl *ToNominatedNamespace; |
| 4279 | SourceLocation ToUsingLoc, ToNamespaceKeyLocation, ToIdentLocation; |
| 4280 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4281 | if (auto Imp = importSeq( |
| 4282 | D->getNominatedNamespace(), D->getUsingLoc(), |
| 4283 | D->getNamespaceKeyLocation(), D->getQualifierLoc(), |
| 4284 | D->getIdentLocation())) |
| 4285 | std::tie( |
| 4286 | ToNominatedNamespace, ToUsingLoc, ToNamespaceKeyLocation, |
| 4287 | ToQualifierLoc, ToIdentLocation) = *Imp; |
| 4288 | else |
| 4289 | return Imp.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4290 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4291 | UsingDirectiveDecl *ToUsingDir; |
| 4292 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4293 | ToUsingLoc, |
| 4294 | ToNamespaceKeyLocation, |
| 4295 | ToQualifierLoc, |
| 4296 | ToIdentLocation, |
| 4297 | ToNominatedNamespace, *ToComAncestorOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4298 | return ToUsingDir; |
| 4299 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4300 | ToUsingDir->setLexicalDeclContext(LexicalDC); |
| 4301 | LexicalDC->addDeclInternal(ToUsingDir); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4302 | |
| 4303 | return ToUsingDir; |
| 4304 | } |
| 4305 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4306 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4307 | UnresolvedUsingValueDecl *D) { |
| 4308 | DeclContext *DC, *LexicalDC; |
| 4309 | DeclarationName Name; |
| 4310 | SourceLocation Loc; |
| 4311 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4312 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4313 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4314 | if (ToD) |
| 4315 | return ToD; |
| 4316 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4317 | SourceLocation ToLoc, ToUsingLoc, ToEllipsisLoc; |
| 4318 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4319 | if (auto Imp = importSeq( |
| 4320 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc(), |
| 4321 | D->getEllipsisLoc())) |
| 4322 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; |
| 4323 | else |
| 4324 | return Imp.takeError(); |
| 4325 | |
| 4326 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4327 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4328 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4329 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4330 | UnresolvedUsingValueDecl *ToUsingValue; |
| 4331 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4332 | ToUsingLoc, ToQualifierLoc, NameInfo, |
| 4333 | ToEllipsisLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4334 | return ToUsingValue; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4335 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4336 | ToUsingValue->setAccess(D->getAccess()); |
| 4337 | ToUsingValue->setLexicalDeclContext(LexicalDC); |
| 4338 | LexicalDC->addDeclInternal(ToUsingValue); |
| 4339 | |
| 4340 | return ToUsingValue; |
| 4341 | } |
| 4342 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4343 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4344 | UnresolvedUsingTypenameDecl *D) { |
| 4345 | DeclContext *DC, *LexicalDC; |
| 4346 | DeclarationName Name; |
| 4347 | SourceLocation Loc; |
| 4348 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4349 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4350 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4351 | if (ToD) |
| 4352 | return ToD; |
| 4353 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4354 | SourceLocation ToUsingLoc, ToTypenameLoc, ToEllipsisLoc; |
| 4355 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4356 | if (auto Imp = importSeq( |
| 4357 | D->getUsingLoc(), D->getTypenameLoc(), D->getQualifierLoc(), |
| 4358 | D->getEllipsisLoc())) |
| 4359 | std::tie(ToUsingLoc, ToTypenameLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; |
| 4360 | else |
| 4361 | return Imp.takeError(); |
| 4362 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4363 | UnresolvedUsingTypenameDecl *ToUsing; |
| 4364 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4365 | ToUsingLoc, ToTypenameLoc, |
| 4366 | ToQualifierLoc, Loc, Name, ToEllipsisLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4367 | return ToUsing; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4368 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4369 | ToUsing->setAccess(D->getAccess()); |
| 4370 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4371 | LexicalDC->addDeclInternal(ToUsing); |
| 4372 | |
| 4373 | return ToUsing; |
| 4374 | } |
| 4375 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4376 | |
| 4377 | Error ASTNodeImporter::ImportDefinition( |
| 4378 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4379 | if (To->getDefinition()) { |
| 4380 | // Check consistency of superclass. |
| 4381 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 4382 | if (FromSuper) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4383 | if (auto FromSuperOrErr = import(FromSuper)) |
| 4384 | FromSuper = *FromSuperOrErr; |
| 4385 | else |
| 4386 | return FromSuperOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4387 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4388 | |
| 4389 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4390 | if ((bool)FromSuper != (bool)ToSuper || |
| 4391 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4392 | Importer.ToDiag(To->getLocation(), |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4393 | diag::warn_odr_objc_superclass_inconsistent) |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4394 | << To->getDeclName(); |
| 4395 | if (ToSuper) |
| 4396 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 4397 | << To->getSuperClass()->getDeclName(); |
| 4398 | else |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4399 | Importer.ToDiag(To->getLocation(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4400 | diag::note_odr_objc_missing_superclass); |
| 4401 | if (From->getSuperClass()) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4402 | Importer.FromDiag(From->getSuperClassLoc(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4403 | diag::note_odr_objc_superclass) |
| 4404 | << From->getSuperClass()->getDeclName(); |
| 4405 | else |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4406 | Importer.FromDiag(From->getLocation(), |
| 4407 | diag::note_odr_objc_missing_superclass); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4408 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4409 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4410 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4411 | if (Error Err = ImportDeclContext(From)) |
| 4412 | return Err; |
| 4413 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4414 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4415 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4416 | // Start the definition. |
| 4417 | To->startDefinition(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4418 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4419 | // If this class has a superclass, import it. |
| 4420 | if (From->getSuperClass()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4421 | if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo())) |
| 4422 | To->setSuperClass(*SuperTInfoOrErr); |
| 4423 | else |
| 4424 | return SuperTInfoOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4425 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4426 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4427 | // Import protocols |
| 4428 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4429 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4430 | ObjCInterfaceDecl::protocol_loc_iterator FromProtoLoc = |
| 4431 | From->protocol_loc_begin(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4432 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4433 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4434 | FromProtoEnd = From->protocol_end(); |
| 4435 | FromProto != FromProtoEnd; |
| 4436 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4437 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4438 | Protocols.push_back(*ToProtoOrErr); |
| 4439 | else |
| 4440 | return ToProtoOrErr.takeError(); |
| 4441 | |
| 4442 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4443 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4444 | else |
| 4445 | return ToProtoLocOrErr.takeError(); |
| 4446 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4447 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4448 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4449 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4450 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4451 | ProtocolLocs.data(), Importer.getToContext()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4452 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4453 | // Import categories. When the categories themselves are imported, they'll |
| 4454 | // hook themselves into this interface. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4455 | for (auto *Cat : From->known_categories()) { |
| 4456 | auto ToCatOrErr = import(Cat); |
| 4457 | if (!ToCatOrErr) |
| 4458 | return ToCatOrErr.takeError(); |
| 4459 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4460 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4461 | // If we have an @implementation, import it as well. |
| 4462 | if (From->getImplementation()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4463 | if (Expected<ObjCImplementationDecl *> ToImplOrErr = |
| 4464 | import(From->getImplementation())) |
| 4465 | To->setImplementation(*ToImplOrErr); |
| 4466 | else |
| 4467 | return ToImplOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4468 | } |
| 4469 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4470 | if (shouldForceImportDeclContext(Kind)) { |
| 4471 | // Import all of the members of this class. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4472 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4473 | return Err; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4474 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4475 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4476 | } |
| 4477 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4478 | Expected<ObjCTypeParamList *> |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4479 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 4480 | if (!list) |
| 4481 | return nullptr; |
| 4482 | |
| 4483 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4484 | for (auto *fromTypeParam : *list) { |
| 4485 | if (auto toTypeParamOrErr = import(fromTypeParam)) |
| 4486 | toTypeParams.push_back(*toTypeParamOrErr); |
| 4487 | else |
| 4488 | return toTypeParamOrErr.takeError(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4489 | } |
| 4490 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4491 | auto LAngleLocOrErr = import(list->getLAngleLoc()); |
| 4492 | if (!LAngleLocOrErr) |
| 4493 | return LAngleLocOrErr.takeError(); |
| 4494 | |
| 4495 | auto RAngleLocOrErr = import(list->getRAngleLoc()); |
| 4496 | if (!RAngleLocOrErr) |
| 4497 | return RAngleLocOrErr.takeError(); |
| 4498 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4499 | return ObjCTypeParamList::create(Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4500 | *LAngleLocOrErr, |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4501 | toTypeParams, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4502 | *RAngleLocOrErr); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4503 | } |
| 4504 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4505 | ExpectedDecl ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4506 | // If this class has a definition in the translation unit we're coming from, |
| 4507 | // but this particular declaration is not that definition, import the |
| 4508 | // definition and map to that. |
| 4509 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 4510 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4511 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4512 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4513 | else |
| 4514 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4515 | } |
| 4516 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4517 | // Import the major distinguishing characteristics of an @interface. |
| 4518 | DeclContext *DC, *LexicalDC; |
| 4519 | DeclarationName Name; |
| 4520 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4521 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4522 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4523 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4524 | if (ToD) |
| 4525 | return ToD; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4526 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4527 | // Look for an existing interface with the same name. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4528 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4529 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4530 | for (auto *FoundDecl : FoundDecls) { |
| 4531 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4532 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4533 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4534 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4535 | break; |
| 4536 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4537 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4538 | // Create an interface declaration, if one does not already exist. |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4539 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4540 | if (!ToIface) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4541 | ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4542 | if (!AtBeginLocOrErr) |
| 4543 | return AtBeginLocOrErr.takeError(); |
| 4544 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4545 | if (GetImportedOrCreateDecl( |
| 4546 | ToIface, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4547 | *AtBeginLocOrErr, Name.getAsIdentifierInfo(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4548 | /*TypeParamList=*/nullptr, |
| 4549 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) |
| 4550 | return ToIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4551 | ToIface->setLexicalDeclContext(LexicalDC); |
| 4552 | LexicalDC->addDeclInternal(ToIface); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4553 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4554 | Importer.MapImported(D, ToIface); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4555 | // Import the type parameter list after MapImported, to avoid |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4556 | // loops when bringing in their DeclContext. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4557 | if (auto ToPListOrErr = |
| 4558 | ImportObjCTypeParamList(D->getTypeParamListAsWritten())) |
| 4559 | ToIface->setTypeParamList(*ToPListOrErr); |
| 4560 | else |
| 4561 | return ToPListOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4562 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4563 | if (D->isThisDeclarationADefinition()) |
| 4564 | if (Error Err = ImportDefinition(D, ToIface)) |
| 4565 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4566 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4567 | return ToIface; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4568 | } |
| 4569 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4570 | ExpectedDecl |
| 4571 | ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 4572 | ObjCCategoryDecl *Category; |
| 4573 | if (Error Err = importInto(Category, D->getCategoryDecl())) |
| 4574 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4575 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4576 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 4577 | if (!ToImpl) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4578 | DeclContext *DC, *LexicalDC; |
| 4579 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4580 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4581 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4582 | SourceLocation ToLocation, ToAtStartLoc, ToCategoryNameLoc; |
| 4583 | if (auto Imp = importSeq( |
| 4584 | D->getLocation(), D->getAtStartLoc(), D->getCategoryNameLoc())) |
| 4585 | std::tie(ToLocation, ToAtStartLoc, ToCategoryNameLoc) = *Imp; |
| 4586 | else |
| 4587 | return Imp.takeError(); |
| 4588 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4589 | if (GetImportedOrCreateDecl( |
| 4590 | ToImpl, D, Importer.getToContext(), DC, |
| 4591 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4592 | ToLocation, ToAtStartLoc, ToCategoryNameLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4593 | return ToImpl; |
| 4594 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4595 | ToImpl->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4596 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4597 | Category->setImplementation(ToImpl); |
| 4598 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4599 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4600 | Importer.MapImported(D, ToImpl); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4601 | if (Error Err = ImportDeclContext(D)) |
| 4602 | return std::move(Err); |
| 4603 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4604 | return ToImpl; |
| 4605 | } |
| 4606 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4607 | ExpectedDecl |
| 4608 | ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4609 | // Find the corresponding interface. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4610 | ObjCInterfaceDecl *Iface; |
| 4611 | if (Error Err = importInto(Iface, D->getClassInterface())) |
| 4612 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4613 | |
| 4614 | // Import the superclass, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4615 | ObjCInterfaceDecl *Super; |
| 4616 | if (Error Err = importInto(Super, D->getSuperClass())) |
| 4617 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4618 | |
| 4619 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 4620 | if (!Impl) { |
| 4621 | // We haven't imported an implementation yet. Create a new @implementation |
| 4622 | // now. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4623 | DeclContext *DC, *LexicalDC; |
| 4624 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4625 | return std::move(Err); |
| 4626 | |
| 4627 | SourceLocation ToLocation, ToAtStartLoc, ToSuperClassLoc; |
| 4628 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; |
| 4629 | if (auto Imp = importSeq( |
| 4630 | D->getLocation(), D->getAtStartLoc(), D->getSuperClassLoc(), |
| 4631 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) |
| 4632 | std::tie( |
| 4633 | ToLocation, ToAtStartLoc, ToSuperClassLoc, |
| 4634 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; |
| 4635 | else |
| 4636 | return Imp.takeError(); |
| 4637 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4638 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4639 | DC, Iface, Super, |
| 4640 | ToLocation, |
| 4641 | ToAtStartLoc, |
| 4642 | ToSuperClassLoc, |
| 4643 | ToIvarLBraceLoc, |
| 4644 | ToIvarRBraceLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4645 | return Impl; |
| 4646 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4647 | Impl->setLexicalDeclContext(LexicalDC); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4648 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4649 | // Associate the implementation with the class it implements. |
| 4650 | Iface->setImplementation(Impl); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4651 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4652 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4653 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4654 | |
| 4655 | // Verify that the existing @implementation has the same superclass. |
| 4656 | if ((Super && !Impl->getSuperClass()) || |
| 4657 | (!Super && Impl->getSuperClass()) || |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4658 | (Super && Impl->getSuperClass() && |
| 4659 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 4660 | Impl->getSuperClass()))) { |
| 4661 | Importer.ToDiag(Impl->getLocation(), |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4662 | diag::warn_odr_objc_superclass_inconsistent) |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4663 | << Iface->getDeclName(); |
| 4664 | // FIXME: It would be nice to have the location of the superclass |
| 4665 | // below. |
| 4666 | if (Impl->getSuperClass()) |
| 4667 | Importer.ToDiag(Impl->getLocation(), |
| 4668 | diag::note_odr_objc_superclass) |
| 4669 | << Impl->getSuperClass()->getDeclName(); |
| 4670 | else |
| 4671 | Importer.ToDiag(Impl->getLocation(), |
| 4672 | diag::note_odr_objc_missing_superclass); |
| 4673 | if (D->getSuperClass()) |
| 4674 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4675 | diag::note_odr_objc_superclass) |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4676 | << D->getSuperClass()->getDeclName(); |
| 4677 | else |
| 4678 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4679 | diag::note_odr_objc_missing_superclass); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4680 | |
| 4681 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4682 | } |
| 4683 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4684 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4685 | // Import all of the members of this @implementation. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4686 | if (Error Err = ImportDeclContext(D)) |
| 4687 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4688 | |
| 4689 | return Impl; |
| 4690 | } |
| 4691 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4692 | ExpectedDecl ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4693 | // Import the major distinguishing characteristics of an @property. |
| 4694 | DeclContext *DC, *LexicalDC; |
| 4695 | DeclarationName Name; |
| 4696 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4697 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4698 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4699 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4700 | if (ToD) |
| 4701 | return ToD; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4702 | |
| 4703 | // Check whether we have already imported this property. |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4704 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4705 | for (auto *FoundDecl : FoundDecls) { |
| 4706 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4707 | // Check property types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4708 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4709 | FoundProp->getType())) { |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4710 | Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent) |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4711 | << Name << D->getType() << FoundProp->getType(); |
| 4712 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 4713 | << FoundProp->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4714 | |
| 4715 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4716 | } |
| 4717 | |
| 4718 | // FIXME: Check property attributes, getters, setters, etc.? |
| 4719 | |
| 4720 | // Consider these properties to be equivalent. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4721 | Importer.MapImported(D, FoundProp); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4722 | return FoundProp; |
| 4723 | } |
| 4724 | } |
| 4725 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4726 | QualType ToType; |
| 4727 | TypeSourceInfo *ToTypeSourceInfo; |
| 4728 | SourceLocation ToAtLoc, ToLParenLoc; |
| 4729 | if (auto Imp = importSeq( |
| 4730 | D->getType(), D->getTypeSourceInfo(), D->getAtLoc(), D->getLParenLoc())) |
| 4731 | std::tie(ToType, ToTypeSourceInfo, ToAtLoc, ToLParenLoc) = *Imp; |
| 4732 | else |
| 4733 | return Imp.takeError(); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4734 | |
| 4735 | // Create the new property. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4736 | ObjCPropertyDecl *ToProperty; |
| 4737 | if (GetImportedOrCreateDecl( |
| 4738 | ToProperty, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4739 | Name.getAsIdentifierInfo(), ToAtLoc, |
| 4740 | ToLParenLoc, ToType, |
| 4741 | ToTypeSourceInfo, D->getPropertyImplementation())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4742 | return ToProperty; |
| 4743 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4744 | Selector ToGetterName, ToSetterName; |
| 4745 | SourceLocation ToGetterNameLoc, ToSetterNameLoc; |
| 4746 | ObjCMethodDecl *ToGetterMethodDecl, *ToSetterMethodDecl; |
| 4747 | ObjCIvarDecl *ToPropertyIvarDecl; |
| 4748 | if (auto Imp = importSeq( |
| 4749 | D->getGetterName(), D->getSetterName(), |
| 4750 | D->getGetterNameLoc(), D->getSetterNameLoc(), |
| 4751 | D->getGetterMethodDecl(), D->getSetterMethodDecl(), |
| 4752 | D->getPropertyIvarDecl())) |
| 4753 | std::tie( |
| 4754 | ToGetterName, ToSetterName, |
| 4755 | ToGetterNameLoc, ToSetterNameLoc, |
| 4756 | ToGetterMethodDecl, ToSetterMethodDecl, |
| 4757 | ToPropertyIvarDecl) = *Imp; |
| 4758 | else |
| 4759 | return Imp.takeError(); |
| 4760 | |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4761 | ToProperty->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4762 | LexicalDC->addDeclInternal(ToProperty); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4763 | |
| 4764 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 4765 | ToProperty->setPropertyAttributesAsWritten( |
| 4766 | D->getPropertyAttributesAsWritten()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4767 | ToProperty->setGetterName(ToGetterName, ToGetterNameLoc); |
| 4768 | ToProperty->setSetterName(ToSetterName, ToSetterNameLoc); |
| 4769 | ToProperty->setGetterMethodDecl(ToGetterMethodDecl); |
| 4770 | ToProperty->setSetterMethodDecl(ToSetterMethodDecl); |
| 4771 | ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4772 | return ToProperty; |
| 4773 | } |
| 4774 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4775 | ExpectedDecl |
| 4776 | ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 4777 | ObjCPropertyDecl *Property; |
| 4778 | if (Error Err = importInto(Property, D->getPropertyDecl())) |
| 4779 | return std::move(Err); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4780 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4781 | DeclContext *DC, *LexicalDC; |
| 4782 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4783 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4784 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4785 | auto *InImpl = cast<ObjCImplDecl>(LexicalDC); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4786 | |
| 4787 | // Import the ivar (for an @synthesize). |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4788 | ObjCIvarDecl *Ivar = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4789 | if (Error Err = importInto(Ivar, D->getPropertyIvarDecl())) |
| 4790 | return std::move(Err); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4791 | |
| 4792 | ObjCPropertyImplDecl *ToImpl |
Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 4793 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 4794 | Property->getQueryKind()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4795 | if (!ToImpl) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4796 | SourceLocation ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc; |
| 4797 | if (auto Imp = importSeq( |
| 4798 | D->getBeginLoc(), D->getLocation(), D->getPropertyIvarDeclLoc())) |
| 4799 | std::tie(ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc) = *Imp; |
| 4800 | else |
| 4801 | return Imp.takeError(); |
| 4802 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4803 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4804 | ToBeginLoc, |
| 4805 | ToLocation, Property, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4806 | D->getPropertyImplementation(), Ivar, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4807 | ToPropertyIvarDeclLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4808 | return ToImpl; |
| 4809 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4810 | ToImpl->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4811 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4812 | } else { |
| 4813 | // Check that we have the same kind of property implementation (@synthesize |
| 4814 | // vs. @dynamic). |
| 4815 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4816 | Importer.ToDiag(ToImpl->getLocation(), |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4817 | diag::warn_odr_objc_property_impl_kind_inconsistent) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4818 | << Property->getDeclName() |
| 4819 | << (ToImpl->getPropertyImplementation() |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4820 | == ObjCPropertyImplDecl::Dynamic); |
| 4821 | Importer.FromDiag(D->getLocation(), |
| 4822 | diag::note_odr_objc_property_impl_kind) |
| 4823 | << D->getPropertyDecl()->getDeclName() |
| 4824 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4825 | |
| 4826 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4827 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4828 | |
| 4829 | // For @synthesize, check that we have the same |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4830 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 4831 | Ivar != ToImpl->getPropertyIvarDecl()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4832 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4833 | diag::warn_odr_objc_synthesize_ivar_inconsistent) |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4834 | << Property->getDeclName() |
| 4835 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 4836 | << Ivar->getDeclName(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4837 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4838 | diag::note_odr_objc_synthesize_ivar_here) |
| 4839 | << D->getPropertyIvarDecl()->getDeclName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4840 | |
| 4841 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4842 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4843 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4844 | // Merge the existing implementation with the new implementation. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4845 | Importer.MapImported(D, ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4846 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4847 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4848 | return ToImpl; |
| 4849 | } |
| 4850 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4851 | ExpectedDecl |
| 4852 | ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4853 | // For template arguments, we adopt the translation unit as our declaration |
| 4854 | // context. This context will be fixed when the actual template declaration |
| 4855 | // is created. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4856 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4857 | // FIXME: Import default argument. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4858 | |
| 4859 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 4860 | if (!BeginLocOrErr) |
| 4861 | return BeginLocOrErr.takeError(); |
| 4862 | |
| 4863 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 4864 | if (!LocationOrErr) |
| 4865 | return LocationOrErr.takeError(); |
| 4866 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4867 | TemplateTypeParmDecl *ToD = nullptr; |
| 4868 | (void)GetImportedOrCreateDecl( |
| 4869 | ToD, D, Importer.getToContext(), |
| 4870 | Importer.getToContext().getTranslationUnitDecl(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4871 | *BeginLocOrErr, *LocationOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4872 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), |
| 4873 | D->wasDeclaredWithTypename(), D->isParameterPack()); |
| 4874 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4875 | } |
| 4876 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4877 | ExpectedDecl |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4878 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4879 | DeclarationName ToDeclName; |
| 4880 | SourceLocation ToLocation, ToInnerLocStart; |
| 4881 | QualType ToType; |
| 4882 | TypeSourceInfo *ToTypeSourceInfo; |
| 4883 | if (auto Imp = importSeq( |
| 4884 | D->getDeclName(), D->getLocation(), D->getType(), D->getTypeSourceInfo(), |
| 4885 | D->getInnerLocStart())) |
| 4886 | std::tie( |
| 4887 | ToDeclName, ToLocation, ToType, ToTypeSourceInfo, |
| 4888 | ToInnerLocStart) = *Imp; |
| 4889 | else |
| 4890 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4891 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4892 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4893 | |
| 4894 | NonTypeTemplateParmDecl *ToD = nullptr; |
| 4895 | (void)GetImportedOrCreateDecl( |
| 4896 | ToD, D, Importer.getToContext(), |
| 4897 | Importer.getToContext().getTranslationUnitDecl(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4898 | ToInnerLocStart, ToLocation, D->getDepth(), |
| 4899 | D->getPosition(), ToDeclName.getAsIdentifierInfo(), ToType, |
| 4900 | D->isParameterPack(), ToTypeSourceInfo); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4901 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4902 | } |
| 4903 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4904 | ExpectedDecl |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4905 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 4906 | // Import the name of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4907 | auto NameOrErr = import(D->getDeclName()); |
| 4908 | if (!NameOrErr) |
| 4909 | return NameOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4910 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4911 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4912 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 4913 | if (!LocationOrErr) |
| 4914 | return LocationOrErr.takeError(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4915 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4916 | // Import template parameters. |
Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 4917 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4918 | if (!TemplateParamsOrErr) |
| 4919 | return TemplateParamsOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4920 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4921 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4922 | |
| 4923 | TemplateTemplateParmDecl *ToD = nullptr; |
| 4924 | (void)GetImportedOrCreateDecl( |
| 4925 | ToD, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4926 | Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr, |
| 4927 | D->getDepth(), D->getPosition(), D->isParameterPack(), |
| 4928 | (*NameOrErr).getAsIdentifierInfo(), |
| 4929 | *TemplateParamsOrErr); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4930 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4931 | } |
| 4932 | |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 4933 | // Returns the definition for a (forward) declaration of a TemplateDecl, if |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4934 | // it has any definition in the redecl chain. |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 4935 | template <typename T> static auto getTemplateDefinition(T *D) -> T * { |
| 4936 | assert(D->getTemplatedDecl() && "Should be called on templates only"); |
| 4937 | auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4938 | if (!ToTemplatedDef) |
| 4939 | return nullptr; |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 4940 | auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate(); |
| 4941 | return cast_or_null<T>(TemplateWithDef); |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4942 | } |
| 4943 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4944 | ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4945 | bool IsFriend = D->getFriendObjectKind() != Decl::FOK_None; |
| 4946 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4947 | // Import the major distinguishing characteristics of this class template. |
| 4948 | DeclContext *DC, *LexicalDC; |
| 4949 | DeclarationName Name; |
| 4950 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4951 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4952 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4953 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4954 | if (ToD) |
| 4955 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4956 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4957 | ClassTemplateDecl *FoundByLookup = nullptr; |
| 4958 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4959 | // We may already have a template of the same name; try to find and match it. |
| 4960 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4961 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4962 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4963 | for (auto *FoundDecl : FoundDecls) { |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4964 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary | |
| 4965 | Decl::IDNS_TagFriend)) |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4966 | continue; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4967 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4968 | Decl *Found = FoundDecl; |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4969 | auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found); |
| 4970 | if (FoundTemplate) { |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4971 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4972 | if (IsStructuralMatch(D, FoundTemplate)) { |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 4973 | ClassTemplateDecl *TemplateWithDef = |
| 4974 | getTemplateDefinition(FoundTemplate); |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4975 | if (D->isThisDeclarationADefinition() && TemplateWithDef) { |
| 4976 | return Importer.MapImported(D, TemplateWithDef); |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4977 | } |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4978 | FoundByLookup = FoundTemplate; |
| 4979 | break; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4980 | } |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4981 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4982 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4983 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4984 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4985 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4986 | if (!ConflictingDecls.empty()) { |
| 4987 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4988 | ConflictingDecls.data(), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4989 | ConflictingDecls.size()); |
| 4990 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4991 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4992 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4993 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4994 | } |
| 4995 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4996 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); |
| 4997 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4998 | // Create the declaration that is being templated. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4999 | CXXRecordDecl *ToTemplated; |
| 5000 | if (Error Err = importInto(ToTemplated, FromTemplated)) |
| 5001 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5002 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5003 | // Create the class template declaration itself. |
Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5004 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5005 | if (!TemplateParamsOrErr) |
| 5006 | return TemplateParamsOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5007 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5008 | ClassTemplateDecl *D2; |
| 5009 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5010 | *TemplateParamsOrErr, ToTemplated)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5011 | return D2; |
| 5012 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5013 | ToTemplated->setDescribedClassTemplate(D2); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5014 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5015 | D2->setAccess(D->getAccess()); |
| 5016 | D2->setLexicalDeclContext(LexicalDC); |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5017 | |
| 5018 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 5019 | DC->addDeclInternal(D2); |
| 5020 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5021 | LexicalDC->addDeclInternal(D2); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5022 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5023 | if (FoundByLookup) { |
| 5024 | auto *Recent = |
| 5025 | const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl()); |
| 5026 | |
| 5027 | // It is possible that during the import of the class template definition |
| 5028 | // we start the import of a fwd friend decl of the very same class template |
| 5029 | // and we add the fwd friend decl to the lookup table. But the ToTemplated |
| 5030 | // had been created earlier and by that time the lookup could not find |
| 5031 | // anything existing, so it has no previous decl. Later, (still during the |
| 5032 | // import of the fwd friend decl) we start to import the definition again |
| 5033 | // and this time the lookup finds the previous fwd friend class template. |
| 5034 | // In this case we must set up the previous decl for the templated decl. |
| 5035 | if (!ToTemplated->getPreviousDecl()) { |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5036 | assert(FoundByLookup->getTemplatedDecl() && |
| 5037 | "Found decl must have its templated decl set"); |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5038 | CXXRecordDecl *PrevTemplated = |
| 5039 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); |
| 5040 | if (ToTemplated != PrevTemplated) |
| 5041 | ToTemplated->setPreviousDecl(PrevTemplated); |
| 5042 | } |
| 5043 | |
| 5044 | D2->setPreviousDecl(Recent); |
| 5045 | } |
| 5046 | |
| 5047 | if (LexicalDC != DC && IsFriend) |
| 5048 | DC->makeDeclVisibleInContext(D2); |
| 5049 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5050 | if (FromTemplated->isCompleteDefinition() && |
| 5051 | !ToTemplated->isCompleteDefinition()) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5052 | // FIXME: Import definition! |
| 5053 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5054 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5055 | return D2; |
| 5056 | } |
| 5057 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5058 | ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5059 | ClassTemplateSpecializationDecl *D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5060 | ClassTemplateDecl *ClassTemplate; |
| 5061 | if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate())) |
| 5062 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5063 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5064 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5065 | DeclContext *DC, *LexicalDC; |
| 5066 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5067 | return std::move(Err); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5068 | |
| 5069 | // Import template arguments. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5070 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5071 | if (Error Err = ImportTemplateArguments( |
| 5072 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5073 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5074 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5075 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5076 | void *InsertPos = nullptr; |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5077 | ClassTemplateSpecializationDecl *PrevDecl = nullptr; |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5078 | ClassTemplatePartialSpecializationDecl *PartialSpec = |
| 5079 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D); |
| 5080 | if (PartialSpec) |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5081 | PrevDecl = |
| 5082 | ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5083 | else |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5084 | PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5085 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5086 | if (PrevDecl) { |
| 5087 | if (IsStructuralMatch(D, PrevDecl)) { |
| 5088 | if (D->isThisDeclarationADefinition() && PrevDecl->getDefinition()) { |
| 5089 | Importer.MapImported(D, PrevDecl->getDefinition()); |
| 5090 | // Import those default field initializers which have been |
| 5091 | // instantiated in the "From" context, but not in the "To" context. |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 5092 | for (auto *FromField : D->fields()) { |
| 5093 | auto ToOrErr = import(FromField); |
| 5094 | if (!ToOrErr) |
| 5095 | return ToOrErr.takeError(); |
| 5096 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5097 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5098 | // Import those methods which have been instantiated in the |
| 5099 | // "From" context, but not in the "To" context. |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 5100 | for (CXXMethodDecl *FromM : D->methods()) { |
| 5101 | auto ToOrErr = import(FromM); |
| 5102 | if (!ToOrErr) |
| 5103 | return ToOrErr.takeError(); |
| 5104 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5105 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5106 | // TODO Import instantiated default arguments. |
| 5107 | // TODO Import instantiated exception specifications. |
| 5108 | // |
| 5109 | // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint |
| 5110 | // what else could be fused during an AST merge. |
| 5111 | return PrevDecl; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5112 | } |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5113 | } else { // ODR violation. |
| 5114 | // FIXME HandleNameConflict |
Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame^] | 5115 | return make_error<ImportError>(ImportError::NameConflict); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5116 | } |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5117 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5118 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5119 | // Import the location of this declaration. |
| 5120 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5121 | if (!BeginLocOrErr) |
| 5122 | return BeginLocOrErr.takeError(); |
| 5123 | ExpectedSLoc IdLocOrErr = import(D->getLocation()); |
| 5124 | if (!IdLocOrErr) |
| 5125 | return IdLocOrErr.takeError(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5126 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5127 | // Create the specialization. |
| 5128 | ClassTemplateSpecializationDecl *D2 = nullptr; |
| 5129 | if (PartialSpec) { |
| 5130 | // Import TemplateArgumentListInfo. |
| 5131 | TemplateArgumentListInfo ToTAInfo; |
| 5132 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
| 5133 | if (Error Err = ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) |
| 5134 | return std::move(Err); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5135 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5136 | QualType CanonInjType; |
| 5137 | if (Error Err = importInto( |
| 5138 | CanonInjType, PartialSpec->getInjectedSpecializationType())) |
| 5139 | return std::move(Err); |
| 5140 | CanonInjType = CanonInjType.getCanonicalType(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5141 | |
Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5142 | auto ToTPListOrErr = import(PartialSpec->getTemplateParameters()); |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5143 | if (!ToTPListOrErr) |
| 5144 | return ToTPListOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5145 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5146 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( |
| 5147 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| 5148 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, ClassTemplate, |
| 5149 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
| 5150 | ToTAInfo, CanonInjType, |
| 5151 | cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl))) |
| 5152 | return D2; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5153 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5154 | // Update InsertPos, because preceding import calls may have invalidated |
| 5155 | // it by adding new specializations. |
| 5156 | if (!ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos)) |
| 5157 | // Add this partial specialization to the class template. |
| 5158 | ClassTemplate->AddPartialSpecialization( |
| 5159 | cast<ClassTemplatePartialSpecializationDecl>(D2), InsertPos); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5160 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5161 | } else { // Not a partial specialization. |
| 5162 | if (GetImportedOrCreateDecl( |
| 5163 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| 5164 | *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs, |
| 5165 | PrevDecl)) |
| 5166 | return D2; |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5167 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5168 | // Update InsertPos, because preceding import calls may have invalidated |
| 5169 | // it by adding new specializations. |
| 5170 | if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos)) |
| 5171 | // Add this specialization to the class template. |
| 5172 | ClassTemplate->AddSpecialization(D2, InsertPos); |
| 5173 | } |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5174 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5175 | D2->setSpecializationKind(D->getSpecializationKind()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5176 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5177 | // Set the context of this specialization/instantiation. |
| 5178 | D2->setLexicalDeclContext(LexicalDC); |
| 5179 | |
| 5180 | // Add to the DC only if it was an explicit specialization/instantiation. |
| 5181 | if (D2->isExplicitInstantiationOrSpecialization()) { |
| 5182 | LexicalDC->addDeclInternal(D2); |
| 5183 | } |
| 5184 | |
| 5185 | // Import the qualifier, if any. |
| 5186 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5187 | D2->setQualifierInfo(*LocOrErr); |
| 5188 | else |
| 5189 | return LocOrErr.takeError(); |
| 5190 | |
| 5191 | if (auto *TSI = D->getTypeAsWritten()) { |
| 5192 | if (auto TInfoOrErr = import(TSI)) |
| 5193 | D2->setTypeAsWritten(*TInfoOrErr); |
| 5194 | else |
| 5195 | return TInfoOrErr.takeError(); |
| 5196 | |
| 5197 | if (auto LocOrErr = import(D->getTemplateKeywordLoc())) |
| 5198 | D2->setTemplateKeywordLoc(*LocOrErr); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5199 | else |
| 5200 | return LocOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5201 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5202 | if (auto LocOrErr = import(D->getExternLoc())) |
| 5203 | D2->setExternLoc(*LocOrErr); |
| 5204 | else |
| 5205 | return LocOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5206 | } |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5207 | |
| 5208 | if (D->getPointOfInstantiation().isValid()) { |
| 5209 | if (auto POIOrErr = import(D->getPointOfInstantiation())) |
| 5210 | D2->setPointOfInstantiation(*POIOrErr); |
| 5211 | else |
| 5212 | return POIOrErr.takeError(); |
| 5213 | } |
| 5214 | |
| 5215 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 5216 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5217 | if (D->isCompleteDefinition()) |
| 5218 | if (Error Err = ImportDefinition(D, D2)) |
| 5219 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5220 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5221 | return D2; |
| 5222 | } |
| 5223 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5224 | ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5225 | // If this variable has a definition in the translation unit we're coming |
| 5226 | // from, |
| 5227 | // but this particular declaration is not that definition, import the |
| 5228 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5229 | auto *Definition = |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5230 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); |
| 5231 | if (Definition && Definition != D->getTemplatedDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5232 | if (ExpectedDecl ImportedDefOrErr = import( |
| 5233 | Definition->getDescribedVarTemplate())) |
| 5234 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5235 | else |
| 5236 | return ImportedDefOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5237 | } |
| 5238 | |
| 5239 | // Import the major distinguishing characteristics of this variable template. |
| 5240 | DeclContext *DC, *LexicalDC; |
| 5241 | DeclarationName Name; |
| 5242 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5243 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5244 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5245 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5246 | if (ToD) |
| 5247 | return ToD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5248 | |
| 5249 | // We may already have a template of the same name; try to find and match it. |
| 5250 | assert(!DC->isFunctionOrMethod() && |
| 5251 | "Variable templates cannot be declared at function scope"); |
| 5252 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5253 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5254 | for (auto *FoundDecl : FoundDecls) { |
| 5255 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5256 | continue; |
| 5257 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5258 | Decl *Found = FoundDecl; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5259 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5260 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 5261 | // The variable templates structurally match; call it the same template. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5262 | Importer.MapImported(D->getTemplatedDecl(), |
| 5263 | FoundTemplate->getTemplatedDecl()); |
| 5264 | return Importer.MapImported(D, FoundTemplate); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5265 | } |
| 5266 | } |
| 5267 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5268 | ConflictingDecls.push_back(FoundDecl); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5269 | } |
| 5270 | |
| 5271 | if (!ConflictingDecls.empty()) { |
| 5272 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 5273 | ConflictingDecls.data(), |
| 5274 | ConflictingDecls.size()); |
| 5275 | } |
| 5276 | |
| 5277 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5278 | // FIXME: Is it possible to get other error than name conflict? |
| 5279 | // (Put this `if` into the previous `if`?) |
| 5280 | return make_error<ImportError>(ImportError::NameConflict); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5281 | |
| 5282 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 5283 | |
| 5284 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5285 | // FIXME: Value not used? |
| 5286 | ExpectedType TypeOrErr = import(DTemplated->getType()); |
| 5287 | if (!TypeOrErr) |
| 5288 | return TypeOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5289 | |
| 5290 | // Create the declaration that is being templated. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5291 | VarDecl *ToTemplated; |
| 5292 | if (Error Err = importInto(ToTemplated, DTemplated)) |
| 5293 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5294 | |
| 5295 | // Create the variable template declaration itself. |
Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5296 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5297 | if (!TemplateParamsOrErr) |
| 5298 | return TemplateParamsOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5299 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5300 | VarTemplateDecl *ToVarTD; |
| 5301 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5302 | Name, *TemplateParamsOrErr, ToTemplated)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5303 | return ToVarTD; |
| 5304 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5305 | ToTemplated->setDescribedVarTemplate(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5306 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5307 | ToVarTD->setAccess(D->getAccess()); |
| 5308 | ToVarTD->setLexicalDeclContext(LexicalDC); |
| 5309 | LexicalDC->addDeclInternal(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5310 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5311 | if (DTemplated->isThisDeclarationADefinition() && |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5312 | !ToTemplated->isThisDeclarationADefinition()) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5313 | // FIXME: Import definition! |
| 5314 | } |
| 5315 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5316 | return ToVarTD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5317 | } |
| 5318 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5319 | ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5320 | VarTemplateSpecializationDecl *D) { |
| 5321 | // If this record has a definition in the translation unit we're coming from, |
| 5322 | // but this particular declaration is not that definition, import the |
| 5323 | // definition and map to that. |
| 5324 | VarDecl *Definition = D->getDefinition(); |
| 5325 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5326 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 5327 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5328 | else |
| 5329 | return ImportedDefOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5330 | } |
| 5331 | |
Simon Pilgrim | 4c146ab | 2019-05-18 11:33:27 +0000 | [diff] [blame] | 5332 | VarTemplateDecl *VarTemplate = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5333 | if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate())) |
| 5334 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5335 | |
| 5336 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5337 | DeclContext *DC, *LexicalDC; |
| 5338 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5339 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5340 | |
| 5341 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5342 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5343 | if (!BeginLocOrErr) |
| 5344 | return BeginLocOrErr.takeError(); |
| 5345 | |
| 5346 | auto IdLocOrErr = import(D->getLocation()); |
| 5347 | if (!IdLocOrErr) |
| 5348 | return IdLocOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5349 | |
| 5350 | // Import template arguments. |
| 5351 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5352 | if (Error Err = ImportTemplateArguments( |
| 5353 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5354 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5355 | |
| 5356 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5357 | void *InsertPos = nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5358 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 5359 | TemplateArgs, InsertPos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5360 | if (D2) { |
| 5361 | // We already have a variable template specialization with these template |
| 5362 | // arguments. |
| 5363 | |
| 5364 | // FIXME: Check for specialization vs. instantiation errors. |
| 5365 | |
| 5366 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 5367 | if (!D->isThisDeclarationADefinition() || |
| 5368 | IsStructuralMatch(D, FoundDef)) { |
| 5369 | // The record types structurally match, or the "from" translation |
| 5370 | // unit only had a forward declaration anyway; call it the same |
| 5371 | // variable. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5372 | return Importer.MapImported(D, FoundDef); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5373 | } |
| 5374 | } |
| 5375 | } else { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5376 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5377 | QualType T; |
| 5378 | if (Error Err = importInto(T, D->getType())) |
| 5379 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5380 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5381 | auto TInfoOrErr = import(D->getTypeSourceInfo()); |
| 5382 | if (!TInfoOrErr) |
| 5383 | return TInfoOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5384 | |
| 5385 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5386 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5387 | D->getTemplateArgsInfo(), ToTAInfo)) |
| 5388 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5389 | |
| 5390 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5391 | // Create a new specialization. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5392 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { |
| 5393 | // Import TemplateArgumentListInfo |
| 5394 | TemplateArgumentListInfo ArgInfos; |
| 5395 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); |
| 5396 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5397 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5398 | *FromTAArgsAsWritten, ArgInfos)) |
| 5399 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5400 | |
Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5401 | auto ToTPListOrErr = import(FromPartial->getTemplateParameters()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5402 | if (!ToTPListOrErr) |
| 5403 | return ToTPListOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5404 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5405 | PartVarSpecDecl *ToPartial; |
| 5406 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5407 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, |
| 5408 | VarTemplate, T, *TInfoOrErr, |
| 5409 | D->getStorageClass(), TemplateArgs, ArgInfos)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5410 | return ToPartial; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5411 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5412 | if (Expected<PartVarSpecDecl *> ToInstOrErr = import( |
| 5413 | FromPartial->getInstantiatedFromMember())) |
| 5414 | ToPartial->setInstantiatedFromMember(*ToInstOrErr); |
| 5415 | else |
| 5416 | return ToInstOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5417 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5418 | if (FromPartial->isMemberSpecialization()) |
| 5419 | ToPartial->setMemberSpecialization(); |
| 5420 | |
| 5421 | D2 = ToPartial; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5422 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5423 | } else { // Full specialization |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5424 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, |
| 5425 | *BeginLocOrErr, *IdLocOrErr, VarTemplate, |
| 5426 | T, *TInfoOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5427 | D->getStorageClass(), TemplateArgs)) |
| 5428 | return D2; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5429 | } |
| 5430 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5431 | if (D->getPointOfInstantiation().isValid()) { |
| 5432 | if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation())) |
| 5433 | D2->setPointOfInstantiation(*POIOrErr); |
| 5434 | else |
| 5435 | return POIOrErr.takeError(); |
| 5436 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5437 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5438 | D2->setSpecializationKind(D->getSpecializationKind()); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5439 | D2->setTemplateArgsInfo(ToTAInfo); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5440 | |
| 5441 | // Add this specialization to the class template. |
| 5442 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 5443 | |
| 5444 | // Import the qualifier, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5445 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5446 | D2->setQualifierInfo(*LocOrErr); |
| 5447 | else |
| 5448 | return LocOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5449 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5450 | if (D->isConstexpr()) |
| 5451 | D2->setConstexpr(true); |
| 5452 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5453 | // Add the specialization to this context. |
| 5454 | D2->setLexicalDeclContext(LexicalDC); |
| 5455 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5456 | |
| 5457 | D2->setAccess(D->getAccess()); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5458 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5459 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5460 | if (Error Err = ImportInitializer(D, D2)) |
| 5461 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5462 | |
| 5463 | return D2; |
| 5464 | } |
| 5465 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5466 | ExpectedDecl |
| 5467 | ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5468 | DeclContext *DC, *LexicalDC; |
| 5469 | DeclarationName Name; |
| 5470 | SourceLocation Loc; |
| 5471 | NamedDecl *ToD; |
| 5472 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5473 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5474 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5475 | |
| 5476 | if (ToD) |
| 5477 | return ToD; |
| 5478 | |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5479 | const FunctionTemplateDecl *FoundByLookup = nullptr; |
| 5480 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5481 | // Try to find a function in our own ("to") context with the same name, same |
| 5482 | // type, and in the same context as the function we're importing. |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5483 | // FIXME Split this into a separate function. |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5484 | if (!LexicalDC->isFunctionOrMethod()) { |
Gabor Marton | e331e63 | 2019-02-18 13:09:27 +0000 | [diff] [blame] | 5485 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5486 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5487 | for (auto *FoundDecl : FoundDecls) { |
| 5488 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5489 | continue; |
| 5490 | |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5491 | if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) { |
| 5492 | if (FoundTemplate->hasExternalFormalLinkage() && |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5493 | D->hasExternalFormalLinkage()) { |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5494 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 5495 | FunctionTemplateDecl *TemplateWithDef = |
| 5496 | getTemplateDefinition(FoundTemplate); |
| 5497 | if (D->isThisDeclarationADefinition() && TemplateWithDef) { |
| 5498 | return Importer.MapImported(D, TemplateWithDef); |
| 5499 | } |
| 5500 | FoundByLookup = FoundTemplate; |
| 5501 | break; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5502 | } |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5503 | // TODO: handle conflicting names |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5504 | } |
| 5505 | } |
| 5506 | } |
| 5507 | } |
| 5508 | |
Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5509 | auto ParamsOrErr = import(D->getTemplateParameters()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5510 | if (!ParamsOrErr) |
| 5511 | return ParamsOrErr.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5512 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5513 | FunctionDecl *TemplatedFD; |
| 5514 | if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl())) |
| 5515 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5516 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5517 | FunctionTemplateDecl *ToFunc; |
| 5518 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5519 | *ParamsOrErr, TemplatedFD)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5520 | return ToFunc; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5521 | |
| 5522 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5523 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5524 | ToFunc->setAccess(D->getAccess()); |
| 5525 | ToFunc->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5526 | LexicalDC->addDeclInternal(ToFunc); |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5527 | |
| 5528 | if (FoundByLookup) { |
| 5529 | auto *Recent = |
| 5530 | const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl()); |
| 5531 | if (!TemplatedFD->getPreviousDecl()) { |
| 5532 | assert(FoundByLookup->getTemplatedDecl() && |
| 5533 | "Found decl must have its templated decl set"); |
| 5534 | auto *PrevTemplated = |
| 5535 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); |
| 5536 | if (TemplatedFD != PrevTemplated) |
| 5537 | TemplatedFD->setPreviousDecl(PrevTemplated); |
| 5538 | } |
| 5539 | ToFunc->setPreviousDecl(Recent); |
| 5540 | } |
| 5541 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5542 | return ToFunc; |
| 5543 | } |
| 5544 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5545 | //---------------------------------------------------------------------------- |
| 5546 | // Import Statements |
| 5547 | //---------------------------------------------------------------------------- |
| 5548 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5549 | ExpectedStmt ASTNodeImporter::VisitStmt(Stmt *S) { |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5550 | Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node) |
| 5551 | << S->getStmtClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5552 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5553 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5554 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5555 | |
| 5556 | ExpectedStmt ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame^] | 5557 | if (Importer.returnWithErrorInTest()) |
| 5558 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5559 | SmallVector<IdentifierInfo *, 4> Names; |
| 5560 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 5561 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5562 | // ToII is nullptr when no symbolic name is given for output operand |
| 5563 | // see ParseStmtAsm::ParseAsmOperandsOpt |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5564 | Names.push_back(ToII); |
| 5565 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5566 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5567 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 5568 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5569 | // ToII is nullptr when no symbolic name is given for input operand |
| 5570 | // see ParseStmtAsm::ParseAsmOperandsOpt |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5571 | Names.push_back(ToII); |
| 5572 | } |
| 5573 | |
| 5574 | SmallVector<StringLiteral *, 4> Clobbers; |
| 5575 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5576 | if (auto ClobberOrErr = import(S->getClobberStringLiteral(I))) |
| 5577 | Clobbers.push_back(*ClobberOrErr); |
| 5578 | else |
| 5579 | return ClobberOrErr.takeError(); |
| 5580 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5581 | } |
| 5582 | |
| 5583 | SmallVector<StringLiteral *, 4> Constraints; |
| 5584 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5585 | if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I))) |
| 5586 | Constraints.push_back(*OutputOrErr); |
| 5587 | else |
| 5588 | return OutputOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5589 | } |
| 5590 | |
| 5591 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5592 | if (auto InputOrErr = import(S->getInputConstraintLiteral(I))) |
| 5593 | Constraints.push_back(*InputOrErr); |
| 5594 | else |
| 5595 | return InputOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5596 | } |
| 5597 | |
Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5598 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs() + |
| 5599 | S->getNumLabels()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5600 | if (Error Err = ImportContainerChecked(S->outputs(), Exprs)) |
| 5601 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5602 | |
Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5603 | if (Error Err = |
| 5604 | ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs())) |
| 5605 | return std::move(Err); |
| 5606 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5607 | if (Error Err = ImportArrayChecked( |
Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5608 | S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs())) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5609 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5610 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5611 | ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc()); |
| 5612 | if (!AsmLocOrErr) |
| 5613 | return AsmLocOrErr.takeError(); |
| 5614 | auto AsmStrOrErr = import(S->getAsmString()); |
| 5615 | if (!AsmStrOrErr) |
| 5616 | return AsmStrOrErr.takeError(); |
| 5617 | ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc()); |
| 5618 | if (!RParenLocOrErr) |
| 5619 | return RParenLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5620 | |
| 5621 | return new (Importer.getToContext()) GCCAsmStmt( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5622 | Importer.getToContext(), |
| 5623 | *AsmLocOrErr, |
| 5624 | S->isSimple(), |
| 5625 | S->isVolatile(), |
| 5626 | S->getNumOutputs(), |
| 5627 | S->getNumInputs(), |
| 5628 | Names.data(), |
| 5629 | Constraints.data(), |
| 5630 | Exprs.data(), |
| 5631 | *AsmStrOrErr, |
| 5632 | S->getNumClobbers(), |
| 5633 | Clobbers.data(), |
Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5634 | S->getNumLabels(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5635 | *RParenLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5636 | } |
| 5637 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5638 | ExpectedStmt ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| 5639 | auto Imp = importSeq(S->getDeclGroup(), S->getBeginLoc(), S->getEndLoc()); |
| 5640 | if (!Imp) |
| 5641 | return Imp.takeError(); |
| 5642 | |
| 5643 | DeclGroupRef ToDG; |
| 5644 | SourceLocation ToBeginLoc, ToEndLoc; |
| 5645 | std::tie(ToDG, ToBeginLoc, ToEndLoc) = *Imp; |
| 5646 | |
| 5647 | return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5648 | } |
| 5649 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5650 | ExpectedStmt ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 5651 | ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc()); |
| 5652 | if (!ToSemiLocOrErr) |
| 5653 | return ToSemiLocOrErr.takeError(); |
| 5654 | return new (Importer.getToContext()) NullStmt( |
| 5655 | *ToSemiLocOrErr, S->hasLeadingEmptyMacro()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5656 | } |
| 5657 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5658 | ExpectedStmt ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5659 | SmallVector<Stmt *, 8> ToStmts(S->size()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5660 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5661 | if (Error Err = ImportContainerChecked(S->body(), ToStmts)) |
| 5662 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5663 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5664 | ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc()); |
| 5665 | if (!ToLBracLocOrErr) |
| 5666 | return ToLBracLocOrErr.takeError(); |
| 5667 | |
| 5668 | ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc()); |
| 5669 | if (!ToRBracLocOrErr) |
| 5670 | return ToRBracLocOrErr.takeError(); |
| 5671 | |
| 5672 | return CompoundStmt::Create( |
| 5673 | Importer.getToContext(), ToStmts, |
| 5674 | *ToLBracLocOrErr, *ToRBracLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5675 | } |
| 5676 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5677 | ExpectedStmt ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| 5678 | auto Imp = importSeq( |
| 5679 | S->getLHS(), S->getRHS(), S->getSubStmt(), S->getCaseLoc(), |
| 5680 | S->getEllipsisLoc(), S->getColonLoc()); |
| 5681 | if (!Imp) |
| 5682 | return Imp.takeError(); |
| 5683 | |
| 5684 | Expr *ToLHS, *ToRHS; |
| 5685 | Stmt *ToSubStmt; |
| 5686 | SourceLocation ToCaseLoc, ToEllipsisLoc, ToColonLoc; |
| 5687 | std::tie(ToLHS, ToRHS, ToSubStmt, ToCaseLoc, ToEllipsisLoc, ToColonLoc) = |
| 5688 | *Imp; |
| 5689 | |
Bruno Ricci | 5b3057175 | 2018-10-28 12:30:53 +0000 | [diff] [blame] | 5690 | auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS, |
| 5691 | ToCaseLoc, ToEllipsisLoc, ToColonLoc); |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5692 | ToStmt->setSubStmt(ToSubStmt); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5693 | |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5694 | return ToStmt; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5695 | } |
| 5696 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5697 | ExpectedStmt ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| 5698 | auto Imp = importSeq(S->getDefaultLoc(), S->getColonLoc(), S->getSubStmt()); |
| 5699 | if (!Imp) |
| 5700 | return Imp.takeError(); |
| 5701 | |
| 5702 | SourceLocation ToDefaultLoc, ToColonLoc; |
| 5703 | Stmt *ToSubStmt; |
| 5704 | std::tie(ToDefaultLoc, ToColonLoc, ToSubStmt) = *Imp; |
| 5705 | |
| 5706 | return new (Importer.getToContext()) DefaultStmt( |
| 5707 | ToDefaultLoc, ToColonLoc, ToSubStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5708 | } |
| 5709 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5710 | ExpectedStmt ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| 5711 | auto Imp = importSeq(S->getIdentLoc(), S->getDecl(), S->getSubStmt()); |
| 5712 | if (!Imp) |
| 5713 | return Imp.takeError(); |
| 5714 | |
| 5715 | SourceLocation ToIdentLoc; |
| 5716 | LabelDecl *ToLabelDecl; |
| 5717 | Stmt *ToSubStmt; |
| 5718 | std::tie(ToIdentLoc, ToLabelDecl, ToSubStmt) = *Imp; |
| 5719 | |
| 5720 | return new (Importer.getToContext()) LabelStmt( |
| 5721 | ToIdentLoc, ToLabelDecl, ToSubStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5722 | } |
| 5723 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5724 | ExpectedStmt ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { |
| 5725 | ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc()); |
| 5726 | if (!ToAttrLocOrErr) |
| 5727 | return ToAttrLocOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5728 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 5729 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5730 | if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs)) |
| 5731 | return std::move(Err); |
| 5732 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 5733 | if (!ToSubStmtOrErr) |
| 5734 | return ToSubStmtOrErr.takeError(); |
| 5735 | |
| 5736 | return AttributedStmt::Create( |
| 5737 | Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5738 | } |
| 5739 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5740 | ExpectedStmt ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| 5741 | auto Imp = importSeq( |
| 5742 | S->getIfLoc(), S->getInit(), S->getConditionVariable(), S->getCond(), |
| 5743 | S->getThen(), S->getElseLoc(), S->getElse()); |
| 5744 | if (!Imp) |
| 5745 | return Imp.takeError(); |
| 5746 | |
| 5747 | SourceLocation ToIfLoc, ToElseLoc; |
| 5748 | Stmt *ToInit, *ToThen, *ToElse; |
| 5749 | VarDecl *ToConditionVariable; |
| 5750 | Expr *ToCond; |
| 5751 | std::tie( |
| 5752 | ToIfLoc, ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, ToElse) = |
| 5753 | *Imp; |
| 5754 | |
Bruno Ricci | b1cc94b | 2018-10-27 21:12:20 +0000 | [diff] [blame] | 5755 | return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->isConstexpr(), |
| 5756 | ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, |
| 5757 | ToElse); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5758 | } |
| 5759 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5760 | ExpectedStmt ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
| 5761 | auto Imp = importSeq( |
| 5762 | S->getInit(), S->getConditionVariable(), S->getCond(), |
| 5763 | S->getBody(), S->getSwitchLoc()); |
| 5764 | if (!Imp) |
| 5765 | return Imp.takeError(); |
| 5766 | |
| 5767 | Stmt *ToInit, *ToBody; |
| 5768 | VarDecl *ToConditionVariable; |
| 5769 | Expr *ToCond; |
| 5770 | SourceLocation ToSwitchLoc; |
| 5771 | std::tie(ToInit, ToConditionVariable, ToCond, ToBody, ToSwitchLoc) = *Imp; |
| 5772 | |
Bruno Ricci | e2806f8 | 2018-10-29 16:12:37 +0000 | [diff] [blame] | 5773 | auto *ToStmt = SwitchStmt::Create(Importer.getToContext(), ToInit, |
| 5774 | ToConditionVariable, ToCond); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5775 | ToStmt->setBody(ToBody); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5776 | ToStmt->setSwitchLoc(ToSwitchLoc); |
| 5777 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5778 | // Now we have to re-chain the cases. |
| 5779 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 5780 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 5781 | SC = SC->getNextSwitchCase()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5782 | Expected<SwitchCase *> ToSCOrErr = import(SC); |
| 5783 | if (!ToSCOrErr) |
| 5784 | return ToSCOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5785 | if (LastChainedSwitchCase) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5786 | LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5787 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5788 | ToStmt->setSwitchCaseList(*ToSCOrErr); |
| 5789 | LastChainedSwitchCase = *ToSCOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5790 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5791 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5792 | return ToStmt; |
| 5793 | } |
| 5794 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5795 | ExpectedStmt ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| 5796 | auto Imp = importSeq( |
| 5797 | S->getConditionVariable(), S->getCond(), S->getBody(), S->getWhileLoc()); |
| 5798 | if (!Imp) |
| 5799 | return Imp.takeError(); |
| 5800 | |
| 5801 | VarDecl *ToConditionVariable; |
| 5802 | Expr *ToCond; |
| 5803 | Stmt *ToBody; |
| 5804 | SourceLocation ToWhileLoc; |
| 5805 | std::tie(ToConditionVariable, ToCond, ToBody, ToWhileLoc) = *Imp; |
| 5806 | |
Bruno Ricci | bacf751 | 2018-10-30 13:42:41 +0000 | [diff] [blame] | 5807 | return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond, |
| 5808 | ToBody, ToWhileLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5809 | } |
| 5810 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5811 | ExpectedStmt ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| 5812 | auto Imp = importSeq( |
| 5813 | S->getBody(), S->getCond(), S->getDoLoc(), S->getWhileLoc(), |
| 5814 | S->getRParenLoc()); |
| 5815 | if (!Imp) |
| 5816 | return Imp.takeError(); |
| 5817 | |
| 5818 | Stmt *ToBody; |
| 5819 | Expr *ToCond; |
| 5820 | SourceLocation ToDoLoc, ToWhileLoc, ToRParenLoc; |
| 5821 | std::tie(ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc) = *Imp; |
| 5822 | |
| 5823 | return new (Importer.getToContext()) DoStmt( |
| 5824 | ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5825 | } |
| 5826 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5827 | ExpectedStmt ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| 5828 | auto Imp = importSeq( |
| 5829 | S->getInit(), S->getCond(), S->getConditionVariable(), S->getInc(), |
| 5830 | S->getBody(), S->getForLoc(), S->getLParenLoc(), S->getRParenLoc()); |
| 5831 | if (!Imp) |
| 5832 | return Imp.takeError(); |
| 5833 | |
| 5834 | Stmt *ToInit; |
| 5835 | Expr *ToCond, *ToInc; |
| 5836 | VarDecl *ToConditionVariable; |
| 5837 | Stmt *ToBody; |
| 5838 | SourceLocation ToForLoc, ToLParenLoc, ToRParenLoc; |
| 5839 | std::tie( |
| 5840 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, |
| 5841 | ToLParenLoc, ToRParenLoc) = *Imp; |
| 5842 | |
| 5843 | return new (Importer.getToContext()) ForStmt( |
| 5844 | Importer.getToContext(), |
| 5845 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc, |
| 5846 | ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5847 | } |
| 5848 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5849 | ExpectedStmt ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| 5850 | auto Imp = importSeq(S->getLabel(), S->getGotoLoc(), S->getLabelLoc()); |
| 5851 | if (!Imp) |
| 5852 | return Imp.takeError(); |
| 5853 | |
| 5854 | LabelDecl *ToLabel; |
| 5855 | SourceLocation ToGotoLoc, ToLabelLoc; |
| 5856 | std::tie(ToLabel, ToGotoLoc, ToLabelLoc) = *Imp; |
| 5857 | |
| 5858 | return new (Importer.getToContext()) GotoStmt( |
| 5859 | ToLabel, ToGotoLoc, ToLabelLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5860 | } |
| 5861 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5862 | ExpectedStmt ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 5863 | auto Imp = importSeq(S->getGotoLoc(), S->getStarLoc(), S->getTarget()); |
| 5864 | if (!Imp) |
| 5865 | return Imp.takeError(); |
| 5866 | |
| 5867 | SourceLocation ToGotoLoc, ToStarLoc; |
| 5868 | Expr *ToTarget; |
| 5869 | std::tie(ToGotoLoc, ToStarLoc, ToTarget) = *Imp; |
| 5870 | |
| 5871 | return new (Importer.getToContext()) IndirectGotoStmt( |
| 5872 | ToGotoLoc, ToStarLoc, ToTarget); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5873 | } |
| 5874 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5875 | ExpectedStmt ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 5876 | ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc()); |
| 5877 | if (!ToContinueLocOrErr) |
| 5878 | return ToContinueLocOrErr.takeError(); |
| 5879 | return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5880 | } |
| 5881 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5882 | ExpectedStmt ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 5883 | auto ToBreakLocOrErr = import(S->getBreakLoc()); |
| 5884 | if (!ToBreakLocOrErr) |
| 5885 | return ToBreakLocOrErr.takeError(); |
| 5886 | return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5887 | } |
| 5888 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5889 | ExpectedStmt ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| 5890 | auto Imp = importSeq( |
| 5891 | S->getReturnLoc(), S->getRetValue(), S->getNRVOCandidate()); |
| 5892 | if (!Imp) |
| 5893 | return Imp.takeError(); |
| 5894 | |
| 5895 | SourceLocation ToReturnLoc; |
| 5896 | Expr *ToRetValue; |
| 5897 | const VarDecl *ToNRVOCandidate; |
| 5898 | std::tie(ToReturnLoc, ToRetValue, ToNRVOCandidate) = *Imp; |
| 5899 | |
Bruno Ricci | 023b1d1 | 2018-10-30 14:40:49 +0000 | [diff] [blame] | 5900 | return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue, |
| 5901 | ToNRVOCandidate); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5902 | } |
| 5903 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5904 | ExpectedStmt ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| 5905 | auto Imp = importSeq( |
| 5906 | S->getCatchLoc(), S->getExceptionDecl(), S->getHandlerBlock()); |
| 5907 | if (!Imp) |
| 5908 | return Imp.takeError(); |
| 5909 | |
| 5910 | SourceLocation ToCatchLoc; |
| 5911 | VarDecl *ToExceptionDecl; |
| 5912 | Stmt *ToHandlerBlock; |
| 5913 | std::tie(ToCatchLoc, ToExceptionDecl, ToHandlerBlock) = *Imp; |
| 5914 | |
| 5915 | return new (Importer.getToContext()) CXXCatchStmt ( |
| 5916 | ToCatchLoc, ToExceptionDecl, ToHandlerBlock); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5917 | } |
| 5918 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5919 | ExpectedStmt ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 5920 | ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc()); |
| 5921 | if (!ToTryLocOrErr) |
| 5922 | return ToTryLocOrErr.takeError(); |
| 5923 | |
| 5924 | ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock()); |
| 5925 | if (!ToTryBlockOrErr) |
| 5926 | return ToTryBlockOrErr.takeError(); |
| 5927 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5928 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 5929 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 5930 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5931 | if (auto ToHandlerOrErr = import(FromHandler)) |
| 5932 | ToHandlers[HI] = *ToHandlerOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5933 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5934 | return ToHandlerOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5935 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5936 | |
| 5937 | return CXXTryStmt::Create( |
| 5938 | Importer.getToContext(), *ToTryLocOrErr,*ToTryBlockOrErr, ToHandlers); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5939 | } |
| 5940 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5941 | ExpectedStmt ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
| 5942 | auto Imp1 = importSeq( |
| 5943 | S->getInit(), S->getRangeStmt(), S->getBeginStmt(), S->getEndStmt(), |
| 5944 | S->getCond(), S->getInc(), S->getLoopVarStmt(), S->getBody()); |
| 5945 | if (!Imp1) |
| 5946 | return Imp1.takeError(); |
| 5947 | auto Imp2 = importSeq( |
| 5948 | S->getForLoc(), S->getCoawaitLoc(), S->getColonLoc(), S->getRParenLoc()); |
| 5949 | if (!Imp2) |
| 5950 | return Imp2.takeError(); |
| 5951 | |
| 5952 | DeclStmt *ToRangeStmt, *ToBeginStmt, *ToEndStmt, *ToLoopVarStmt; |
| 5953 | Expr *ToCond, *ToInc; |
| 5954 | Stmt *ToInit, *ToBody; |
| 5955 | std::tie( |
| 5956 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 5957 | ToBody) = *Imp1; |
| 5958 | SourceLocation ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc; |
| 5959 | std::tie(ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc) = *Imp2; |
| 5960 | |
| 5961 | return new (Importer.getToContext()) CXXForRangeStmt( |
| 5962 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 5963 | ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5964 | } |
| 5965 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5966 | ExpectedStmt |
| 5967 | ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 5968 | auto Imp = importSeq( |
| 5969 | S->getElement(), S->getCollection(), S->getBody(), |
| 5970 | S->getForLoc(), S->getRParenLoc()); |
| 5971 | if (!Imp) |
| 5972 | return Imp.takeError(); |
| 5973 | |
| 5974 | Stmt *ToElement, *ToBody; |
| 5975 | Expr *ToCollection; |
| 5976 | SourceLocation ToForLoc, ToRParenLoc; |
| 5977 | std::tie(ToElement, ToCollection, ToBody, ToForLoc, ToRParenLoc) = *Imp; |
| 5978 | |
| 5979 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement, |
| 5980 | ToCollection, |
| 5981 | ToBody, |
| 5982 | ToForLoc, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5983 | ToRParenLoc); |
| 5984 | } |
| 5985 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5986 | ExpectedStmt ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 5987 | auto Imp = importSeq( |
| 5988 | S->getAtCatchLoc(), S->getRParenLoc(), S->getCatchParamDecl(), |
| 5989 | S->getCatchBody()); |
| 5990 | if (!Imp) |
| 5991 | return Imp.takeError(); |
| 5992 | |
| 5993 | SourceLocation ToAtCatchLoc, ToRParenLoc; |
| 5994 | VarDecl *ToCatchParamDecl; |
| 5995 | Stmt *ToCatchBody; |
| 5996 | std::tie(ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody) = *Imp; |
| 5997 | |
| 5998 | return new (Importer.getToContext()) ObjCAtCatchStmt ( |
| 5999 | ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6000 | } |
| 6001 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6002 | ExpectedStmt ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 6003 | ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc()); |
| 6004 | if (!ToAtFinallyLocOrErr) |
| 6005 | return ToAtFinallyLocOrErr.takeError(); |
| 6006 | ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody()); |
| 6007 | if (!ToAtFinallyStmtOrErr) |
| 6008 | return ToAtFinallyStmtOrErr.takeError(); |
| 6009 | return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr, |
| 6010 | *ToAtFinallyStmtOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6011 | } |
| 6012 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6013 | ExpectedStmt ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 6014 | auto Imp = importSeq( |
| 6015 | S->getAtTryLoc(), S->getTryBody(), S->getFinallyStmt()); |
| 6016 | if (!Imp) |
| 6017 | return Imp.takeError(); |
| 6018 | |
| 6019 | SourceLocation ToAtTryLoc; |
| 6020 | Stmt *ToTryBody, *ToFinallyStmt; |
| 6021 | std::tie(ToAtTryLoc, ToTryBody, ToFinallyStmt) = *Imp; |
| 6022 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6023 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 6024 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 6025 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6026 | if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt)) |
| 6027 | ToCatchStmts[CI] = *ToCatchStmtOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6028 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6029 | return ToCatchStmtOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6030 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6031 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6032 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6033 | ToAtTryLoc, ToTryBody, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6034 | ToCatchStmts.begin(), ToCatchStmts.size(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6035 | ToFinallyStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6036 | } |
| 6037 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6038 | ExpectedStmt ASTNodeImporter::VisitObjCAtSynchronizedStmt |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6039 | (ObjCAtSynchronizedStmt *S) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6040 | auto Imp = importSeq( |
| 6041 | S->getAtSynchronizedLoc(), S->getSynchExpr(), S->getSynchBody()); |
| 6042 | if (!Imp) |
| 6043 | return Imp.takeError(); |
| 6044 | |
| 6045 | SourceLocation ToAtSynchronizedLoc; |
| 6046 | Expr *ToSynchExpr; |
| 6047 | Stmt *ToSynchBody; |
| 6048 | std::tie(ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody) = *Imp; |
| 6049 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6050 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 6051 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 6052 | } |
| 6053 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6054 | ExpectedStmt ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 6055 | ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc()); |
| 6056 | if (!ToThrowLocOrErr) |
| 6057 | return ToThrowLocOrErr.takeError(); |
| 6058 | ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr()); |
| 6059 | if (!ToThrowExprOrErr) |
| 6060 | return ToThrowExprOrErr.takeError(); |
| 6061 | return new (Importer.getToContext()) ObjCAtThrowStmt( |
| 6062 | *ToThrowLocOrErr, *ToThrowExprOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6063 | } |
| 6064 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6065 | ExpectedStmt ASTNodeImporter::VisitObjCAutoreleasePoolStmt( |
| 6066 | ObjCAutoreleasePoolStmt *S) { |
| 6067 | ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc()); |
| 6068 | if (!ToAtLocOrErr) |
| 6069 | return ToAtLocOrErr.takeError(); |
| 6070 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 6071 | if (!ToSubStmtOrErr) |
| 6072 | return ToSubStmtOrErr.takeError(); |
| 6073 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr, |
| 6074 | *ToSubStmtOrErr); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6075 | } |
| 6076 | |
| 6077 | //---------------------------------------------------------------------------- |
| 6078 | // Import Expressions |
| 6079 | //---------------------------------------------------------------------------- |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6080 | ExpectedStmt ASTNodeImporter::VisitExpr(Expr *E) { |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6081 | Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node) |
| 6082 | << E->getStmtClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6083 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6084 | } |
| 6085 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6086 | ExpectedStmt ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| 6087 | auto Imp = importSeq( |
| 6088 | E->getBuiltinLoc(), E->getSubExpr(), E->getWrittenTypeInfo(), |
| 6089 | E->getRParenLoc(), E->getType()); |
| 6090 | if (!Imp) |
| 6091 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6092 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6093 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6094 | Expr *ToSubExpr; |
| 6095 | TypeSourceInfo *ToWrittenTypeInfo; |
| 6096 | QualType ToType; |
| 6097 | std::tie(ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType) = |
| 6098 | *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6099 | |
| 6100 | return new (Importer.getToContext()) VAArgExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6101 | ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType, |
| 6102 | E->isMicrosoftABI()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6103 | } |
| 6104 | |
Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 6105 | ExpectedStmt ASTNodeImporter::VisitChooseExpr(ChooseExpr *E) { |
| 6106 | auto Imp = importSeq(E->getCond(), E->getLHS(), E->getRHS(), |
| 6107 | E->getBuiltinLoc(), E->getRParenLoc(), E->getType()); |
| 6108 | if (!Imp) |
| 6109 | return Imp.takeError(); |
| 6110 | |
| 6111 | Expr *ToCond; |
| 6112 | Expr *ToLHS; |
| 6113 | Expr *ToRHS; |
| 6114 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6115 | QualType ToType; |
| 6116 | std::tie(ToCond, ToLHS, ToRHS, ToBuiltinLoc, ToRParenLoc, ToType) = *Imp; |
| 6117 | |
| 6118 | ExprValueKind VK = E->getValueKind(); |
| 6119 | ExprObjectKind OK = E->getObjectKind(); |
| 6120 | |
| 6121 | bool TypeDependent = ToCond->isTypeDependent(); |
| 6122 | bool ValueDependent = ToCond->isValueDependent(); |
| 6123 | |
| 6124 | // The value of CondIsTrue only matters if the value is not |
| 6125 | // condition-dependent. |
| 6126 | bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue(); |
| 6127 | |
| 6128 | return new (Importer.getToContext()) |
| 6129 | ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK, |
| 6130 | ToRParenLoc, CondIsTrue, TypeDependent, ValueDependent); |
| 6131 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6132 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6133 | ExpectedStmt ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 6134 | ExpectedType TypeOrErr = import(E->getType()); |
| 6135 | if (!TypeOrErr) |
| 6136 | return TypeOrErr.takeError(); |
| 6137 | |
| 6138 | ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc()); |
| 6139 | if (!BeginLocOrErr) |
| 6140 | return BeginLocOrErr.takeError(); |
| 6141 | |
| 6142 | return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6143 | } |
| 6144 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6145 | ExpectedStmt ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { |
| 6146 | auto Imp = importSeq( |
| 6147 | E->getBeginLoc(), E->getType(), E->getFunctionName()); |
| 6148 | if (!Imp) |
| 6149 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6150 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6151 | SourceLocation ToBeginLoc; |
| 6152 | QualType ToType; |
| 6153 | StringLiteral *ToFunctionName; |
| 6154 | std::tie(ToBeginLoc, ToType, ToFunctionName) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6155 | |
Bruno Ricci | 17ff026 | 2018-10-27 19:21:19 +0000 | [diff] [blame] | 6156 | return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType, |
| 6157 | E->getIdentKind(), ToFunctionName); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6158 | } |
| 6159 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6160 | ExpectedStmt ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
| 6161 | auto Imp = importSeq( |
| 6162 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDecl(), |
| 6163 | E->getLocation(), E->getType()); |
| 6164 | if (!Imp) |
| 6165 | return Imp.takeError(); |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6166 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6167 | NestedNameSpecifierLoc ToQualifierLoc; |
| 6168 | SourceLocation ToTemplateKeywordLoc, ToLocation; |
| 6169 | ValueDecl *ToDecl; |
| 6170 | QualType ToType; |
| 6171 | std::tie(ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, ToLocation, ToType) = |
| 6172 | *Imp; |
| 6173 | |
| 6174 | NamedDecl *ToFoundD = nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6175 | if (E->getDecl() != E->getFoundDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6176 | auto FoundDOrErr = import(E->getFoundDecl()); |
| 6177 | if (!FoundDOrErr) |
| 6178 | return FoundDOrErr.takeError(); |
| 6179 | ToFoundD = *FoundDOrErr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6180 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6181 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6182 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6183 | TemplateArgumentListInfo *ToResInfo = nullptr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6184 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6185 | if (Error Err = |
| 6186 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 6187 | return std::move(Err); |
| 6188 | ToResInfo = &ToTAInfo; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6189 | } |
| 6190 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6191 | auto *ToE = DeclRefExpr::Create( |
| 6192 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, |
| 6193 | E->refersToEnclosingVariableOrCapture(), ToLocation, ToType, |
Richard Smith | 715f7a1 | 2019-06-11 17:50:32 +0000 | [diff] [blame] | 6194 | E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse()); |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 6195 | if (E->hadMultipleCandidates()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6196 | ToE->setHadMultipleCandidates(true); |
| 6197 | return ToE; |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 6198 | } |
| 6199 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6200 | ExpectedStmt ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 6201 | ExpectedType TypeOrErr = import(E->getType()); |
| 6202 | if (!TypeOrErr) |
| 6203 | return TypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6204 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6205 | return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6206 | } |
| 6207 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6208 | ExpectedStmt ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { |
| 6209 | ExpectedExpr ToInitOrErr = import(E->getInit()); |
| 6210 | if (!ToInitOrErr) |
| 6211 | return ToInitOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6212 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6213 | ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc()); |
| 6214 | if (!ToEqualOrColonLocOrErr) |
| 6215 | return ToEqualOrColonLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6216 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6217 | SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6218 | // List elements from the second, the first is Init itself |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6219 | for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) { |
| 6220 | if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I))) |
| 6221 | ToIndexExprs[I - 1] = *ToArgOrErr; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6222 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6223 | return ToArgOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6224 | } |
| 6225 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6226 | SmallVector<Designator, 4> ToDesignators(E->size()); |
| 6227 | if (Error Err = ImportContainerChecked(E->designators(), ToDesignators)) |
| 6228 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6229 | |
| 6230 | return DesignatedInitExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6231 | Importer.getToContext(), ToDesignators, |
| 6232 | ToIndexExprs, *ToEqualOrColonLocOrErr, |
| 6233 | E->usesGNUSyntax(), *ToInitOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6234 | } |
| 6235 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6236 | ExpectedStmt |
| 6237 | ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 6238 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6239 | if (!ToTypeOrErr) |
| 6240 | return ToTypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6241 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6242 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6243 | if (!ToLocationOrErr) |
| 6244 | return ToLocationOrErr.takeError(); |
| 6245 | |
| 6246 | return new (Importer.getToContext()) CXXNullPtrLiteralExpr( |
| 6247 | *ToTypeOrErr, *ToLocationOrErr); |
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::VisitIntegerLiteral(IntegerLiteral *E) { |
| 6251 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6252 | if (!ToTypeOrErr) |
| 6253 | return ToTypeOrErr.takeError(); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6254 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6255 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6256 | if (!ToLocationOrErr) |
| 6257 | return ToLocationOrErr.takeError(); |
| 6258 | |
| 6259 | return IntegerLiteral::Create( |
| 6260 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6261 | } |
| 6262 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6263 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6264 | ExpectedStmt ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 6265 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6266 | if (!ToTypeOrErr) |
| 6267 | return ToTypeOrErr.takeError(); |
| 6268 | |
| 6269 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6270 | if (!ToLocationOrErr) |
| 6271 | return ToLocationOrErr.takeError(); |
| 6272 | |
| 6273 | return FloatingLiteral::Create( |
| 6274 | Importer.getToContext(), E->getValue(), E->isExact(), |
| 6275 | *ToTypeOrErr, *ToLocationOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6276 | } |
| 6277 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6278 | ExpectedStmt ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) { |
| 6279 | auto ToTypeOrErr = import(E->getType()); |
| 6280 | if (!ToTypeOrErr) |
| 6281 | return ToTypeOrErr.takeError(); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6282 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6283 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6284 | if (!ToSubExprOrErr) |
| 6285 | return ToSubExprOrErr.takeError(); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6286 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6287 | return new (Importer.getToContext()) ImaginaryLiteral( |
| 6288 | *ToSubExprOrErr, *ToTypeOrErr); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6289 | } |
| 6290 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6291 | ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 6292 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6293 | if (!ToTypeOrErr) |
| 6294 | return ToTypeOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6295 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6296 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6297 | if (!ToLocationOrErr) |
| 6298 | return ToLocationOrErr.takeError(); |
| 6299 | |
| 6300 | return new (Importer.getToContext()) CharacterLiteral( |
| 6301 | E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr); |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 6302 | } |
| 6303 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6304 | ExpectedStmt ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 6305 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6306 | if (!ToTypeOrErr) |
| 6307 | return ToTypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6308 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6309 | SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated()); |
| 6310 | if (Error Err = ImportArrayChecked( |
| 6311 | E->tokloc_begin(), E->tokloc_end(), ToLocations.begin())) |
| 6312 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6313 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6314 | return StringLiteral::Create( |
| 6315 | Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(), |
| 6316 | *ToTypeOrErr, ToLocations.data(), ToLocations.size()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6317 | } |
| 6318 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6319 | ExpectedStmt ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 6320 | auto Imp = importSeq( |
| 6321 | E->getLParenLoc(), E->getTypeSourceInfo(), E->getType(), |
| 6322 | E->getInitializer()); |
| 6323 | if (!Imp) |
| 6324 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6325 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6326 | SourceLocation ToLParenLoc; |
| 6327 | TypeSourceInfo *ToTypeSourceInfo; |
| 6328 | QualType ToType; |
| 6329 | Expr *ToInitializer; |
| 6330 | std::tie(ToLParenLoc, ToTypeSourceInfo, ToType, ToInitializer) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6331 | |
| 6332 | return new (Importer.getToContext()) CompoundLiteralExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6333 | ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(), |
| 6334 | ToInitializer, E->isFileScope()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6335 | } |
| 6336 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6337 | ExpectedStmt ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { |
| 6338 | auto Imp = importSeq( |
| 6339 | E->getBuiltinLoc(), E->getType(), E->getRParenLoc()); |
| 6340 | if (!Imp) |
| 6341 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6342 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6343 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6344 | QualType ToType; |
| 6345 | std::tie(ToBuiltinLoc, ToType, ToRParenLoc) = *Imp; |
| 6346 | |
| 6347 | SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs()); |
| 6348 | if (Error Err = ImportArrayChecked( |
| 6349 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 6350 | ToExprs.begin())) |
| 6351 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6352 | |
| 6353 | return new (Importer.getToContext()) AtomicExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6354 | ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6355 | } |
| 6356 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6357 | ExpectedStmt ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 6358 | auto Imp = importSeq( |
| 6359 | E->getAmpAmpLoc(), E->getLabelLoc(), E->getLabel(), E->getType()); |
| 6360 | if (!Imp) |
| 6361 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6362 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6363 | SourceLocation ToAmpAmpLoc, ToLabelLoc; |
| 6364 | LabelDecl *ToLabel; |
| 6365 | QualType ToType; |
| 6366 | std::tie(ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6367 | |
| 6368 | return new (Importer.getToContext()) AddrLabelExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6369 | ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6370 | } |
| 6371 | |
Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6372 | ExpectedStmt ASTNodeImporter::VisitConstantExpr(ConstantExpr *E) { |
| 6373 | auto Imp = importSeq(E->getSubExpr()); |
| 6374 | if (!Imp) |
| 6375 | return Imp.takeError(); |
| 6376 | |
| 6377 | Expr *ToSubExpr; |
| 6378 | std::tie(ToSubExpr) = *Imp; |
| 6379 | |
Gauthier Harnisch | 83c7b61 | 2019-06-15 10:24:47 +0000 | [diff] [blame] | 6380 | // TODO : Handle APValue::ValueKind that require importing. |
| 6381 | APValue::ValueKind Kind = E->getResultAPValueKind(); |
| 6382 | if (Kind == APValue::Int || Kind == APValue::Float || |
| 6383 | Kind == APValue::FixedPoint || Kind == APValue::ComplexFloat || |
| 6384 | Kind == APValue::ComplexInt) |
| 6385 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, |
| 6386 | E->getAPValueResult()); |
Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 6387 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr); |
Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6388 | } |
| 6389 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6390 | ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| 6391 | auto Imp = importSeq(E->getLParen(), E->getRParen(), E->getSubExpr()); |
| 6392 | if (!Imp) |
| 6393 | return Imp.takeError(); |
| 6394 | |
| 6395 | SourceLocation ToLParen, ToRParen; |
| 6396 | Expr *ToSubExpr; |
| 6397 | std::tie(ToLParen, ToRParen, ToSubExpr) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6398 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6399 | return new (Importer.getToContext()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6400 | ParenExpr(ToLParen, ToRParen, ToSubExpr); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6401 | } |
| 6402 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6403 | ExpectedStmt ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 6404 | SmallVector<Expr *, 4> ToExprs(E->getNumExprs()); |
| 6405 | if (Error Err = ImportContainerChecked(E->exprs(), ToExprs)) |
| 6406 | return std::move(Err); |
| 6407 | |
| 6408 | ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc()); |
| 6409 | if (!ToLParenLocOrErr) |
| 6410 | return ToLParenLocOrErr.takeError(); |
| 6411 | |
| 6412 | ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc()); |
| 6413 | if (!ToRParenLocOrErr) |
| 6414 | return ToRParenLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6415 | |
Bruno Ricci | f49e1ca | 2018-11-20 16:20:40 +0000 | [diff] [blame] | 6416 | return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr, |
| 6417 | ToExprs, *ToRParenLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6418 | } |
| 6419 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6420 | ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| 6421 | auto Imp = importSeq( |
| 6422 | E->getSubStmt(), E->getType(), E->getLParenLoc(), E->getRParenLoc()); |
| 6423 | if (!Imp) |
| 6424 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6425 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6426 | CompoundStmt *ToSubStmt; |
| 6427 | QualType ToType; |
| 6428 | SourceLocation ToLParenLoc, ToRParenLoc; |
| 6429 | std::tie(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6430 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6431 | return new (Importer.getToContext()) StmtExpr( |
| 6432 | ToSubStmt, ToType, ToLParenLoc, ToRParenLoc); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6433 | } |
| 6434 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6435 | ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| 6436 | auto Imp = importSeq( |
| 6437 | E->getSubExpr(), E->getType(), E->getOperatorLoc()); |
| 6438 | if (!Imp) |
| 6439 | return Imp.takeError(); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6440 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6441 | Expr *ToSubExpr; |
| 6442 | QualType ToType; |
| 6443 | SourceLocation ToOperatorLoc; |
| 6444 | std::tie(ToSubExpr, ToType, ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6445 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6446 | return new (Importer.getToContext()) UnaryOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6447 | ToSubExpr, E->getOpcode(), ToType, E->getValueKind(), E->getObjectKind(), |
| 6448 | ToOperatorLoc, E->canOverflow()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6449 | } |
| 6450 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6451 | ExpectedStmt |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6452 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6453 | auto Imp = importSeq(E->getType(), E->getOperatorLoc(), E->getRParenLoc()); |
| 6454 | if (!Imp) |
| 6455 | return Imp.takeError(); |
| 6456 | |
| 6457 | QualType ToType; |
| 6458 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 6459 | std::tie(ToType, ToOperatorLoc, ToRParenLoc) = *Imp; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6460 | |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6461 | if (E->isArgumentType()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6462 | Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr = |
| 6463 | import(E->getArgumentTypeInfo()); |
| 6464 | if (!ToArgumentTypeInfoOrErr) |
| 6465 | return ToArgumentTypeInfoOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6466 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6467 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6468 | E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc, |
| 6469 | ToRParenLoc); |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6470 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6471 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6472 | ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr()); |
| 6473 | if (!ToArgumentExprOrErr) |
| 6474 | return ToArgumentExprOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6475 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6476 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6477 | E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc); |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6478 | } |
| 6479 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6480 | ExpectedStmt ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| 6481 | auto Imp = importSeq( |
| 6482 | E->getLHS(), E->getRHS(), E->getType(), E->getOperatorLoc()); |
| 6483 | if (!Imp) |
| 6484 | return Imp.takeError(); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6485 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6486 | Expr *ToLHS, *ToRHS; |
| 6487 | QualType ToType; |
| 6488 | SourceLocation ToOperatorLoc; |
| 6489 | std::tie(ToLHS, ToRHS, ToType, ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6490 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6491 | return new (Importer.getToContext()) BinaryOperator( |
| 6492 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6493 | E->getObjectKind(), ToOperatorLoc, E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6494 | } |
| 6495 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6496 | ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| 6497 | auto Imp = importSeq( |
| 6498 | E->getCond(), E->getQuestionLoc(), E->getLHS(), E->getColonLoc(), |
| 6499 | E->getRHS(), E->getType()); |
| 6500 | if (!Imp) |
| 6501 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6502 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6503 | Expr *ToCond, *ToLHS, *ToRHS; |
| 6504 | SourceLocation ToQuestionLoc, ToColonLoc; |
| 6505 | QualType ToType; |
| 6506 | std::tie(ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6507 | |
| 6508 | return new (Importer.getToContext()) ConditionalOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6509 | ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType, |
| 6510 | E->getValueKind(), E->getObjectKind()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6511 | } |
| 6512 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6513 | ExpectedStmt ASTNodeImporter::VisitBinaryConditionalOperator( |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6514 | BinaryConditionalOperator *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6515 | auto Imp = importSeq( |
| 6516 | E->getCommon(), E->getOpaqueValue(), E->getCond(), E->getTrueExpr(), |
| 6517 | E->getFalseExpr(), E->getQuestionLoc(), E->getColonLoc(), E->getType()); |
| 6518 | if (!Imp) |
| 6519 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6520 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6521 | Expr *ToCommon, *ToCond, *ToTrueExpr, *ToFalseExpr; |
| 6522 | OpaqueValueExpr *ToOpaqueValue; |
| 6523 | SourceLocation ToQuestionLoc, ToColonLoc; |
| 6524 | QualType ToType; |
| 6525 | std::tie( |
| 6526 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, ToQuestionLoc, |
| 6527 | ToColonLoc, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6528 | |
| 6529 | return new (Importer.getToContext()) BinaryConditionalOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6530 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, |
| 6531 | ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(), |
| 6532 | E->getObjectKind()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6533 | } |
| 6534 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6535 | ExpectedStmt ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 6536 | auto Imp = importSeq( |
| 6537 | E->getBeginLoc(), E->getQueriedTypeSourceInfo(), |
| 6538 | E->getDimensionExpression(), E->getEndLoc(), E->getType()); |
| 6539 | if (!Imp) |
| 6540 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6541 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6542 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6543 | TypeSourceInfo *ToQueriedTypeSourceInfo; |
| 6544 | Expr *ToDimensionExpression; |
| 6545 | QualType ToType; |
| 6546 | std::tie( |
| 6547 | ToBeginLoc, ToQueriedTypeSourceInfo, ToDimensionExpression, ToEndLoc, |
| 6548 | ToType) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6549 | |
| 6550 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6551 | ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(), |
| 6552 | ToDimensionExpression, ToEndLoc, ToType); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6553 | } |
| 6554 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6555 | ExpectedStmt ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 6556 | auto Imp = importSeq( |
| 6557 | E->getBeginLoc(), E->getQueriedExpression(), E->getEndLoc(), E->getType()); |
| 6558 | if (!Imp) |
| 6559 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6560 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6561 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6562 | Expr *ToQueriedExpression; |
| 6563 | QualType ToType; |
| 6564 | std::tie(ToBeginLoc, ToQueriedExpression, ToEndLoc, ToType) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6565 | |
| 6566 | return new (Importer.getToContext()) ExpressionTraitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6567 | ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(), |
| 6568 | ToEndLoc, ToType); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6569 | } |
| 6570 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6571 | ExpectedStmt ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| 6572 | auto Imp = importSeq( |
| 6573 | E->getLocation(), E->getType(), E->getSourceExpr()); |
| 6574 | if (!Imp) |
| 6575 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6576 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6577 | SourceLocation ToLocation; |
| 6578 | QualType ToType; |
| 6579 | Expr *ToSourceExpr; |
| 6580 | std::tie(ToLocation, ToType, ToSourceExpr) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6581 | |
| 6582 | return new (Importer.getToContext()) OpaqueValueExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6583 | ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6584 | } |
| 6585 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6586 | ExpectedStmt ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 6587 | auto Imp = importSeq( |
| 6588 | E->getLHS(), E->getRHS(), E->getType(), E->getRBracketLoc()); |
| 6589 | if (!Imp) |
| 6590 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6591 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6592 | Expr *ToLHS, *ToRHS; |
| 6593 | SourceLocation ToRBracketLoc; |
| 6594 | QualType ToType; |
| 6595 | std::tie(ToLHS, ToRHS, ToType, ToRBracketLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6596 | |
| 6597 | return new (Importer.getToContext()) ArraySubscriptExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6598 | ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(), |
| 6599 | ToRBracketLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6600 | } |
| 6601 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6602 | ExpectedStmt |
| 6603 | ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 6604 | auto Imp = importSeq( |
| 6605 | E->getLHS(), E->getRHS(), E->getType(), E->getComputationLHSType(), |
| 6606 | E->getComputationResultType(), E->getOperatorLoc()); |
| 6607 | if (!Imp) |
| 6608 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6609 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6610 | Expr *ToLHS, *ToRHS; |
| 6611 | QualType ToType, ToComputationLHSType, ToComputationResultType; |
| 6612 | SourceLocation ToOperatorLoc; |
| 6613 | std::tie(ToLHS, ToRHS, ToType, ToComputationLHSType, ToComputationResultType, |
| 6614 | ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6615 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6616 | return new (Importer.getToContext()) CompoundAssignOperator( |
| 6617 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6618 | E->getObjectKind(), ToComputationLHSType, ToComputationResultType, |
| 6619 | ToOperatorLoc, E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6620 | } |
| 6621 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6622 | Expected<CXXCastPath> |
| 6623 | ASTNodeImporter::ImportCastPath(CastExpr *CE) { |
| 6624 | CXXCastPath Path; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6625 | 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] | 6626 | if (auto SpecOrErr = import(*I)) |
| 6627 | Path.push_back(*SpecOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6628 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6629 | return SpecOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6630 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6631 | return Path; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6632 | } |
| 6633 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6634 | ExpectedStmt ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 6635 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6636 | if (!ToTypeOrErr) |
| 6637 | return ToTypeOrErr.takeError(); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6638 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6639 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6640 | if (!ToSubExprOrErr) |
| 6641 | return ToSubExprOrErr.takeError(); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6642 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6643 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6644 | if (!ToBasePathOrErr) |
| 6645 | return ToBasePathOrErr.takeError(); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6646 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6647 | return ImplicitCastExpr::Create( |
| 6648 | Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr, |
| 6649 | &(*ToBasePathOrErr), E->getValueKind()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6650 | } |
| 6651 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6652 | ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
| 6653 | auto Imp1 = importSeq( |
| 6654 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten()); |
| 6655 | if (!Imp1) |
| 6656 | return Imp1.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6657 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6658 | QualType ToType; |
| 6659 | Expr *ToSubExpr; |
| 6660 | TypeSourceInfo *ToTypeInfoAsWritten; |
| 6661 | std::tie(ToType, ToSubExpr, ToTypeInfoAsWritten) = *Imp1; |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6662 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6663 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6664 | if (!ToBasePathOrErr) |
| 6665 | return ToBasePathOrErr.takeError(); |
| 6666 | CXXCastPath *ToBasePath = &(*ToBasePathOrErr); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6667 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6668 | switch (E->getStmtClass()) { |
| 6669 | case Stmt::CStyleCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6670 | auto *CCE = cast<CStyleCastExpr>(E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6671 | ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc()); |
| 6672 | if (!ToLParenLocOrErr) |
| 6673 | return ToLParenLocOrErr.takeError(); |
| 6674 | ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc()); |
| 6675 | if (!ToRParenLocOrErr) |
| 6676 | return ToRParenLocOrErr.takeError(); |
| 6677 | return CStyleCastExpr::Create( |
| 6678 | Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(), |
| 6679 | ToSubExpr, ToBasePath, ToTypeInfoAsWritten, *ToLParenLocOrErr, |
| 6680 | *ToRParenLocOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6681 | } |
| 6682 | |
| 6683 | case Stmt::CXXFunctionalCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6684 | auto *FCE = cast<CXXFunctionalCastExpr>(E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6685 | ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc()); |
| 6686 | if (!ToLParenLocOrErr) |
| 6687 | return ToLParenLocOrErr.takeError(); |
| 6688 | ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc()); |
| 6689 | if (!ToRParenLocOrErr) |
| 6690 | return ToRParenLocOrErr.takeError(); |
| 6691 | return CXXFunctionalCastExpr::Create( |
| 6692 | Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten, |
| 6693 | E->getCastKind(), ToSubExpr, ToBasePath, *ToLParenLocOrErr, |
| 6694 | *ToRParenLocOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6695 | } |
| 6696 | |
| 6697 | case Stmt::ObjCBridgedCastExprClass: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6698 | auto *OCE = cast<ObjCBridgedCastExpr>(E); |
| 6699 | ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc()); |
| 6700 | if (!ToLParenLocOrErr) |
| 6701 | return ToLParenLocOrErr.takeError(); |
| 6702 | ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc()); |
| 6703 | if (!ToBridgeKeywordLocOrErr) |
| 6704 | return ToBridgeKeywordLocOrErr.takeError(); |
| 6705 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 6706 | *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), |
| 6707 | *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6708 | } |
| 6709 | default: |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6710 | llvm_unreachable("Cast expression of unsupported type!"); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6711 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6712 | } |
| 6713 | } |
| 6714 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6715 | ExpectedStmt ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *E) { |
| 6716 | SmallVector<OffsetOfNode, 4> ToNodes; |
| 6717 | for (int I = 0, N = E->getNumComponents(); I < N; ++I) { |
| 6718 | const OffsetOfNode &FromNode = E->getComponent(I); |
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 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6721 | if (FromNode.getKind() != OffsetOfNode::Base) { |
| 6722 | auto Imp = importSeq(FromNode.getBeginLoc(), FromNode.getEndLoc()); |
| 6723 | if (!Imp) |
| 6724 | return Imp.takeError(); |
| 6725 | std::tie(ToBeginLoc, ToEndLoc) = *Imp; |
| 6726 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6727 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6728 | switch (FromNode.getKind()) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6729 | case OffsetOfNode::Array: |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6730 | ToNodes.push_back( |
| 6731 | OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6732 | break; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6733 | case OffsetOfNode::Base: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6734 | auto ToBSOrErr = import(FromNode.getBase()); |
| 6735 | if (!ToBSOrErr) |
| 6736 | return ToBSOrErr.takeError(); |
| 6737 | ToNodes.push_back(OffsetOfNode(*ToBSOrErr)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6738 | break; |
| 6739 | } |
| 6740 | case OffsetOfNode::Field: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6741 | auto ToFieldOrErr = import(FromNode.getField()); |
| 6742 | if (!ToFieldOrErr) |
| 6743 | return ToFieldOrErr.takeError(); |
| 6744 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6745 | break; |
| 6746 | } |
| 6747 | case OffsetOfNode::Identifier: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6748 | IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName()); |
| 6749 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6750 | break; |
| 6751 | } |
| 6752 | } |
| 6753 | } |
| 6754 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6755 | SmallVector<Expr *, 4> ToExprs(E->getNumExpressions()); |
| 6756 | for (int I = 0, N = E->getNumExpressions(); I < N; ++I) { |
| 6757 | ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I)); |
| 6758 | if (!ToIndexExprOrErr) |
| 6759 | return ToIndexExprOrErr.takeError(); |
| 6760 | ToExprs[I] = *ToIndexExprOrErr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6761 | } |
| 6762 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6763 | auto Imp = importSeq( |
| 6764 | E->getType(), E->getTypeSourceInfo(), E->getOperatorLoc(), |
| 6765 | E->getRParenLoc()); |
| 6766 | if (!Imp) |
| 6767 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6768 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6769 | QualType ToType; |
| 6770 | TypeSourceInfo *ToTypeSourceInfo; |
| 6771 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 6772 | std::tie(ToType, ToTypeSourceInfo, ToOperatorLoc, ToRParenLoc) = *Imp; |
| 6773 | |
| 6774 | return OffsetOfExpr::Create( |
| 6775 | Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes, |
| 6776 | ToExprs, ToRParenLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6777 | } |
| 6778 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6779 | ExpectedStmt ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 6780 | auto Imp = importSeq( |
| 6781 | E->getType(), E->getOperand(), E->getBeginLoc(), E->getEndLoc()); |
| 6782 | if (!Imp) |
| 6783 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6784 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6785 | QualType ToType; |
| 6786 | Expr *ToOperand; |
| 6787 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6788 | std::tie(ToType, ToOperand, ToBeginLoc, ToEndLoc) = *Imp; |
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 | CanThrowResult ToCanThrow; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6791 | if (E->isValueDependent()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6792 | ToCanThrow = CT_Dependent; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6793 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6794 | ToCanThrow = E->getValue() ? CT_Can : CT_Cannot; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6795 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6796 | return new (Importer.getToContext()) CXXNoexceptExpr( |
| 6797 | ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6798 | } |
| 6799 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6800 | ExpectedStmt ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| 6801 | auto Imp = importSeq(E->getSubExpr(), E->getType(), E->getThrowLoc()); |
| 6802 | if (!Imp) |
| 6803 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6804 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6805 | Expr *ToSubExpr; |
| 6806 | QualType ToType; |
| 6807 | SourceLocation ToThrowLoc; |
| 6808 | std::tie(ToSubExpr, ToType, ToThrowLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6809 | |
| 6810 | return new (Importer.getToContext()) CXXThrowExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6811 | ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6812 | } |
| 6813 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6814 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| 6815 | ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation()); |
| 6816 | if (!ToUsedLocOrErr) |
| 6817 | return ToUsedLocOrErr.takeError(); |
| 6818 | |
| 6819 | auto ToParamOrErr = import(E->getParam()); |
| 6820 | if (!ToParamOrErr) |
| 6821 | return ToParamOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6822 | |
Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 6823 | auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext()); |
| 6824 | if (!UsedContextOrErr) |
| 6825 | return UsedContextOrErr.takeError(); |
| 6826 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6827 | return CXXDefaultArgExpr::Create( |
Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 6828 | Importer.getToContext(), *ToUsedLocOrErr, *ToParamOrErr, *UsedContextOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6829 | } |
| 6830 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6831 | ExpectedStmt |
| 6832 | ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| 6833 | auto Imp = importSeq( |
| 6834 | E->getType(), E->getTypeSourceInfo(), E->getRParenLoc()); |
| 6835 | if (!Imp) |
| 6836 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6837 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6838 | QualType ToType; |
| 6839 | TypeSourceInfo *ToTypeSourceInfo; |
| 6840 | SourceLocation ToRParenLoc; |
| 6841 | std::tie(ToType, ToTypeSourceInfo, ToRParenLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6842 | |
| 6843 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6844 | ToType, ToTypeSourceInfo, ToRParenLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6845 | } |
| 6846 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6847 | ExpectedStmt |
| 6848 | ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 6849 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6850 | if (!ToSubExprOrErr) |
| 6851 | return ToSubExprOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6852 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6853 | auto ToDtorOrErr = import(E->getTemporary()->getDestructor()); |
| 6854 | if (!ToDtorOrErr) |
| 6855 | return ToDtorOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6856 | |
| 6857 | ASTContext &ToCtx = Importer.getToContext(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6858 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr); |
| 6859 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6860 | } |
| 6861 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6862 | ExpectedStmt |
| 6863 | ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { |
| 6864 | auto Imp = importSeq( |
| 6865 | E->getConstructor(), E->getType(), E->getTypeSourceInfo(), |
| 6866 | E->getParenOrBraceRange()); |
| 6867 | if (!Imp) |
| 6868 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6869 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6870 | CXXConstructorDecl *ToConstructor; |
| 6871 | QualType ToType; |
| 6872 | TypeSourceInfo *ToTypeSourceInfo; |
| 6873 | SourceRange ToParenOrBraceRange; |
| 6874 | std::tie(ToConstructor, ToType, ToTypeSourceInfo, ToParenOrBraceRange) = *Imp; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6875 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6876 | SmallVector<Expr *, 8> ToArgs(E->getNumArgs()); |
| 6877 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 6878 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6879 | |
Bruno Ricci | ddb8f6b | 2018-12-22 14:39:30 +0000 | [diff] [blame] | 6880 | return CXXTemporaryObjectExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6881 | Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs, |
| 6882 | ToParenOrBraceRange, E->hadMultipleCandidates(), |
| 6883 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 6884 | E->requiresZeroInitialization()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6885 | } |
| 6886 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6887 | ExpectedStmt |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6888 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6889 | auto Imp = importSeq( |
| 6890 | E->getType(), E->GetTemporaryExpr(), E->getExtendingDecl()); |
| 6891 | if (!Imp) |
| 6892 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6893 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6894 | QualType ToType; |
| 6895 | Expr *ToTemporaryExpr; |
| 6896 | const ValueDecl *ToExtendingDecl; |
| 6897 | std::tie(ToType, ToTemporaryExpr, ToExtendingDecl) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6898 | |
| 6899 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6900 | ToType, ToTemporaryExpr, E->isBoundToLvalueReference()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6901 | |
| 6902 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6903 | ToMTE->setExtendingDecl(ToExtendingDecl, E->getManglingNumber()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6904 | return ToMTE; |
| 6905 | } |
| 6906 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6907 | ExpectedStmt ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { |
| 6908 | auto Imp = importSeq( |
| 6909 | E->getType(), E->getPattern(), E->getEllipsisLoc()); |
| 6910 | if (!Imp) |
| 6911 | return Imp.takeError(); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6912 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6913 | QualType ToType; |
| 6914 | Expr *ToPattern; |
| 6915 | SourceLocation ToEllipsisLoc; |
| 6916 | std::tie(ToType, ToPattern, ToEllipsisLoc) = *Imp; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6917 | |
| 6918 | return new (Importer.getToContext()) PackExpansionExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6919 | ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions()); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6920 | } |
| 6921 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6922 | ExpectedStmt ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { |
| 6923 | auto Imp = importSeq( |
| 6924 | E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc()); |
| 6925 | if (!Imp) |
| 6926 | return Imp.takeError(); |
| 6927 | |
| 6928 | SourceLocation ToOperatorLoc, ToPackLoc, ToRParenLoc; |
| 6929 | NamedDecl *ToPack; |
| 6930 | std::tie(ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc) = *Imp; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6931 | |
| 6932 | Optional<unsigned> Length; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6933 | if (!E->isValueDependent()) |
| 6934 | Length = E->getPackLength(); |
| 6935 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6936 | SmallVector<TemplateArgument, 8> ToPartialArguments; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6937 | if (E->isPartiallySubstituted()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6938 | if (Error Err = ImportTemplateArguments( |
| 6939 | E->getPartialArguments().data(), |
| 6940 | E->getPartialArguments().size(), |
| 6941 | ToPartialArguments)) |
| 6942 | return std::move(Err); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6943 | } |
| 6944 | |
| 6945 | return SizeOfPackExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6946 | Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc, |
| 6947 | Length, ToPartialArguments); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6948 | } |
| 6949 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6950 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6951 | ExpectedStmt ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) { |
| 6952 | auto Imp = importSeq( |
| 6953 | E->getOperatorNew(), E->getOperatorDelete(), E->getTypeIdParens(), |
| 6954 | E->getArraySize(), E->getInitializer(), E->getType(), |
| 6955 | E->getAllocatedTypeSourceInfo(), E->getSourceRange(), |
| 6956 | E->getDirectInitRange()); |
| 6957 | if (!Imp) |
| 6958 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6959 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6960 | FunctionDecl *ToOperatorNew, *ToOperatorDelete; |
| 6961 | SourceRange ToTypeIdParens, ToSourceRange, ToDirectInitRange; |
Richard Smith | b9fb121 | 2019-05-06 03:47:15 +0000 | [diff] [blame] | 6962 | Optional<Expr *> ToArraySize; |
| 6963 | Expr *ToInitializer; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6964 | QualType ToType; |
| 6965 | TypeSourceInfo *ToAllocatedTypeSourceInfo; |
| 6966 | std::tie( |
| 6967 | ToOperatorNew, ToOperatorDelete, ToTypeIdParens, ToArraySize, ToInitializer, |
| 6968 | ToType, ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6969 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6970 | SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs()); |
| 6971 | if (Error Err = |
| 6972 | ImportContainerChecked(E->placement_arguments(), ToPlacementArgs)) |
| 6973 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6974 | |
Bruno Ricci | 9b6dfac | 2019-01-07 15:04:45 +0000 | [diff] [blame] | 6975 | return CXXNewExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6976 | Importer.getToContext(), E->isGlobalNew(), ToOperatorNew, |
| 6977 | ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(), |
| 6978 | ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(), |
| 6979 | ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange, |
| 6980 | ToDirectInitRange); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6981 | } |
| 6982 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6983 | ExpectedStmt ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 6984 | auto Imp = importSeq( |
| 6985 | E->getType(), E->getOperatorDelete(), E->getArgument(), E->getBeginLoc()); |
| 6986 | if (!Imp) |
| 6987 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6988 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6989 | QualType ToType; |
| 6990 | FunctionDecl *ToOperatorDelete; |
| 6991 | Expr *ToArgument; |
| 6992 | SourceLocation ToBeginLoc; |
| 6993 | std::tie(ToType, ToOperatorDelete, ToArgument, ToBeginLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6994 | |
| 6995 | return new (Importer.getToContext()) CXXDeleteExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6996 | ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(), |
| 6997 | E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument, |
| 6998 | ToBeginLoc); |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6999 | } |
| 7000 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7001 | ExpectedStmt ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| 7002 | auto Imp = importSeq( |
| 7003 | E->getType(), E->getLocation(), E->getConstructor(), |
| 7004 | E->getParenOrBraceRange()); |
| 7005 | if (!Imp) |
| 7006 | return Imp.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7007 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7008 | QualType ToType; |
| 7009 | SourceLocation ToLocation; |
| 7010 | CXXConstructorDecl *ToConstructor; |
| 7011 | SourceRange ToParenOrBraceRange; |
| 7012 | std::tie(ToType, ToLocation, ToConstructor, ToParenOrBraceRange) = *Imp; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7013 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7014 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7015 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7016 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7017 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7018 | return CXXConstructExpr::Create( |
| 7019 | Importer.getToContext(), ToType, ToLocation, ToConstructor, |
| 7020 | E->isElidable(), ToArgs, E->hadMultipleCandidates(), |
| 7021 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 7022 | E->requiresZeroInitialization(), E->getConstructionKind(), |
| 7023 | ToParenOrBraceRange); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7024 | } |
| 7025 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7026 | ExpectedStmt ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *E) { |
| 7027 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7028 | if (!ToSubExprOrErr) |
| 7029 | return ToSubExprOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7030 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7031 | SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects()); |
| 7032 | if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects)) |
| 7033 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7034 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7035 | return ExprWithCleanups::Create( |
| 7036 | Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(), |
| 7037 | ToObjects); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7038 | } |
| 7039 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7040 | ExpectedStmt ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 7041 | auto Imp = importSeq( |
| 7042 | E->getCallee(), E->getType(), E->getRParenLoc()); |
| 7043 | if (!Imp) |
| 7044 | return Imp.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7045 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7046 | Expr *ToCallee; |
| 7047 | QualType ToType; |
| 7048 | SourceLocation ToRParenLoc; |
| 7049 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7050 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7051 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7052 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7053 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7054 | |
Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7055 | return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, |
| 7056 | ToType, E->getValueKind(), ToRParenLoc); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7057 | } |
| 7058 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7059 | ExpectedStmt ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 7060 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7061 | if (!ToTypeOrErr) |
| 7062 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7063 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7064 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7065 | if (!ToLocationOrErr) |
| 7066 | return ToLocationOrErr.takeError(); |
| 7067 | |
| 7068 | return new (Importer.getToContext()) CXXThisExpr( |
| 7069 | *ToLocationOrErr, *ToTypeOrErr, E->isImplicit()); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7070 | } |
| 7071 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7072 | ExpectedStmt ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 7073 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7074 | if (!ToTypeOrErr) |
| 7075 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7076 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7077 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7078 | if (!ToLocationOrErr) |
| 7079 | return ToLocationOrErr.takeError(); |
| 7080 | |
| 7081 | return new (Importer.getToContext()) CXXBoolLiteralExpr( |
| 7082 | E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7083 | } |
| 7084 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7085 | ExpectedStmt ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| 7086 | auto Imp1 = importSeq( |
| 7087 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7088 | E->getTemplateKeywordLoc(), E->getMemberDecl(), E->getType()); |
| 7089 | if (!Imp1) |
| 7090 | return Imp1.takeError(); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7091 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7092 | Expr *ToBase; |
| 7093 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7094 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7095 | ValueDecl *ToMemberDecl; |
| 7096 | QualType ToType; |
| 7097 | std::tie( |
| 7098 | ToBase, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, |
| 7099 | ToType) = *Imp1; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7100 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7101 | auto Imp2 = importSeq( |
| 7102 | E->getFoundDecl().getDecl(), E->getMemberNameInfo().getName(), |
| 7103 | E->getMemberNameInfo().getLoc(), E->getLAngleLoc(), E->getRAngleLoc()); |
| 7104 | if (!Imp2) |
| 7105 | return Imp2.takeError(); |
| 7106 | NamedDecl *ToDecl; |
| 7107 | DeclarationName ToName; |
| 7108 | SourceLocation ToLoc, ToLAngleLoc, ToRAngleLoc; |
| 7109 | std::tie(ToDecl, ToName, ToLoc, ToLAngleLoc, ToRAngleLoc) = *Imp2; |
Peter Szecsi | ef97252 | 2018-05-02 11:52:54 +0000 | [diff] [blame] | 7110 | |
| 7111 | DeclAccessPair ToFoundDecl = |
| 7112 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7113 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7114 | DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7115 | |
Gabor Marton | 5caba30 | 2019-03-07 13:38:20 +0000 | [diff] [blame] | 7116 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7117 | if (E->hasExplicitTemplateArgs()) { |
Gabor Marton | 5caba30 | 2019-03-07 13:38:20 +0000 | [diff] [blame] | 7118 | if (Error Err = |
| 7119 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 7120 | E->template_arguments(), ToTAInfo)) |
| 7121 | return std::move(Err); |
| 7122 | ResInfo = &ToTAInfo; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7123 | } |
| 7124 | |
Richard Smith | 1bbad59 | 2019-06-11 17:50:36 +0000 | [diff] [blame] | 7125 | return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(), |
| 7126 | ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7127 | ToMemberDecl, ToFoundDecl, ToMemberNameInfo, |
| 7128 | ResInfo, ToType, E->getValueKind(), |
| 7129 | E->getObjectKind(), E->isNonOdrUse()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7130 | } |
| 7131 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7132 | ExpectedStmt |
| 7133 | ASTNodeImporter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { |
| 7134 | auto Imp = importSeq( |
| 7135 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7136 | E->getScopeTypeInfo(), E->getColonColonLoc(), E->getTildeLoc()); |
| 7137 | if (!Imp) |
| 7138 | return Imp.takeError(); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7139 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7140 | Expr *ToBase; |
| 7141 | SourceLocation ToOperatorLoc, ToColonColonLoc, ToTildeLoc; |
| 7142 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7143 | TypeSourceInfo *ToScopeTypeInfo; |
| 7144 | std::tie( |
| 7145 | ToBase, ToOperatorLoc, ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, |
| 7146 | ToTildeLoc) = *Imp; |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7147 | |
| 7148 | PseudoDestructorTypeStorage Storage; |
| 7149 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { |
| 7150 | IdentifierInfo *ToII = Importer.Import(FromII); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7151 | ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc()); |
| 7152 | if (!ToDestroyedTypeLocOrErr) |
| 7153 | return ToDestroyedTypeLocOrErr.takeError(); |
| 7154 | Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7155 | } else { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7156 | if (auto ToTIOrErr = import(E->getDestroyedTypeInfo())) |
| 7157 | Storage = PseudoDestructorTypeStorage(*ToTIOrErr); |
| 7158 | else |
| 7159 | return ToTIOrErr.takeError(); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7160 | } |
| 7161 | |
| 7162 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7163 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, |
| 7164 | ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7165 | } |
| 7166 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7167 | ExpectedStmt ASTNodeImporter::VisitCXXDependentScopeMemberExpr( |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7168 | CXXDependentScopeMemberExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7169 | auto Imp = importSeq( |
| 7170 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7171 | E->getTemplateKeywordLoc(), E->getFirstQualifierFoundInScope()); |
| 7172 | if (!Imp) |
| 7173 | return Imp.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7174 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7175 | QualType ToType; |
| 7176 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7177 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7178 | NamedDecl *ToFirstQualifierFoundInScope; |
| 7179 | std::tie( |
| 7180 | ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7181 | ToFirstQualifierFoundInScope) = *Imp; |
| 7182 | |
| 7183 | Expr *ToBase = nullptr; |
| 7184 | if (!E->isImplicitAccess()) { |
| 7185 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7186 | ToBase = *ToBaseOrErr; |
| 7187 | else |
| 7188 | return ToBaseOrErr.takeError(); |
| 7189 | } |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7190 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7191 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7192 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7193 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7194 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7195 | ToTAInfo)) |
| 7196 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7197 | ResInfo = &ToTAInfo; |
| 7198 | } |
| 7199 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7200 | auto ToMemberNameInfoOrErr = importSeq(E->getMember(), E->getMemberLoc()); |
| 7201 | if (!ToMemberNameInfoOrErr) |
| 7202 | return ToMemberNameInfoOrErr.takeError(); |
| 7203 | DeclarationNameInfo ToMemberNameInfo( |
| 7204 | std::get<0>(*ToMemberNameInfoOrErr), std::get<1>(*ToMemberNameInfoOrErr)); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7205 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7206 | if (Error Err = ImportDeclarationNameLoc( |
| 7207 | E->getMemberNameInfo(), ToMemberNameInfo)) |
| 7208 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7209 | |
| 7210 | return CXXDependentScopeMemberExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7211 | Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc, |
| 7212 | ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope, |
| 7213 | ToMemberNameInfo, ResInfo); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7214 | } |
| 7215 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7216 | ExpectedStmt |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7217 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7218 | auto Imp = importSeq( |
| 7219 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDeclName(), |
| 7220 | E->getExprLoc(), E->getLAngleLoc(), E->getRAngleLoc()); |
| 7221 | if (!Imp) |
| 7222 | return Imp.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7223 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7224 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7225 | SourceLocation ToTemplateKeywordLoc, ToExprLoc, ToLAngleLoc, ToRAngleLoc; |
| 7226 | DeclarationName ToDeclName; |
| 7227 | std::tie( |
| 7228 | ToQualifierLoc, ToTemplateKeywordLoc, ToDeclName, ToExprLoc, |
| 7229 | ToLAngleLoc, ToRAngleLoc) = *Imp; |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7230 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7231 | DeclarationNameInfo ToNameInfo(ToDeclName, ToExprLoc); |
| 7232 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7233 | return std::move(Err); |
| 7234 | |
| 7235 | TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7236 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7237 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7238 | if (Error Err = |
| 7239 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 7240 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7241 | ResInfo = &ToTAInfo; |
| 7242 | } |
| 7243 | |
| 7244 | return DependentScopeDeclRefExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7245 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, |
| 7246 | ToNameInfo, ResInfo); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7247 | } |
| 7248 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7249 | ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr( |
| 7250 | CXXUnresolvedConstructExpr *E) { |
| 7251 | auto Imp = importSeq( |
| 7252 | E->getLParenLoc(), E->getRParenLoc(), E->getTypeSourceInfo()); |
| 7253 | if (!Imp) |
| 7254 | return Imp.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7255 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7256 | SourceLocation ToLParenLoc, ToRParenLoc; |
| 7257 | TypeSourceInfo *ToTypeSourceInfo; |
| 7258 | std::tie(ToLParenLoc, ToRParenLoc, ToTypeSourceInfo) = *Imp; |
| 7259 | |
| 7260 | SmallVector<Expr *, 8> ToArgs(E->arg_size()); |
| 7261 | if (Error Err = |
| 7262 | ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin())) |
| 7263 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7264 | |
| 7265 | return CXXUnresolvedConstructExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7266 | Importer.getToContext(), ToTypeSourceInfo, ToLParenLoc, |
| 7267 | llvm::makeArrayRef(ToArgs), ToRParenLoc); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7268 | } |
| 7269 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7270 | ExpectedStmt |
| 7271 | ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { |
| 7272 | Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass()); |
| 7273 | if (!ToNamingClassOrErr) |
| 7274 | return ToNamingClassOrErr.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7275 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7276 | auto ToQualifierLocOrErr = import(E->getQualifierLoc()); |
| 7277 | if (!ToQualifierLocOrErr) |
| 7278 | return ToQualifierLocOrErr.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7279 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7280 | auto ToNameInfoOrErr = importSeq(E->getName(), E->getNameLoc()); |
| 7281 | if (!ToNameInfoOrErr) |
| 7282 | return ToNameInfoOrErr.takeError(); |
| 7283 | DeclarationNameInfo ToNameInfo( |
| 7284 | std::get<0>(*ToNameInfoOrErr), std::get<1>(*ToNameInfoOrErr)); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7285 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7286 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7287 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7288 | |
| 7289 | UnresolvedSet<8> ToDecls; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7290 | for (auto *D : E->decls()) |
| 7291 | if (auto ToDOrErr = import(D)) |
| 7292 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7293 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7294 | return ToDOrErr.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7295 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7296 | if (E->hasExplicitTemplateArgs() && E->getTemplateKeywordLoc().isValid()) { |
| 7297 | TemplateArgumentListInfo ToTAInfo; |
| 7298 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7299 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7300 | ToTAInfo)) |
| 7301 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7302 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7303 | ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc()); |
| 7304 | if (!ToTemplateKeywordLocOrErr) |
| 7305 | return ToTemplateKeywordLocOrErr.takeError(); |
| 7306 | |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7307 | return UnresolvedLookupExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7308 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7309 | *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo, |
| 7310 | ToDecls.begin(), ToDecls.end()); |
| 7311 | } |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7312 | |
| 7313 | return UnresolvedLookupExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7314 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7315 | ToNameInfo, E->requiresADL(), E->isOverloaded(), ToDecls.begin(), |
| 7316 | ToDecls.end()); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7317 | } |
| 7318 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7319 | ExpectedStmt |
| 7320 | ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { |
| 7321 | auto Imp1 = importSeq( |
| 7322 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7323 | E->getTemplateKeywordLoc()); |
| 7324 | if (!Imp1) |
| 7325 | return Imp1.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7326 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7327 | QualType ToType; |
| 7328 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7329 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7330 | std::tie(ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc) = *Imp1; |
| 7331 | |
| 7332 | auto Imp2 = importSeq(E->getName(), E->getNameLoc()); |
| 7333 | if (!Imp2) |
| 7334 | return Imp2.takeError(); |
| 7335 | DeclarationNameInfo ToNameInfo(std::get<0>(*Imp2), std::get<1>(*Imp2)); |
| 7336 | // Import additional name location/type info. |
| 7337 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7338 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7339 | |
| 7340 | UnresolvedSet<8> ToDecls; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7341 | for (Decl *D : E->decls()) |
| 7342 | if (auto ToDOrErr = import(D)) |
| 7343 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7344 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7345 | return ToDOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7346 | |
| 7347 | TemplateArgumentListInfo ToTAInfo; |
| 7348 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7349 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7350 | if (Error Err = |
| 7351 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 7352 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7353 | ResInfo = &ToTAInfo; |
| 7354 | } |
| 7355 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7356 | Expr *ToBase = nullptr; |
| 7357 | if (!E->isImplicitAccess()) { |
| 7358 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7359 | ToBase = *ToBaseOrErr; |
| 7360 | else |
| 7361 | return ToBaseOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7362 | } |
| 7363 | |
| 7364 | return UnresolvedMemberExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7365 | Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType, |
| 7366 | E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7367 | ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end()); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7368 | } |
| 7369 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7370 | ExpectedStmt ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| 7371 | auto Imp = importSeq(E->getCallee(), E->getType(), E->getRParenLoc()); |
| 7372 | if (!Imp) |
| 7373 | return Imp.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7374 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7375 | Expr *ToCallee; |
| 7376 | QualType ToType; |
| 7377 | SourceLocation ToRParenLoc; |
| 7378 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7379 | |
| 7380 | unsigned NumArgs = E->getNumArgs(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7381 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); |
| 7382 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7383 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7384 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7385 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { |
Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7386 | return CXXOperatorCallExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7387 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType, |
Eric Fiselier | 5cdc2cd | 2018-12-12 21:50:55 +0000 | [diff] [blame] | 7388 | OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(), |
| 7389 | OCE->getADLCallKind()); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7390 | } |
| 7391 | |
Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7392 | return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType, |
| 7393 | E->getValueKind(), ToRParenLoc, /*MinNumArgs=*/0, |
| 7394 | E->getADLCallKind()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7395 | } |
| 7396 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7397 | ExpectedStmt ASTNodeImporter::VisitLambdaExpr(LambdaExpr *E) { |
| 7398 | CXXRecordDecl *FromClass = E->getLambdaClass(); |
| 7399 | auto ToClassOrErr = import(FromClass); |
| 7400 | if (!ToClassOrErr) |
| 7401 | return ToClassOrErr.takeError(); |
| 7402 | CXXRecordDecl *ToClass = *ToClassOrErr; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7403 | |
| 7404 | // NOTE: lambda classes are created with BeingDefined flag set up. |
| 7405 | // It means that ImportDefinition doesn't work for them and we should fill it |
| 7406 | // manually. |
Gabor Marton | 302f300 | 2019-02-15 12:04:05 +0000 | [diff] [blame] | 7407 | if (ToClass->isBeingDefined()) |
| 7408 | if (Error Err = ImportDeclContext(FromClass, /*ForceImport = */ true)) |
| 7409 | return std::move(Err); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7410 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7411 | auto ToCallOpOrErr = import(E->getCallOperator()); |
| 7412 | if (!ToCallOpOrErr) |
| 7413 | return ToCallOpOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7414 | |
| 7415 | ToClass->completeDefinition(); |
| 7416 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7417 | SmallVector<LambdaCapture, 8> ToCaptures; |
| 7418 | ToCaptures.reserve(E->capture_size()); |
| 7419 | for (const auto &FromCapture : E->captures()) { |
| 7420 | if (auto ToCaptureOrErr = import(FromCapture)) |
| 7421 | ToCaptures.push_back(*ToCaptureOrErr); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7422 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7423 | return ToCaptureOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7424 | } |
| 7425 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7426 | SmallVector<Expr *, 8> ToCaptureInits(E->capture_size()); |
| 7427 | if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits)) |
| 7428 | return std::move(Err); |
| 7429 | |
| 7430 | auto Imp = importSeq( |
| 7431 | E->getIntroducerRange(), E->getCaptureDefaultLoc(), E->getEndLoc()); |
| 7432 | if (!Imp) |
| 7433 | return Imp.takeError(); |
| 7434 | |
| 7435 | SourceRange ToIntroducerRange; |
| 7436 | SourceLocation ToCaptureDefaultLoc, ToEndLoc; |
| 7437 | std::tie(ToIntroducerRange, ToCaptureDefaultLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7438 | |
Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 7439 | return LambdaExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7440 | Importer.getToContext(), ToClass, ToIntroducerRange, |
| 7441 | E->getCaptureDefault(), ToCaptureDefaultLoc, ToCaptures, |
| 7442 | E->hasExplicitParameters(), E->hasExplicitResultType(), ToCaptureInits, |
| 7443 | ToEndLoc, E->containsUnexpandedParameterPack()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7444 | } |
| 7445 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7446 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7447 | ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) { |
| 7448 | auto Imp = importSeq(E->getLBraceLoc(), E->getRBraceLoc(), E->getType()); |
| 7449 | if (!Imp) |
| 7450 | return Imp.takeError(); |
| 7451 | |
| 7452 | SourceLocation ToLBraceLoc, ToRBraceLoc; |
| 7453 | QualType ToType; |
| 7454 | std::tie(ToLBraceLoc, ToRBraceLoc, ToType) = *Imp; |
| 7455 | |
| 7456 | SmallVector<Expr *, 4> ToExprs(E->getNumInits()); |
| 7457 | if (Error Err = ImportContainerChecked(E->inits(), ToExprs)) |
| 7458 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7459 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7460 | ASTContext &ToCtx = Importer.getToContext(); |
| 7461 | InitListExpr *To = new (ToCtx) InitListExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7462 | ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc); |
| 7463 | To->setType(ToType); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7464 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7465 | if (E->hasArrayFiller()) { |
| 7466 | if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller())) |
| 7467 | To->setArrayFiller(*ToFillerOrErr); |
| 7468 | else |
| 7469 | return ToFillerOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7470 | } |
| 7471 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7472 | if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) { |
| 7473 | if (auto ToFDOrErr = import(FromFD)) |
| 7474 | To->setInitializedFieldInUnion(*ToFDOrErr); |
| 7475 | else |
| 7476 | return ToFDOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7477 | } |
| 7478 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7479 | if (InitListExpr *SyntForm = E->getSyntacticForm()) { |
| 7480 | if (auto ToSyntFormOrErr = import(SyntForm)) |
| 7481 | To->setSyntacticForm(*ToSyntFormOrErr); |
| 7482 | else |
| 7483 | return ToSyntFormOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7484 | } |
| 7485 | |
Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7486 | // Copy InitListExprBitfields, which are not handled in the ctor of |
| 7487 | // InitListExpr. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7488 | To->sawArrayRangeDesignator(E->hadArrayRangeDesignator()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7489 | |
| 7490 | return To; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7491 | } |
| 7492 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7493 | ExpectedStmt ASTNodeImporter::VisitCXXStdInitializerListExpr( |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7494 | CXXStdInitializerListExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7495 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7496 | if (!ToTypeOrErr) |
| 7497 | return ToTypeOrErr.takeError(); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7498 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7499 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7500 | if (!ToSubExprOrErr) |
| 7501 | return ToSubExprOrErr.takeError(); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7502 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7503 | return new (Importer.getToContext()) CXXStdInitializerListExpr( |
| 7504 | *ToTypeOrErr, *ToSubExprOrErr); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7505 | } |
| 7506 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7507 | ExpectedStmt ASTNodeImporter::VisitCXXInheritedCtorInitExpr( |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7508 | CXXInheritedCtorInitExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7509 | auto Imp = importSeq(E->getLocation(), E->getType(), E->getConstructor()); |
| 7510 | if (!Imp) |
| 7511 | return Imp.takeError(); |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7512 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7513 | SourceLocation ToLocation; |
| 7514 | QualType ToType; |
| 7515 | CXXConstructorDecl *ToConstructor; |
| 7516 | std::tie(ToLocation, ToType, ToConstructor) = *Imp; |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7517 | |
| 7518 | return new (Importer.getToContext()) CXXInheritedCtorInitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7519 | ToLocation, ToType, ToConstructor, E->constructsVBase(), |
| 7520 | E->inheritedFromVBase()); |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7521 | } |
| 7522 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7523 | ExpectedStmt ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 7524 | auto Imp = importSeq(E->getType(), E->getCommonExpr(), E->getSubExpr()); |
| 7525 | if (!Imp) |
| 7526 | return Imp.takeError(); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7527 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7528 | QualType ToType; |
| 7529 | Expr *ToCommonExpr, *ToSubExpr; |
| 7530 | std::tie(ToType, ToCommonExpr, ToSubExpr) = *Imp; |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7531 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7532 | return new (Importer.getToContext()) ArrayInitLoopExpr( |
| 7533 | ToType, ToCommonExpr, ToSubExpr); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7534 | } |
| 7535 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7536 | ExpectedStmt ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 7537 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7538 | if (!ToTypeOrErr) |
| 7539 | return ToTypeOrErr.takeError(); |
| 7540 | return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7541 | } |
| 7542 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7543 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 7544 | ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc()); |
| 7545 | if (!ToBeginLocOrErr) |
| 7546 | return ToBeginLocOrErr.takeError(); |
| 7547 | |
| 7548 | auto ToFieldOrErr = import(E->getField()); |
| 7549 | if (!ToFieldOrErr) |
| 7550 | return ToFieldOrErr.takeError(); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7551 | |
Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 7552 | auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext()); |
| 7553 | if (!UsedContextOrErr) |
| 7554 | return UsedContextOrErr.takeError(); |
| 7555 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7556 | return CXXDefaultInitExpr::Create( |
Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 7557 | Importer.getToContext(), *ToBeginLocOrErr, *ToFieldOrErr, *UsedContextOrErr); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7558 | } |
| 7559 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7560 | ExpectedStmt ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 7561 | auto Imp = importSeq( |
| 7562 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten(), |
| 7563 | E->getOperatorLoc(), E->getRParenLoc(), E->getAngleBrackets()); |
| 7564 | if (!Imp) |
| 7565 | return Imp.takeError(); |
| 7566 | |
| 7567 | QualType ToType; |
| 7568 | Expr *ToSubExpr; |
| 7569 | TypeSourceInfo *ToTypeInfoAsWritten; |
| 7570 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 7571 | SourceRange ToAngleBrackets; |
| 7572 | std::tie( |
| 7573 | ToType, ToSubExpr, ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, |
| 7574 | ToAngleBrackets) = *Imp; |
| 7575 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7576 | ExprValueKind VK = E->getValueKind(); |
| 7577 | CastKind CK = E->getCastKind(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7578 | auto ToBasePathOrErr = ImportCastPath(E); |
| 7579 | if (!ToBasePathOrErr) |
| 7580 | return ToBasePathOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7581 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7582 | if (isa<CXXStaticCastExpr>(E)) { |
| 7583 | return CXXStaticCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7584 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7585 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7586 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 7587 | return CXXDynamicCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7588 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7589 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7590 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 7591 | return CXXReinterpretCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7592 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7593 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Raphael Isemann | c705bb8 | 2018-08-20 16:20:01 +0000 | [diff] [blame] | 7594 | } else if (isa<CXXConstCastExpr>(E)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7595 | return CXXConstCastExpr::Create( |
| 7596 | Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten, |
| 7597 | ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7598 | } else { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7599 | llvm_unreachable("Unknown cast type"); |
| 7600 | return make_error<ImportError>(); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7601 | } |
| 7602 | } |
| 7603 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7604 | ExpectedStmt ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7605 | SubstNonTypeTemplateParmExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7606 | auto Imp = importSeq( |
| 7607 | E->getType(), E->getExprLoc(), E->getParameter(), E->getReplacement()); |
| 7608 | if (!Imp) |
| 7609 | return Imp.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7610 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7611 | QualType ToType; |
| 7612 | SourceLocation ToExprLoc; |
| 7613 | NonTypeTemplateParmDecl *ToParameter; |
| 7614 | Expr *ToReplacement; |
| 7615 | std::tie(ToType, ToExprLoc, ToParameter, ToReplacement) = *Imp; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7616 | |
| 7617 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7618 | ToType, E->getValueKind(), ToExprLoc, ToParameter, ToReplacement); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7619 | } |
| 7620 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7621 | ExpectedStmt ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { |
| 7622 | auto Imp = importSeq( |
| 7623 | E->getType(), E->getBeginLoc(), E->getEndLoc()); |
| 7624 | if (!Imp) |
| 7625 | return Imp.takeError(); |
| 7626 | |
| 7627 | QualType ToType; |
| 7628 | SourceLocation ToBeginLoc, ToEndLoc; |
| 7629 | std::tie(ToType, ToBeginLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7630 | |
| 7631 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7632 | if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs)) |
| 7633 | return std::move(Err); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7634 | |
| 7635 | // According to Sema::BuildTypeTrait(), if E is value-dependent, |
| 7636 | // Value is always false. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7637 | bool ToValue = (E->isValueDependent() ? false : E->getValue()); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7638 | |
| 7639 | return TypeTraitExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7640 | Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs, |
| 7641 | ToEndLoc, ToValue); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7642 | } |
| 7643 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7644 | ExpectedStmt ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { |
| 7645 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7646 | if (!ToTypeOrErr) |
| 7647 | return ToTypeOrErr.takeError(); |
| 7648 | |
| 7649 | auto ToSourceRangeOrErr = import(E->getSourceRange()); |
| 7650 | if (!ToSourceRangeOrErr) |
| 7651 | return ToSourceRangeOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7652 | |
| 7653 | if (E->isTypeOperand()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7654 | if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo())) |
| 7655 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7656 | *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr); |
| 7657 | else |
| 7658 | return ToTSIOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7659 | } |
| 7660 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7661 | ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand()); |
| 7662 | if (!ToExprOperandOrErr) |
| 7663 | return ToExprOperandOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7664 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7665 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7666 | *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7667 | } |
| 7668 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7669 | void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod, |
| 7670 | CXXMethodDecl *FromMethod) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7671 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) { |
| 7672 | if (auto ImportedOrErr = import(FromOverriddenMethod)) |
| 7673 | ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>( |
| 7674 | (*ImportedOrErr)->getCanonicalDecl())); |
| 7675 | else |
| 7676 | consumeError(ImportedOrErr.takeError()); |
| 7677 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7678 | } |
| 7679 | |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7680 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7681 | ASTContext &FromContext, FileManager &FromFileManager, |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7682 | bool MinimalImport, |
| 7683 | ASTImporterLookupTable *LookupTable) |
| 7684 | : LookupTable(LookupTable), ToContext(ToContext), FromContext(FromContext), |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7685 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
| 7686 | Minimal(MinimalImport) { |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7687 | |
| 7688 | ImportedDecls[FromContext.getTranslationUnitDecl()] = |
| 7689 | ToContext.getTranslationUnitDecl(); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7690 | } |
| 7691 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7692 | ASTImporter::~ASTImporter() = default; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7693 | |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7694 | Optional<unsigned> ASTImporter::getFieldIndex(Decl *F) { |
| 7695 | assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) && |
| 7696 | "Try to get field index for non-field."); |
| 7697 | |
| 7698 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); |
| 7699 | if (!Owner) |
| 7700 | return None; |
| 7701 | |
| 7702 | unsigned Index = 0; |
| 7703 | for (const auto *D : Owner->decls()) { |
| 7704 | if (D == F) |
| 7705 | return Index; |
| 7706 | |
| 7707 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) |
| 7708 | ++Index; |
| 7709 | } |
| 7710 | |
| 7711 | llvm_unreachable("Field was not found in its parent context."); |
| 7712 | |
| 7713 | return None; |
| 7714 | } |
| 7715 | |
| 7716 | ASTImporter::FoundDeclsTy |
| 7717 | ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) { |
| 7718 | // We search in the redecl context because of transparent contexts. |
| 7719 | // E.g. a simple C language enum is a transparent context: |
| 7720 | // enum E { A, B }; |
| 7721 | // Now if we had a global variable in the TU |
| 7722 | // int A; |
| 7723 | // then the enum constant 'A' and the variable 'A' violates ODR. |
| 7724 | // We can diagnose this only if we search in the redecl context. |
| 7725 | DeclContext *ReDC = DC->getRedeclContext(); |
| 7726 | if (LookupTable) { |
| 7727 | ASTImporterLookupTable::LookupResult LookupResult = |
| 7728 | LookupTable->lookup(ReDC, Name); |
| 7729 | return FoundDeclsTy(LookupResult.begin(), LookupResult.end()); |
| 7730 | } else { |
| 7731 | // FIXME Can we remove this kind of lookup? |
| 7732 | // Or lldb really needs this C/C++ lookup? |
| 7733 | FoundDeclsTy Result; |
| 7734 | ReDC->localUncachedLookup(Name, Result); |
| 7735 | return Result; |
| 7736 | } |
| 7737 | } |
| 7738 | |
| 7739 | void ASTImporter::AddToLookupTable(Decl *ToD) { |
| 7740 | if (LookupTable) |
| 7741 | if (auto *ToND = dyn_cast<NamedDecl>(ToD)) |
| 7742 | LookupTable->add(ToND); |
| 7743 | } |
| 7744 | |
Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 7745 | Expected<Decl *> ASTImporter::ImportImpl(Decl *FromD) { |
| 7746 | // Import the decl using ASTNodeImporter. |
| 7747 | ASTNodeImporter Importer(*this); |
| 7748 | return Importer.Visit(FromD); |
| 7749 | } |
| 7750 | |
| 7751 | void ASTImporter::RegisterImportedDecl(Decl *FromD, Decl *ToD) { |
| 7752 | MapImported(FromD, ToD); |
Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 7753 | } |
| 7754 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7755 | Expected<QualType> ASTImporter::Import(QualType FromT) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7756 | if (FromT.isNull()) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7757 | return QualType{}; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7758 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7759 | const Type *FromTy = FromT.getTypePtr(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7760 | |
| 7761 | // Check whether we've already imported this type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7762 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7763 | = ImportedTypes.find(FromTy); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7764 | if (Pos != ImportedTypes.end()) |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7765 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7766 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7767 | // Import the type |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7768 | ASTNodeImporter Importer(*this); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7769 | ExpectedType ToTOrErr = Importer.Visit(FromTy); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7770 | if (!ToTOrErr) |
| 7771 | return ToTOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7772 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7773 | // Record the imported type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7774 | ImportedTypes[FromTy] = (*ToTOrErr).getTypePtr(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7775 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7776 | return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7777 | } |
| 7778 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7779 | Expected<TypeSourceInfo *> ASTImporter::Import(TypeSourceInfo *FromTSI) { |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7780 | if (!FromTSI) |
| 7781 | return FromTSI; |
| 7782 | |
| 7783 | // FIXME: For now we just create a "trivial" type source info based |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 7784 | // on the type and a single location. Implement a real version of this. |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7785 | ExpectedType TOrErr = Import(FromTSI->getType()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7786 | if (!TOrErr) |
| 7787 | return TOrErr.takeError(); |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7788 | ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7789 | if (!BeginLocOrErr) |
| 7790 | return BeginLocOrErr.takeError(); |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7791 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7792 | return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr); |
| 7793 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7794 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7795 | Expected<Attr *> ASTImporter::Import(const Attr *FromAttr) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7796 | Attr *ToAttr = FromAttr->clone(ToContext); |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7797 | if (auto ToRangeOrErr = Import(FromAttr->getRange())) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7798 | ToAttr->setRange(*ToRangeOrErr); |
| 7799 | else |
| 7800 | return ToRangeOrErr.takeError(); |
| 7801 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7802 | return ToAttr; |
Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 7803 | } |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 7804 | |
Gabor Marton | be77a98 | 2018-12-12 11:22:55 +0000 | [diff] [blame] | 7805 | Decl *ASTImporter::GetAlreadyImportedOrNull(const Decl *FromD) const { |
| 7806 | auto Pos = ImportedDecls.find(FromD); |
| 7807 | if (Pos != ImportedDecls.end()) |
| 7808 | return Pos->second; |
| 7809 | else |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7810 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7811 | } |
| 7812 | |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 7813 | TranslationUnitDecl *ASTImporter::GetFromTU(Decl *ToD) { |
| 7814 | auto FromDPos = ImportedFromDecls.find(ToD); |
| 7815 | if (FromDPos == ImportedFromDecls.end()) |
| 7816 | return nullptr; |
| 7817 | return FromDPos->second->getTranslationUnitDecl(); |
| 7818 | } |
| 7819 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7820 | Expected<Decl *> ASTImporter::Import(Decl *FromD) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7821 | if (!FromD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7822 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7823 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7824 | |
Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame^] | 7825 | // Check whether there was a previous failed import. |
| 7826 | // If yes return the existing error. |
| 7827 | if (auto Error = getImportDeclErrorIfAny(FromD)) |
| 7828 | return make_error<ImportError>(*Error); |
| 7829 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7830 | // Check whether we've already imported this declaration. |
| 7831 | Decl *ToD = GetAlreadyImportedOrNull(FromD); |
| 7832 | if (ToD) { |
| 7833 | // If FromD has some updated flags after last import, apply it |
| 7834 | updateFlags(FromD, ToD); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7835 | return ToD; |
| 7836 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7837 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7838 | // Import the declaration. |
Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 7839 | ExpectedDecl ToDOrErr = ImportImpl(FromD); |
Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame^] | 7840 | if (!ToDOrErr) { |
| 7841 | // Failed to import. |
| 7842 | |
| 7843 | auto Pos = ImportedDecls.find(FromD); |
| 7844 | if (Pos != ImportedDecls.end()) { |
| 7845 | // Import failed after the object was created. |
| 7846 | // Remove all references to it. |
| 7847 | auto *ToD = Pos->second; |
| 7848 | ImportedDecls.erase(Pos); |
| 7849 | |
| 7850 | // ImportedDecls and ImportedFromDecls are not symmetric. It may happen |
| 7851 | // (e.g. with namespaces) that several decls from the 'from' context are |
| 7852 | // mapped to the same decl in the 'to' context. If we removed entries |
| 7853 | // from the LookupTable here then we may end up removing them multiple |
| 7854 | // times. |
| 7855 | |
| 7856 | // The Lookuptable contains decls only which are in the 'to' context. |
| 7857 | // Remove from the Lookuptable only if it is *imported* into the 'to' |
| 7858 | // context (and do not remove it if it was added during the initial |
| 7859 | // traverse of the 'to' context). |
| 7860 | auto PosF = ImportedFromDecls.find(ToD); |
| 7861 | if (PosF != ImportedFromDecls.end()) { |
| 7862 | if (LookupTable) |
| 7863 | if (auto *ToND = dyn_cast<NamedDecl>(ToD)) |
| 7864 | LookupTable->remove(ToND); |
| 7865 | ImportedFromDecls.erase(PosF); |
| 7866 | } |
| 7867 | |
| 7868 | // FIXME: AST may contain remaining references to the failed object. |
| 7869 | } |
| 7870 | |
| 7871 | // Error encountered for the first time. |
| 7872 | assert(!getImportDeclErrorIfAny(FromD) && |
| 7873 | "Import error already set for Decl."); |
| 7874 | |
| 7875 | // After takeError the error is not usable any more in ToDOrErr. |
| 7876 | // Get a copy of the error object (any more simple solution for this?). |
| 7877 | ImportError ErrOut; |
| 7878 | handleAllErrors(ToDOrErr.takeError(), |
| 7879 | [&ErrOut](const ImportError &E) { ErrOut = E; }); |
| 7880 | setImportDeclError(FromD, ErrOut); |
| 7881 | // Do not return ToDOrErr, error was taken out of it. |
| 7882 | return make_error<ImportError>(ErrOut); |
| 7883 | } |
| 7884 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7885 | ToD = *ToDOrErr; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7886 | |
Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame^] | 7887 | // FIXME: Handle the "already imported with error" case. We can get here |
| 7888 | // nullptr only if GetImportedOrCreateDecl returned nullptr (after a |
| 7889 | // previously failed create was requested). |
| 7890 | // Later GetImportedOrCreateDecl can be updated to return the error. |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 7891 | if (!ToD) { |
Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame^] | 7892 | auto Err = getImportDeclErrorIfAny(FromD); |
| 7893 | assert(Err); |
| 7894 | return make_error<ImportError>(*Err); |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 7895 | } |
| 7896 | |
Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 7897 | // Make sure that ImportImpl registered the imported decl. |
| 7898 | assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?"); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7899 | // Notify subclasses. |
| 7900 | Imported(FromD, ToD); |
| 7901 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 7902 | updateFlags(FromD, ToD); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7903 | return ToDOrErr; |
| 7904 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7905 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7906 | Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7907 | if (!FromDC) |
| 7908 | return FromDC; |
| 7909 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7910 | ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC)); |
Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 7911 | if (!ToDCOrErr) |
| 7912 | return ToDCOrErr.takeError(); |
| 7913 | auto *ToDC = cast<DeclContext>(*ToDCOrErr); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7914 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7915 | // 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] | 7916 | // need it to have a definition. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7917 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
| 7918 | auto *FromRecord = cast<RecordDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7919 | if (ToRecord->isCompleteDefinition()) { |
| 7920 | // Do nothing. |
| 7921 | } else if (FromRecord->isCompleteDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7922 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7923 | FromRecord, ToRecord, ASTNodeImporter::IDK_Basic)) |
| 7924 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7925 | } else { |
| 7926 | CompleteDecl(ToRecord); |
| 7927 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7928 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 7929 | auto *FromEnum = cast<EnumDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7930 | if (ToEnum->isCompleteDefinition()) { |
| 7931 | // Do nothing. |
| 7932 | } else if (FromEnum->isCompleteDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7933 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7934 | FromEnum, ToEnum, ASTNodeImporter::IDK_Basic)) |
| 7935 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7936 | } else { |
| 7937 | CompleteDecl(ToEnum); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7938 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7939 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 7940 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7941 | if (ToClass->getDefinition()) { |
| 7942 | // Do nothing. |
| 7943 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7944 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7945 | FromDef, ToClass, ASTNodeImporter::IDK_Basic)) |
| 7946 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7947 | } else { |
| 7948 | CompleteDecl(ToClass); |
| 7949 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7950 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 7951 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7952 | if (ToProto->getDefinition()) { |
| 7953 | // Do nothing. |
| 7954 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7955 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7956 | FromDef, ToProto, ASTNodeImporter::IDK_Basic)) |
| 7957 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7958 | } else { |
| 7959 | CompleteDecl(ToProto); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7960 | } |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7961 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7962 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7963 | return ToDC; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7964 | } |
| 7965 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7966 | Expected<Expr *> ASTImporter::Import(Expr *FromE) { |
| 7967 | if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE))) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7968 | return cast_or_null<Expr>(*ToSOrErr); |
| 7969 | else |
| 7970 | return ToSOrErr.takeError(); |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7971 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7972 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7973 | Expected<Stmt *> ASTImporter::Import(Stmt *FromS) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7974 | if (!FromS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7975 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7976 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7977 | // Check whether we've already imported this statement. |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7978 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 7979 | if (Pos != ImportedStmts.end()) |
| 7980 | return Pos->second; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7981 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7982 | // Import the statement. |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7983 | ASTNodeImporter Importer(*this); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7984 | ExpectedStmt ToSOrErr = Importer.Visit(FromS); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7985 | if (!ToSOrErr) |
| 7986 | return ToSOrErr; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7987 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7988 | if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) { |
Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7989 | auto *FromE = cast<Expr>(FromS); |
| 7990 | // Copy ExprBitfields, which may not be handled in Expr subclasses |
| 7991 | // constructors. |
| 7992 | ToE->setValueKind(FromE->getValueKind()); |
| 7993 | ToE->setObjectKind(FromE->getObjectKind()); |
| 7994 | ToE->setTypeDependent(FromE->isTypeDependent()); |
| 7995 | ToE->setValueDependent(FromE->isValueDependent()); |
| 7996 | ToE->setInstantiationDependent(FromE->isInstantiationDependent()); |
| 7997 | ToE->setContainsUnexpandedParameterPack( |
| 7998 | FromE->containsUnexpandedParameterPack()); |
| 7999 | } |
| 8000 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8001 | // Record the imported statement object. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8002 | ImportedStmts[FromS] = *ToSOrErr; |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8003 | return ToSOrErr; |
| 8004 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8005 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8006 | Expected<NestedNameSpecifier *> |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8007 | ASTImporter::Import(NestedNameSpecifier *FromNNS) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8008 | if (!FromNNS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8009 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8010 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8011 | NestedNameSpecifier *Prefix; |
| 8012 | if (Error Err = importInto(Prefix, FromNNS->getPrefix())) |
| 8013 | return std::move(Err); |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8014 | |
| 8015 | switch (FromNNS->getKind()) { |
| 8016 | case NestedNameSpecifier::Identifier: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8017 | assert(FromNNS->getAsIdentifier() && "NNS should contain identifier."); |
| 8018 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 8019 | Import(FromNNS->getAsIdentifier())); |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8020 | |
| 8021 | case NestedNameSpecifier::Namespace: |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8022 | if (ExpectedDecl NSOrErr = Import(FromNNS->getAsNamespace())) { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8023 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 8024 | cast<NamespaceDecl>(*NSOrErr)); |
| 8025 | } else |
| 8026 | return NSOrErr.takeError(); |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8027 | |
| 8028 | case NestedNameSpecifier::NamespaceAlias: |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8029 | if (ExpectedDecl NSADOrErr = Import(FromNNS->getAsNamespaceAlias())) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8030 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 8031 | cast<NamespaceAliasDecl>(*NSADOrErr)); |
| 8032 | else |
| 8033 | return NSADOrErr.takeError(); |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8034 | |
| 8035 | case NestedNameSpecifier::Global: |
| 8036 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 8037 | |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8038 | case NestedNameSpecifier::Super: |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8039 | if (ExpectedDecl RDOrErr = Import(FromNNS->getAsRecordDecl())) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8040 | return NestedNameSpecifier::SuperSpecifier(ToContext, |
| 8041 | cast<CXXRecordDecl>(*RDOrErr)); |
| 8042 | else |
| 8043 | return RDOrErr.takeError(); |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8044 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8045 | case NestedNameSpecifier::TypeSpec: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8046 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 8047 | if (Expected<QualType> TyOrErr = |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8048 | Import(QualType(FromNNS->getAsType(), 0u))) { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8049 | bool TSTemplate = |
| 8050 | FromNNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate; |
| 8051 | return NestedNameSpecifier::Create(ToContext, Prefix, TSTemplate, |
| 8052 | TyOrErr->getTypePtr()); |
| 8053 | } else { |
| 8054 | return TyOrErr.takeError(); |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8055 | } |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8056 | } |
| 8057 | |
| 8058 | llvm_unreachable("Invalid nested name specifier kind"); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8059 | } |
| 8060 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8061 | Expected<NestedNameSpecifierLoc> |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8062 | ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8063 | // Copied from NestedNameSpecifier mostly. |
| 8064 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 8065 | NestedNameSpecifierLoc NNS = FromNNS; |
| 8066 | |
| 8067 | // Push each of the nested-name-specifiers's onto a stack for |
| 8068 | // serialization in reverse order. |
| 8069 | while (NNS) { |
| 8070 | NestedNames.push_back(NNS); |
| 8071 | NNS = NNS.getPrefix(); |
| 8072 | } |
| 8073 | |
| 8074 | NestedNameSpecifierLocBuilder Builder; |
| 8075 | |
| 8076 | while (!NestedNames.empty()) { |
| 8077 | NNS = NestedNames.pop_back_val(); |
Simon Pilgrim | 4c146ab | 2019-05-18 11:33:27 +0000 | [diff] [blame] | 8078 | NestedNameSpecifier *Spec = nullptr; |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8079 | if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier())) |
| 8080 | return std::move(Err); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8081 | |
| 8082 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8083 | |
| 8084 | SourceLocation ToLocalBeginLoc, ToLocalEndLoc; |
| 8085 | if (Kind != NestedNameSpecifier::Super) { |
| 8086 | if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc())) |
| 8087 | return std::move(Err); |
| 8088 | |
| 8089 | if (Kind != NestedNameSpecifier::Global) |
| 8090 | if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc())) |
| 8091 | return std::move(Err); |
| 8092 | } |
| 8093 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8094 | switch (Kind) { |
| 8095 | case NestedNameSpecifier::Identifier: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8096 | Builder.Extend(getToContext(), Spec->getAsIdentifier(), ToLocalBeginLoc, |
| 8097 | ToLocalEndLoc); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8098 | break; |
| 8099 | |
| 8100 | case NestedNameSpecifier::Namespace: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8101 | Builder.Extend(getToContext(), Spec->getAsNamespace(), ToLocalBeginLoc, |
| 8102 | ToLocalEndLoc); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8103 | break; |
| 8104 | |
| 8105 | case NestedNameSpecifier::NamespaceAlias: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8106 | Builder.Extend(getToContext(), Spec->getAsNamespaceAlias(), |
| 8107 | ToLocalBeginLoc, ToLocalEndLoc); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8108 | break; |
| 8109 | |
| 8110 | case NestedNameSpecifier::TypeSpec: |
| 8111 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Balazs Keri | 5f4fd8b | 2019-03-14 14:20:23 +0000 | [diff] [blame] | 8112 | SourceLocation ToTLoc; |
| 8113 | if (Error Err = importInto(ToTLoc, NNS.getTypeLoc().getBeginLoc())) |
| 8114 | return std::move(Err); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8115 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
Balazs Keri | 5f4fd8b | 2019-03-14 14:20:23 +0000 | [diff] [blame] | 8116 | QualType(Spec->getAsType(), 0), ToTLoc); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8117 | Builder.Extend(getToContext(), ToLocalBeginLoc, TSI->getTypeLoc(), |
| 8118 | ToLocalEndLoc); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8119 | break; |
| 8120 | } |
| 8121 | |
| 8122 | case NestedNameSpecifier::Global: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8123 | Builder.MakeGlobal(getToContext(), ToLocalBeginLoc); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8124 | break; |
| 8125 | |
| 8126 | case NestedNameSpecifier::Super: { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8127 | auto ToSourceRangeOrErr = Import(NNS.getSourceRange()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8128 | if (!ToSourceRangeOrErr) |
| 8129 | return ToSourceRangeOrErr.takeError(); |
| 8130 | |
| 8131 | Builder.MakeSuper(getToContext(), Spec->getAsRecordDecl(), |
| 8132 | ToSourceRangeOrErr->getBegin(), |
| 8133 | ToSourceRangeOrErr->getEnd()); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8134 | } |
| 8135 | } |
| 8136 | } |
| 8137 | |
| 8138 | return Builder.getWithLocInContext(getToContext()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 8139 | } |
| 8140 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8141 | Expected<TemplateName> ASTImporter::Import(TemplateName From) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8142 | switch (From.getKind()) { |
| 8143 | case TemplateName::Template: |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8144 | if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl())) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8145 | return TemplateName(cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8146 | else |
| 8147 | return ToTemplateOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8148 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8149 | case TemplateName::OverloadedTemplate: { |
| 8150 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 8151 | UnresolvedSet<2> ToTemplates; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8152 | for (auto *I : *FromStorage) { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8153 | if (auto ToOrErr = Import(I)) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8154 | ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr)); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8155 | else |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8156 | return ToOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8157 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8158 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8159 | ToTemplates.end()); |
| 8160 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8161 | |
Richard Smith | b23c5e8 | 2019-05-09 03:31:27 +0000 | [diff] [blame] | 8162 | case TemplateName::AssumedTemplate: { |
| 8163 | AssumedTemplateStorage *FromStorage = From.getAsAssumedTemplateName(); |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8164 | auto DeclNameOrErr = Import(FromStorage->getDeclName()); |
Richard Smith | b23c5e8 | 2019-05-09 03:31:27 +0000 | [diff] [blame] | 8165 | if (!DeclNameOrErr) |
| 8166 | return DeclNameOrErr.takeError(); |
| 8167 | return ToContext.getAssumedTemplateName(*DeclNameOrErr); |
| 8168 | } |
| 8169 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8170 | case TemplateName::QualifiedTemplate: { |
| 8171 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8172 | auto QualifierOrErr = Import(QTN->getQualifier()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8173 | if (!QualifierOrErr) |
| 8174 | return QualifierOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8175 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8176 | if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl())) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8177 | return ToContext.getQualifiedTemplateName( |
| 8178 | *QualifierOrErr, QTN->hasTemplateKeyword(), |
| 8179 | cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8180 | else |
| 8181 | return ToTemplateOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8182 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8183 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8184 | case TemplateName::DependentTemplate: { |
| 8185 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8186 | auto QualifierOrErr = Import(DTN->getQualifier()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8187 | if (!QualifierOrErr) |
| 8188 | return QualifierOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8189 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8190 | if (DTN->isIdentifier()) { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8191 | return ToContext.getDependentTemplateName(*QualifierOrErr, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8192 | Import(DTN->getIdentifier())); |
| 8193 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8194 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8195 | return ToContext.getDependentTemplateName(*QualifierOrErr, |
| 8196 | DTN->getOperator()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8197 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8198 | |
| 8199 | case TemplateName::SubstTemplateTemplateParm: { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8200 | SubstTemplateTemplateParmStorage *Subst = |
| 8201 | From.getAsSubstTemplateTemplateParm(); |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8202 | ExpectedDecl ParamOrErr = Import(Subst->getParameter()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8203 | if (!ParamOrErr) |
| 8204 | return ParamOrErr.takeError(); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8205 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8206 | auto ReplacementOrErr = Import(Subst->getReplacement()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8207 | if (!ReplacementOrErr) |
| 8208 | return ReplacementOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8209 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8210 | return ToContext.getSubstTemplateTemplateParm( |
| 8211 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ReplacementOrErr); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8212 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8213 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8214 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 8215 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 8216 | = From.getAsSubstTemplateTemplateParmPack(); |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8217 | ExpectedDecl ParamOrErr = Import(SubstPack->getParameterPack()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8218 | if (!ParamOrErr) |
| 8219 | return ParamOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8220 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8221 | ASTNodeImporter Importer(*this); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8222 | auto ArgPackOrErr = |
| 8223 | Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
| 8224 | if (!ArgPackOrErr) |
| 8225 | return ArgPackOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8226 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8227 | return ToContext.getSubstTemplateTemplateParmPack( |
| 8228 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ArgPackOrErr); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8229 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8230 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8231 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8232 | llvm_unreachable("Invalid template name kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8233 | } |
| 8234 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8235 | Expected<SourceLocation> ASTImporter::Import(SourceLocation FromLoc) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8236 | if (FromLoc.isInvalid()) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8237 | return SourceLocation{}; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8238 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8239 | SourceManager &FromSM = FromContext.getSourceManager(); |
Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8240 | bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8241 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8242 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8243 | Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8244 | if (!ToFileIDOrErr) |
| 8245 | return ToFileIDOrErr.takeError(); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8246 | SourceManager &ToSM = ToContext.getSourceManager(); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8247 | return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second); |
| 8248 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8249 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8250 | Expected<SourceRange> ASTImporter::Import(SourceRange FromRange) { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8251 | SourceLocation ToBegin, ToEnd; |
| 8252 | if (Error Err = importInto(ToBegin, FromRange.getBegin())) |
| 8253 | return std::move(Err); |
| 8254 | if (Error Err = importInto(ToEnd, FromRange.getEnd())) |
| 8255 | return std::move(Err); |
| 8256 | |
| 8257 | return SourceRange(ToBegin, ToEnd); |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8258 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8259 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8260 | Expected<FileID> ASTImporter::Import(FileID FromID, bool IsBuiltin) { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8261 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8262 | if (Pos != ImportedFileIDs.end()) |
| 8263 | return Pos->second; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8264 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8265 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 8266 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 8267 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8268 | |
| 8269 | // Map the FromID to the "to" source manager. |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8270 | FileID ToID; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8271 | if (FromSLoc.isExpansion()) { |
| 8272 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8273 | ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8274 | if (!ToSpLoc) |
| 8275 | return ToSpLoc.takeError(); |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8276 | ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8277 | if (!ToExLocS) |
| 8278 | return ToExLocS.takeError(); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8279 | unsigned TokenLen = FromSM.getFileIDSize(FromID); |
| 8280 | SourceLocation MLoc; |
| 8281 | if (FromEx.isMacroArgExpansion()) { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8282 | MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, TokenLen); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8283 | } else { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8284 | if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd())) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8285 | MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, TokenLen, |
| 8286 | FromEx.isExpansionTokenRange()); |
| 8287 | else |
| 8288 | return ToExLocE.takeError(); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8289 | } |
| 8290 | ToID = ToSM.getFileID(MLoc); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8291 | } else { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8292 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8293 | |
| 8294 | if (!IsBuiltin) { |
| 8295 | // Include location of this file. |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8296 | ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8297 | if (!ToIncludeLoc) |
| 8298 | return ToIncludeLoc.takeError(); |
Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8299 | |
| 8300 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
| 8301 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 8302 | // disk again |
| 8303 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 8304 | // than mmap the files several times. |
| 8305 | const FileEntry *Entry = |
| 8306 | ToFileManager.getFile(Cache->OrigEntry->getName()); |
| 8307 | // FIXME: The filename may be a virtual name that does probably not |
| 8308 | // point to a valid file and we get no Entry here. In this case try with |
| 8309 | // the memory buffer below. |
| 8310 | if (Entry) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8311 | ToID = ToSM.createFileID(Entry, *ToIncludeLoc, |
Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8312 | FromSLoc.getFile().getFileCharacteristic()); |
| 8313 | } |
Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8314 | } |
Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8315 | |
| 8316 | if (ToID.isInvalid() || IsBuiltin) { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8317 | // FIXME: We want to re-use the existing MemoryBuffer! |
Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8318 | bool Invalid = true; |
| 8319 | const llvm::MemoryBuffer *FromBuf = Cache->getBuffer( |
| 8320 | FromContext.getDiagnostics(), FromSM, SourceLocation{}, &Invalid); |
| 8321 | if (!FromBuf || Invalid) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8322 | // FIXME: Use a new error kind? |
| 8323 | return llvm::make_error<ImportError>(ImportError::Unknown); |
Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8324 | |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8325 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = |
| 8326 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
| 8327 | FromBuf->getBufferIdentifier()); |
| 8328 | ToID = ToSM.createFileID(std::move(ToBuf), |
| 8329 | FromSLoc.getFile().getFileCharacteristic()); |
| 8330 | } |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8331 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8332 | |
Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8333 | assert(ToID.isValid() && "Unexpected invalid fileID was created."); |
| 8334 | |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 8335 | ImportedFileIDs[FromID] = ToID; |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8336 | return ToID; |
| 8337 | } |
| 8338 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8339 | Expected<CXXCtorInitializer *> ASTImporter::Import(CXXCtorInitializer *From) { |
| 8340 | ExpectedExpr ToExprOrErr = Import(From->getInit()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8341 | if (!ToExprOrErr) |
| 8342 | return ToExprOrErr.takeError(); |
| 8343 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8344 | auto LParenLocOrErr = Import(From->getLParenLoc()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8345 | if (!LParenLocOrErr) |
| 8346 | return LParenLocOrErr.takeError(); |
| 8347 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8348 | auto RParenLocOrErr = Import(From->getRParenLoc()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8349 | if (!RParenLocOrErr) |
| 8350 | return RParenLocOrErr.takeError(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8351 | |
| 8352 | if (From->isBaseInitializer()) { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8353 | auto ToTInfoOrErr = Import(From->getTypeSourceInfo()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8354 | if (!ToTInfoOrErr) |
| 8355 | return ToTInfoOrErr.takeError(); |
| 8356 | |
| 8357 | SourceLocation EllipsisLoc; |
| 8358 | if (From->isPackExpansion()) |
| 8359 | if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc())) |
| 8360 | return std::move(Err); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8361 | |
| 8362 | return new (ToContext) CXXCtorInitializer( |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8363 | ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr, |
| 8364 | *ToExprOrErr, *RParenLocOrErr, EllipsisLoc); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8365 | } else if (From->isMemberInitializer()) { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8366 | ExpectedDecl ToFieldOrErr = Import(From->getMember()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8367 | if (!ToFieldOrErr) |
| 8368 | return ToFieldOrErr.takeError(); |
| 8369 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8370 | auto MemberLocOrErr = Import(From->getMemberLocation()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8371 | if (!MemberLocOrErr) |
| 8372 | return MemberLocOrErr.takeError(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8373 | |
| 8374 | return new (ToContext) CXXCtorInitializer( |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8375 | ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr, |
| 8376 | *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8377 | } else if (From->isIndirectMemberInitializer()) { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8378 | ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8379 | if (!ToIFieldOrErr) |
| 8380 | return ToIFieldOrErr.takeError(); |
| 8381 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8382 | auto MemberLocOrErr = Import(From->getMemberLocation()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8383 | if (!MemberLocOrErr) |
| 8384 | return MemberLocOrErr.takeError(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8385 | |
| 8386 | return new (ToContext) CXXCtorInitializer( |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8387 | ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr), |
| 8388 | *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8389 | } else if (From->isDelegatingInitializer()) { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8390 | auto ToTInfoOrErr = Import(From->getTypeSourceInfo()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8391 | if (!ToTInfoOrErr) |
| 8392 | return ToTInfoOrErr.takeError(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8393 | |
| 8394 | return new (ToContext) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8395 | CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr, |
| 8396 | *ToExprOrErr, *RParenLocOrErr); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8397 | } else { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8398 | // FIXME: assert? |
| 8399 | return make_error<ImportError>(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8400 | } |
Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 8401 | } |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8402 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8403 | Expected<CXXBaseSpecifier *> |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8404 | ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8405 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 8406 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 8407 | return Pos->second; |
| 8408 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8409 | Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8410 | if (!ToSourceRange) |
| 8411 | return ToSourceRange.takeError(); |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8412 | Expected<TypeSourceInfo *> ToTSI = Import(BaseSpec->getTypeSourceInfo()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8413 | if (!ToTSI) |
| 8414 | return ToTSI.takeError(); |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8415 | ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8416 | if (!ToEllipsisLoc) |
| 8417 | return ToEllipsisLoc.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8418 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8419 | *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 8420 | BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8421 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 8422 | return Imported; |
| 8423 | } |
| 8424 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8425 | Error ASTImporter::ImportDefinition(Decl *From) { |
| 8426 | ExpectedDecl ToOrErr = Import(From); |
| 8427 | if (!ToOrErr) |
| 8428 | return ToOrErr.takeError(); |
| 8429 | Decl *To = *ToOrErr; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8430 | |
Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8431 | auto *FromDC = cast<DeclContext>(From); |
| 8432 | ASTNodeImporter Importer(*this); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8433 | |
Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8434 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { |
| 8435 | if (!ToRecord->getDefinition()) { |
| 8436 | return Importer.ImportDefinition( |
| 8437 | cast<RecordDecl>(FromDC), ToRecord, |
| 8438 | ASTNodeImporter::IDK_Everything); |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 8439 | } |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8440 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8441 | |
Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8442 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { |
| 8443 | if (!ToEnum->getDefinition()) { |
| 8444 | return Importer.ImportDefinition( |
| 8445 | cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything); |
| 8446 | } |
| 8447 | } |
| 8448 | |
| 8449 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
| 8450 | if (!ToIFace->getDefinition()) { |
| 8451 | return Importer.ImportDefinition( |
| 8452 | cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
| 8453 | ASTNodeImporter::IDK_Everything); |
| 8454 | } |
| 8455 | } |
| 8456 | |
| 8457 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
| 8458 | if (!ToProto->getDefinition()) { |
| 8459 | return Importer.ImportDefinition( |
| 8460 | cast<ObjCProtocolDecl>(FromDC), ToProto, |
| 8461 | ASTNodeImporter::IDK_Everything); |
| 8462 | } |
| 8463 | } |
| 8464 | |
| 8465 | return Importer.ImportDeclContext(FromDC, true); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8466 | } |
| 8467 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8468 | Expected<DeclarationName> ASTImporter::Import(DeclarationName FromName) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8469 | if (!FromName) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8470 | return DeclarationName{}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8471 | |
| 8472 | switch (FromName.getNameKind()) { |
| 8473 | case DeclarationName::Identifier: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8474 | return DeclarationName(Import(FromName.getAsIdentifierInfo())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8475 | |
| 8476 | case DeclarationName::ObjCZeroArgSelector: |
| 8477 | case DeclarationName::ObjCOneArgSelector: |
| 8478 | case DeclarationName::ObjCMultiArgSelector: |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8479 | if (auto ToSelOrErr = Import(FromName.getObjCSelector())) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8480 | return DeclarationName(*ToSelOrErr); |
| 8481 | else |
| 8482 | return ToSelOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8483 | |
| 8484 | case DeclarationName::CXXConstructorName: { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8485 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8486 | return ToContext.DeclarationNames.getCXXConstructorName( |
| 8487 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8488 | else |
| 8489 | return ToTyOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8490 | } |
| 8491 | |
| 8492 | case DeclarationName::CXXDestructorName: { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8493 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8494 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 8495 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8496 | else |
| 8497 | return ToTyOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8498 | } |
| 8499 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8500 | case DeclarationName::CXXDeductionGuideName: { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8501 | if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate())) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8502 | return ToContext.DeclarationNames.getCXXDeductionGuideName( |
| 8503 | cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8504 | else |
| 8505 | return ToTemplateOrErr.takeError(); |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8506 | } |
| 8507 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8508 | case DeclarationName::CXXConversionFunctionName: { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8509 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8510 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 8511 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8512 | else |
| 8513 | return ToTyOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8514 | } |
| 8515 | |
| 8516 | case DeclarationName::CXXOperatorName: |
| 8517 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 8518 | FromName.getCXXOverloadedOperator()); |
| 8519 | |
| 8520 | case DeclarationName::CXXLiteralOperatorName: |
| 8521 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8522 | Import(FromName.getCXXLiteralIdentifier())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8523 | |
| 8524 | case DeclarationName::CXXUsingDirective: |
| 8525 | // FIXME: STATICS! |
| 8526 | return DeclarationName::getUsingDirectiveName(); |
| 8527 | } |
| 8528 | |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 8529 | llvm_unreachable("Invalid DeclarationName Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8530 | } |
| 8531 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8532 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8533 | if (!FromId) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8534 | return nullptr; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8535 | |
Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 8536 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 8537 | |
| 8538 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 8539 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 8540 | |
| 8541 | return ToId; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8542 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8543 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8544 | Expected<Selector> ASTImporter::Import(Selector FromSel) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8545 | if (FromSel.isNull()) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8546 | return Selector{}; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8547 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 8548 | SmallVector<IdentifierInfo *, 4> Idents; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8549 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 8550 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 8551 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 8552 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 8553 | } |
| 8554 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8555 | DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, |
| 8556 | DeclContext *DC, |
| 8557 | unsigned IDNS, |
| 8558 | NamedDecl **Decls, |
| 8559 | unsigned NumDecls) { |
| 8560 | return Name; |
| 8561 | } |
| 8562 | |
| 8563 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8564 | if (LastDiagFromFrom) |
| 8565 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8566 | FromContext.getDiagnostics()); |
| 8567 | LastDiagFromFrom = false; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8568 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8569 | } |
| 8570 | |
| 8571 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8572 | if (!LastDiagFromFrom) |
| 8573 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8574 | ToContext.getDiagnostics()); |
| 8575 | LastDiagFromFrom = true; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8576 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8577 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8578 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8579 | void ASTImporter::CompleteDecl (Decl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8580 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8581 | if (!ID->getDefinition()) |
| 8582 | ID->startDefinition(); |
| 8583 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8584 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8585 | if (!PD->getDefinition()) |
| 8586 | PD->startDefinition(); |
| 8587 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8588 | else if (auto *TD = dyn_cast<TagDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8589 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 8590 | TD->startDefinition(); |
| 8591 | TD->setCompleteDefinition(true); |
| 8592 | } |
| 8593 | } |
| 8594 | else { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8595 | assert(0 && "CompleteDecl called on a Decl that can't be completed"); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8596 | } |
| 8597 | } |
| 8598 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8599 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { |
| 8600 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); |
| 8601 | assert((Pos == ImportedDecls.end() || Pos->second == To) && |
| 8602 | "Try to import an already imported Decl"); |
| 8603 | if (Pos != ImportedDecls.end()) |
| 8604 | return Pos->second; |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8605 | ImportedDecls[From] = To; |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 8606 | // This mapping should be maintained only in this function. Therefore do not |
| 8607 | // check for additional consistency. |
| 8608 | ImportedFromDecls[To] = From; |
Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame^] | 8609 | AddToLookupTable(To); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8610 | return To; |
Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 8611 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8612 | |
Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame^] | 8613 | llvm::Optional<ImportError> |
| 8614 | ASTImporter::getImportDeclErrorIfAny(Decl *FromD) const { |
| 8615 | auto Pos = ImportDeclErrors.find(FromD); |
| 8616 | if (Pos != ImportDeclErrors.end()) |
| 8617 | return Pos->second; |
| 8618 | else |
| 8619 | return Optional<ImportError>(); |
| 8620 | } |
| 8621 | |
| 8622 | void ASTImporter::setImportDeclError(Decl *From, ImportError Error) { |
| 8623 | assert(ImportDeclErrors.find(From) == ImportDeclErrors.end() && |
| 8624 | "Setting import error allowed only once for a Decl."); |
| 8625 | ImportDeclErrors[From] = Error; |
| 8626 | } |
| 8627 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8628 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 8629 | bool Complain) { |
Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 8630 | llvm::DenseMap<const Type *, const Type *>::iterator Pos = |
| 8631 | ImportedTypes.find(From.getTypePtr()); |
| 8632 | if (Pos != ImportedTypes.end()) { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8633 | if (ExpectedType ToFromOrErr = Import(From)) { |
Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 8634 | if (ToContext.hasSameType(*ToFromOrErr, To)) |
| 8635 | return true; |
| 8636 | } else { |
| 8637 | llvm::consumeError(ToFromOrErr.takeError()); |
| 8638 | } |
| 8639 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 8640 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8641 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8642 | getStructuralEquivalenceKind(*this), false, |
| 8643 | Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 8644 | return Ctx.IsEquivalent(From, To); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8645 | } |